| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Google::API::Method; |
|
2
|
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
14
|
use strict; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
64
|
|
|
4
|
2
|
|
|
2
|
|
6
|
use warnings; |
|
|
2
|
|
|
|
|
2
|
|
|
|
2
|
|
|
|
|
46
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
1047
|
use Encode; |
|
|
2
|
|
|
|
|
16691
|
|
|
|
2
|
|
|
|
|
146
|
|
|
7
|
2
|
|
|
2
|
|
926
|
use HTTP::Request; |
|
|
2
|
|
|
|
|
36086
|
|
|
|
2
|
|
|
|
|
59
|
|
|
8
|
2
|
|
|
2
|
|
15
|
use URI; |
|
|
2
|
|
|
|
|
2
|
|
|
|
2
|
|
|
|
|
37
|
|
|
9
|
2
|
|
|
2
|
|
7
|
use URI::Escape qw/uri_escape/; |
|
|
2
|
|
|
|
|
2
|
|
|
|
2
|
|
|
|
|
1913
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub new { |
|
12
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
|
13
|
0
|
|
|
|
|
|
my (%param) = @_; |
|
14
|
0
|
|
|
|
|
|
for my $required (qw/ua json_parser base_url opt doc/) { |
|
15
|
0
|
0
|
|
|
|
|
die unless $param{$required}; |
|
16
|
|
|
|
|
|
|
} |
|
17
|
0
|
|
|
|
|
|
bless { %param }, $class; |
|
18
|
|
|
|
|
|
|
} |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub execute { |
|
21
|
0
|
|
|
0
|
1
|
|
my ($self, $arg) = @_; |
|
22
|
0
|
|
|
|
|
|
my $url = $self->{base_url} . $self->{doc}{path}; |
|
23
|
0
|
|
|
|
|
|
my $http_method = uc($self->{doc}{httpMethod}); |
|
24
|
0
|
|
|
|
|
|
my %required_param; |
|
25
|
0
|
|
|
|
|
|
for my $p (@{$self->{doc}{parameterOrder}}) { |
|
|
0
|
|
|
|
|
|
|
|
26
|
0
|
|
|
|
|
|
$required_param{$p} = delete $self->{opt}{$p}; |
|
27
|
0
|
0
|
0
|
|
|
|
if ($self->{opt}{body} && $self->{opt}{body}{$p}) { |
|
28
|
0
|
|
|
|
|
|
$required_param{$p} = delete $self->{opt}{body}{$p}; |
|
29
|
|
|
|
|
|
|
} |
|
30
|
|
|
|
|
|
|
} |
|
31
|
0
|
|
|
|
|
|
$url =~ s/{([^}]+)}/uri_escape(delete $required_param{$1})/eg; |
|
|
0
|
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
|
my $uri = URI->new($url); |
|
33
|
0
|
|
|
|
|
|
my $request; |
|
34
|
0
|
0
|
0
|
|
|
|
if ($http_method eq 'POST' || |
|
|
|
0
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
35
|
|
|
|
|
|
|
$http_method eq 'PUT' || |
|
36
|
|
|
|
|
|
|
$http_method eq 'PATCH' || |
|
37
|
|
|
|
|
|
|
$http_method eq 'DELETE') { |
|
38
|
0
|
|
|
|
|
|
$uri->query_form(\%required_param); |
|
39
|
0
|
|
|
|
|
|
$request = HTTP::Request->new($http_method => $uri); |
|
40
|
0
|
0
|
|
|
|
|
if ($self->{opt}{body}) { |
|
41
|
0
|
|
|
|
|
|
$request->content_type('application/json'); |
|
42
|
0
|
|
|
|
|
|
$request->content($self->{json_parser}->encode($self->{opt}{body})); |
|
43
|
|
|
|
|
|
|
} else { |
|
44
|
0
|
|
|
|
|
|
$request->content_length(0); |
|
45
|
|
|
|
|
|
|
} |
|
46
|
|
|
|
|
|
|
} elsif ($http_method eq 'GET') { |
|
47
|
0
|
|
0
|
|
|
|
my $body = $self->{opt}{body} || {}; |
|
48
|
0
|
|
|
|
|
|
my %q = ( |
|
49
|
|
|
|
|
|
|
%required_param, |
|
50
|
|
|
|
|
|
|
%$body, |
|
51
|
|
|
|
|
|
|
); |
|
52
|
0
|
0
|
|
|
|
|
if ($arg->{key}) { |
|
53
|
0
|
|
|
|
|
|
$q{key} = $arg->{key}; |
|
54
|
|
|
|
|
|
|
} |
|
55
|
0
|
|
|
|
|
|
$uri->query_form(\%q); |
|
56
|
0
|
|
|
|
|
|
$request = HTTP::Request->new($http_method => $uri); |
|
57
|
|
|
|
|
|
|
} |
|
58
|
0
|
0
|
|
|
|
|
if ($arg->{auth_driver}) { |
|
59
|
0
|
|
|
|
|
|
$request->header('Authorization', |
|
60
|
|
|
|
|
|
|
sprintf "%s %s", |
|
61
|
|
|
|
|
|
|
$arg->{auth_driver}->token_type, |
|
62
|
|
|
|
|
|
|
$arg->{auth_driver}->access_token); |
|
63
|
|
|
|
|
|
|
} |
|
64
|
0
|
|
|
|
|
|
my $response = $self->{ua}->request($request); |
|
65
|
0
|
0
|
0
|
|
|
|
if ($response->code == 401 && $arg->{auth_driver}) { |
|
66
|
0
|
|
|
|
|
|
$arg->{auth_driver}->refresh; |
|
67
|
0
|
|
|
|
|
|
$request->header('Authorization', |
|
68
|
|
|
|
|
|
|
sprintf "%s %s", |
|
69
|
|
|
|
|
|
|
$arg->{auth_driver}->token_type, |
|
70
|
|
|
|
|
|
|
$arg->{auth_driver}->access_token); |
|
71
|
0
|
|
|
|
|
|
$response = $self->{ua}->request($request); |
|
72
|
|
|
|
|
|
|
} |
|
73
|
0
|
0
|
|
|
|
|
unless ($response->is_success) { |
|
74
|
0
|
|
|
|
|
|
$self->_die_with_error($response); |
|
75
|
|
|
|
|
|
|
} |
|
76
|
0
|
0
|
|
|
|
|
if ($response->code == 204) { |
|
77
|
0
|
|
|
|
|
|
return 1; |
|
78
|
|
|
|
|
|
|
} |
|
79
|
0
|
0
|
|
|
|
|
return $response->header('content-type') =~ m!^application/json! |
|
80
|
|
|
|
|
|
|
? $self->{json_parser}->decode(decode_utf8($response->content)) |
|
81
|
|
|
|
|
|
|
: $response->content |
|
82
|
|
|
|
|
|
|
; |
|
83
|
|
|
|
|
|
|
} |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub _die_with_error { |
|
86
|
0
|
|
|
0
|
|
|
my ($self, $response) = @_; |
|
87
|
0
|
|
|
|
|
|
my $err_str = $response->status_line; |
|
88
|
0
|
0
|
0
|
|
|
|
if ($response->content |
|
89
|
|
|
|
|
|
|
&& $response->header('content-type') =~ m!^application/json!) { |
|
90
|
0
|
|
|
|
|
|
my $content = $self->{json_parser}->decode(decode_utf8($response->content)); |
|
91
|
0
|
|
|
|
|
|
$err_str = "$err_str: $content->{error}{message}"; |
|
92
|
|
|
|
|
|
|
} |
|
93
|
0
|
|
|
|
|
|
die $err_str; |
|
94
|
|
|
|
|
|
|
} |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
1; |
|
97
|
|
|
|
|
|
|
__END__ |