line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojar::Google::Analytics::Response; |
2
|
3
|
|
|
3
|
|
14
|
use Mojo::Base -base; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
21
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
our $VERSION = 1.001; |
5
|
|
|
|
|
|
|
|
6
|
3
|
|
|
3
|
|
2286
|
use Mojar::Util 'snakecase'; |
|
3
|
|
|
|
|
91856
|
|
|
3
|
|
|
|
|
1153
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# Attributes |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
has [qw(content error success)]; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has start_index => 1; |
13
|
|
|
|
|
|
|
has contains_sampled_data => !!0; |
14
|
|
|
|
|
|
|
has column_headers => sub {[]}; |
15
|
|
|
|
|
|
|
has total_results => 0; |
16
|
|
|
|
|
|
|
has rows => sub {[]}; |
17
|
|
|
|
|
|
|
has [qw(items_per_page profile_info next_link totals_for_all_results)]; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# Public methods |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub parse { |
22
|
0
|
|
|
0
|
1
|
|
my ($self, $res) = @_; |
23
|
|
|
|
|
|
|
|
24
|
0
|
0
|
|
|
|
|
if ($res->is_success) { |
25
|
0
|
|
|
|
|
|
delete @$self{qw(content error)}; |
26
|
0
|
|
|
|
|
|
my $j = $res->json; |
27
|
0
|
|
|
|
|
|
$self->{snakecase($_)} = $j->{$_} for keys %$j; |
28
|
0
|
|
|
|
|
|
return $self->success(1); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
else { |
31
|
|
|
|
|
|
|
# Got a transaction-level error |
32
|
0
|
|
0
|
|
|
|
$self->error({ |
|
|
|
0
|
|
|
|
|
33
|
|
|
|
|
|
|
code => $res->code || 408, |
34
|
|
|
|
|
|
|
message => $res->message // 'Possible timeout' |
35
|
|
|
|
|
|
|
}); |
36
|
|
|
|
|
|
|
|
37
|
0
|
0
|
0
|
|
|
|
if ($res and my $j = $res->json) { |
38
|
|
|
|
|
|
|
# Got JSON body in response |
39
|
0
|
|
|
|
|
|
$self->content($j); |
40
|
0
|
0
|
0
|
|
|
|
my $m = ref($j->{error}) ? $j->{error} : {message => $j->{error} // ''}; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# Got message record |
43
|
0
|
|
0
|
|
|
|
$self->{error}{code} = $m->{code} || $self->{error}{code} // 0; |
|
|
|
0
|
|
|
|
|
44
|
|
|
|
|
|
|
# Take note of headline error |
45
|
0
|
|
0
|
|
|
|
my $msg = ($m->{message} // $j->{message}) ."\n"; |
46
|
|
|
|
|
|
|
|
47
|
0
|
|
0
|
|
|
|
for my $e (@{$m->{errors} // []}) { |
|
0
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# Take note of next listed error |
49
|
|
|
|
|
|
|
$msg .= sprintf "%s at %s\n%s\n", |
50
|
0
|
|
0
|
|
|
|
$e->{reason}, ($e->{location} // $e->{domain}), $e->{message}; |
51
|
|
|
|
|
|
|
} |
52
|
0
|
|
|
|
|
|
$self->{error}{message} = $msg; |
53
|
|
|
|
|
|
|
} |
54
|
0
|
|
|
|
|
|
return undef; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
1; |
59
|
|
|
|
|
|
|
__END__ |