« V26/Services/YouTubeVideoUploadService/UpdateYouTubeVideoUploadResponse.pm
↑ Summary
Common/AuthError.pm »
| 1 | # Copyright 2019, Google LLC | ||||||||||
| 2 | # | ||||||||||
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); | ||||||||||
| 4 | # you may not use this file except in compliance with the License. | ||||||||||
| 5 | # You may obtain a copy of the License at | ||||||||||
| 6 | # | ||||||||||
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 | ||||||||||
| 8 | # | ||||||||||
| 9 | # Unless required by applicable law or agreed to in writing, software | ||||||||||
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, | ||||||||||
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||||||
| 12 | # See the License for the specific language governing permissions and | ||||||||||
| 13 | # limitations under the License. | ||||||||||
| 14 | # | ||||||||||
| 15 | # This module contains utility methods for media processing. | ||||||||||
| 16 | |||||||||||
| 17 | package Google::Ads::GoogleAds::Utils::MediaUtils; | ||||||||||
| 18 | |||||||||||
| 19 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 20 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 21 | 2 | ▶ | use version; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 22 | |||||||||||
| 23 | # The following needs to be on one line because CPAN uses a particularly hacky | ||||||||||
| 24 | # eval() to determine module versions. | ||||||||||
| 25 | 2 | ▶ | use Google::Ads::GoogleAds::Constants; our $VERSION = ${Google::Ads::GoogleAds::Constants::VERSION}; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 26 | |||||||||||
| 27 | 2 | ▶ | use Exporter 'import'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 28 | 2 | our @EXPORT = qw(get_base64_data_from_url); | |||||||||
| 29 | |||||||||||
| 30 | 2 | ▶ | use HTTP::Request; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 31 | 2 | ▶ | use LWP::UserAgent; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 32 | 2 | ▶ | use URI::Escape; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 33 | 2 | ▶ | use MIME::Base64; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 34 | |||||||||||
| 35 | # Gets the image data (byte representation) from a given URL. | ||||||||||
| 36 | 2 | ▶ | sub get_base64_data_from_url { | ||||||||
|
Subroutine
get_base64_data_from_url: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||
| 37 | 2 | my $url = shift; | |||||||||
| 38 | 2 | my $request = HTTP::Request->new(GET => $url); | |||||||||
| 39 | 2 | my $response = LWP::UserAgent->new->request($request); | |||||||||
| 40 | 2 | ▶ | return encode_base64($response->content, '') if $response->is_success; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 41 | } | ||||||||||
| 42 | |||||||||||
| 43 | 2 | 1; | |||||||||
| 44 | |||||||||||
| 45 | =pod | ||||||||||
| 46 | |||||||||||
| 47 | =head1 NAME | ||||||||||
| 48 | |||||||||||
| 49 | Google::Ads::GoogleAds::Utils::MediaUtils | ||||||||||
| 50 | |||||||||||
| 51 | =head1 SYNOPSIS | ||||||||||
| 52 | |||||||||||
| 53 | use Google::Ads::GoogleAds::Utils::MediaUtils; | ||||||||||
| 54 | |||||||||||
| 55 | my $image_data = get_base64_data_from_url("https://gaagl.page.link/Eit5"); | ||||||||||
| 56 | |||||||||||
| 57 | if ($image_data) { | ||||||||||
| 58 | # Make use of $image_data. | ||||||||||
| 59 | } | ||||||||||
| 60 | |||||||||||
| 61 | =head1 DESCRIPTION | ||||||||||
| 62 | |||||||||||
| 63 | This module contains utility methods for media processing. | ||||||||||
| 64 | |||||||||||
| 65 | =head1 METHODS | ||||||||||
| 66 | |||||||||||
| 67 | =head2 get_base64_data_from_url | ||||||||||
| 68 | |||||||||||
| 69 | Gets the image data (byte representation) from a given URL. | ||||||||||
| 70 | |||||||||||
| 71 | =head3 Parameters | ||||||||||
| 72 | |||||||||||
| 73 | The URL from which the data will be retrieved. | ||||||||||
| 74 | |||||||||||
| 75 | =head3 Returns | ||||||||||
| 76 | |||||||||||
| 77 | A base64 encoded string of the image data. Or undef if the image is not found. | ||||||||||
| 78 | |||||||||||
| 79 | =head1 LICENSE AND COPYRIGHT | ||||||||||
| 80 | |||||||||||
| 81 | Copyright 2019 Google LLC | ||||||||||
| 82 | |||||||||||
| 83 | Licensed under the Apache License, Version 2.0 (the "License"); | ||||||||||
| 84 | you may not use this file except in compliance with the License. | ||||||||||
| 85 | You may obtain a copy of the License at | ||||||||||
| 86 | |||||||||||
| 87 | http://www.apache.org/licenses/LICENSE-2.0 | ||||||||||
| 88 | |||||||||||
| 89 | Unless required by applicable law or agreed to in writing, software | ||||||||||
| 90 | distributed under the License is distributed on an "AS IS" BASIS, | ||||||||||
| 91 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||||||
| 92 | See the License for the specific language governing permissions and | ||||||||||
| 93 | limitations under the License. | ||||||||||
| 94 | |||||||||||
| 95 | =head1 REPOSITORY INFORMATION | ||||||||||
| 96 | |||||||||||
| 97 | $Rev: $ | ||||||||||
| 98 | $LastChangedBy: $ | ||||||||||
| 99 | $Id: $ | ||||||||||
| 100 | |||||||||||
| 101 | =cut | ||||||||||