line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyright 2013, Google Inc. All Rights Reserved. |
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
|
|
|
|
|
|
|
package Google::Ads::Common::MediaUtils; |
16
|
|
|
|
|
|
|
|
17
|
3
|
|
|
3
|
|
181751
|
use strict; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
92
|
|
18
|
3
|
|
|
3
|
|
16
|
use warnings; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
78
|
|
19
|
3
|
|
|
3
|
|
480
|
use version; |
|
3
|
|
|
|
|
3308
|
|
|
3
|
|
|
|
|
18
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# The following needs to be on one line because CPAN uses a particularly hacky |
22
|
|
|
|
|
|
|
# eval() to determine module versions. |
23
|
3
|
|
|
3
|
|
917
|
use Google::Ads::Common::Constants; our $VERSION = ${Google::Ads::Common::Constants::VERSION}; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
119
|
|
24
|
|
|
|
|
|
|
|
25
|
3
|
|
|
3
|
|
590
|
use HTTP::Request; |
|
3
|
|
|
|
|
20837
|
|
|
3
|
|
|
|
|
77
|
|
26
|
3
|
|
|
3
|
|
845
|
use LWP::UserAgent; |
|
3
|
|
|
|
|
33926
|
|
|
3
|
|
|
|
|
118
|
|
27
|
3
|
|
|
3
|
|
29
|
use URI::Escape; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
232
|
|
28
|
3
|
|
|
3
|
|
934
|
use MIME::Base64; |
|
3
|
|
|
|
|
1405
|
|
|
3
|
|
|
|
|
569
|
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub get_base64_data_from_url (%) { |
31
|
0
|
|
|
0
|
0
|
|
my $url = shift; |
32
|
0
|
|
|
|
|
|
my $request = HTTP::Request->new(GET => $url); |
33
|
0
|
|
|
|
|
|
my $userAgent = LWP::UserAgent->new(); |
34
|
0
|
|
|
|
|
|
$userAgent->agent(sprintf("%s: %s", __PACKAGE__, $0)); |
35
|
0
|
|
|
|
|
|
my $response = $userAgent->request($request); |
36
|
0
|
0
|
|
|
|
|
if ($response->is_success()) { |
37
|
0
|
|
|
|
|
|
my $content = $response->content(); |
38
|
0
|
|
|
|
|
|
return encode_base64($content); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
return 1; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=pod |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head1 NAME |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
Google::Ads::Common::ImageUtils |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head1 SYNOPSIS |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
use Google::Ads::Common::ImageUtils; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
my $image_data; |
55
|
|
|
|
|
|
|
eval { |
56
|
|
|
|
|
|
|
$image_data = Google::Ads::Common::ImageUtils::get_image_data_from_url({ |
57
|
|
|
|
|
|
|
url => 'https://sandbox.google.com/sandboximages/image.jpg' |
58
|
|
|
|
|
|
|
}); |
59
|
|
|
|
|
|
|
}; |
60
|
|
|
|
|
|
|
if ($@) { |
61
|
|
|
|
|
|
|
# $@ will contain a string explaining why the image data request failed. |
62
|
|
|
|
|
|
|
} else { |
63
|
|
|
|
|
|
|
# Make use of $image_data. |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head1 DESCRIPTION |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head1 SUBROUTINES |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head2 get_image_data_from_url |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
Gets the image data (byte representation) from a given URL. |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head3 Parameters |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
The URL from which the data will be retrieved. |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head3 Returns |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
A byte array of the image data. Or no return if the image is not found. |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
Copyright 2013 Google Inc. |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License"); |
88
|
|
|
|
|
|
|
you may not use this file except in compliance with the License. |
89
|
|
|
|
|
|
|
You may obtain a copy of the License at |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0 |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software |
94
|
|
|
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS, |
95
|
|
|
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
96
|
|
|
|
|
|
|
See the License for the specific language governing permissions and |
97
|
|
|
|
|
|
|
limitations under the License. |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 REPOSITORY INFORMATION |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
$Rev: $ |
102
|
|
|
|
|
|
|
$LastChangedBy: $ |
103
|
|
|
|
|
|
|
$Id: $ |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=cut |