blib/lib/Google/Ads/Common/MediaUtils.pm untested

filter: Statementstmt 0.0% 0 / 35 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 47 CC 2 SCAR 10.3
CC
2
Cov
0%
get_base64_data_from_url
6.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.8
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 use strict;
18 use warnings;
19 use version;
20  
21 # The following needs to be on one line because CPAN uses a particularly hacky
22 # eval() to determine module versions.
23 use Google::Ads::Common::Constants; our $VERSION = ${Google::Ads::Common::Constants::VERSION};
24  
25 use HTTP::Request;
26 use LWP::UserAgent;
27 use URI::Escape;
28 use MIME::Base64;
29  
30 sub get_base64_data_from_url (%) {
31 my $url = shift;
32 my $request = HTTP::Request->new(GET => $url);
33 my $userAgent = LWP::UserAgent->new();
34 $userAgent->agent(sprintf("%s: %s", __PACKAGE__, $0));
35 my $response = $userAgent->request($request);
36 if ($response->is_success()) {
37 my $content = $response->content();
38 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