lib/Google/Ads/Common/MediaUtils.pm

filter: Statementstmt 74.1% 23 / 31 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 87.5% 7 / 8 Podpod 0.0% 0 / 1 totaltotal 71.4% 30 / 42 CC 2 SCAR 7.5
CC
2
Cov
70%
get_base64_data_from_url
6.0
BEGIN
1.0
BEGIN
1.0
CRAP 2.1
« blib/lib/Google/Ads/Common/OAuth2ServiceAccountsHandler.pm ↑ Summary blib/lib/Google/Ads/AdWords/OAuth2ApplicationsHandler.pm »
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 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use version;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 # The following needs to be on one line because CPAN uses a particularly hacky
21 # eval() to determine module versions.
22 1 ▶use Google::Ads::Common::Constants; our $VERSION = ${Google::Ads::Common::Constants::VERSION};
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 1 ▶use HTTP::Request;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 1 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 1 ▶use URI::Escape;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 1 ▶use MIME::Base64;
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 0 ▶sub get_base64_data_from_url (%) {
Subroutine get_base64_data_from_url: not called CC=2 SCAR=17.9
Pod undocumented
30 0 my $url = shift;
31 0 my $request = HTTP::Request->new(GET => $url);
32 0 my $userAgent = LWP::UserAgent->new();
33 0 $userAgent->agent(sprintf("%s: %s", __PACKAGE__, $0));
34 0 my $response = $userAgent->request($request);
35 0 ▶ if ($response->is_success()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response->is_success) 0 0 0
36 0 my $content = $response->content();
37 0 return encode_base64($content);
38 }
39 }
40  
41 1 return 1;
42  
43 =pod
44  
45 =head1 NAME
46  
47 Google::Ads::Common::ImageUtils
48  
49 =head1 SYNOPSIS
50  
51 use Google::Ads::Common::ImageUtils;
52  
53 my $image_data;
54 eval {
55 $image_data = Google::Ads::Common::ImageUtils::get_image_data_from_url({
56 url => 'https://sandbox.google.com/sandboximages/image.jpg'
57 });
58 };
59 if ($@) {
60 # $@ will contain a string explaining why the image data request failed.
61 } else {
62 # Make use of $image_data.
63 }
64  
65 =head1 DESCRIPTION
66  
67  
68 =head1 SUBROUTINES
69  
70 =head2 get_image_data_from_url
71  
72 Gets the image data (byte representation) from a given URL.
73  
74 =head3 Parameters
75  
76 The URL from which the data will be retrieved.
77  
78 =head3 Returns
79  
80 A byte array of the image data. Or no return if the image is not found.
81  
82 =head1 LICENSE AND COPYRIGHT
83  
84 Copyright 2013 Google Inc.
85  
86 Licensed under the Apache License, Version 2.0 (the "License");
87 you may not use this file except in compliance with the License.
88 You may obtain a copy of the License at
89  
90 http://www.apache.org/licenses/LICENSE-2.0
91  
92 Unless required by applicable law or agreed to in writing, software
93 distributed under the License is distributed on an "AS IS" BASIS,
94 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
95 See the License for the specific language governing permissions and
96 limitations under the License.
97  
98 =head1 AUTHOR
99  
100 David Torres E<lt>api.davidtorres at gmail.comE<gt>
101  
102 =head1 REPOSITORY INFORMATION
103  
104 $Rev: $
105 $LastChangedBy: $
106 $Id: $
107  
108 =cut
« blib/lib/Google/Ads/Common/OAuth2ServiceAccountsHandler.pm ↑ Summary blib/lib/Google/Ads/AdWords/OAuth2ApplicationsHandler.pm »