line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojar::Google::Analytics::Request; |
2
|
4
|
|
|
4
|
|
35441
|
use Mojo::Base -base; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
27
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
our $VERSION = 0.012; |
5
|
|
|
|
|
|
|
|
6
|
4
|
|
|
4
|
|
788
|
use Carp 'croak'; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
205
|
|
7
|
4
|
|
|
4
|
|
1824
|
use Mojo::Parameters; |
|
4
|
|
|
|
|
82354
|
|
|
4
|
|
|
|
|
25
|
|
8
|
4
|
|
|
4
|
|
135
|
use Mojo::Util 'url_escape'; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
432
|
|
9
|
4
|
|
|
4
|
|
553
|
use POSIX 'strftime'; |
|
4
|
|
|
|
|
5289
|
|
|
4
|
|
|
|
|
26
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# Attributes |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
has 'access_token'; |
14
|
|
|
|
|
|
|
has 'ids'; |
15
|
|
|
|
|
|
|
has dimensions => sub {[]}; |
16
|
|
|
|
|
|
|
has metrics => sub {[]}; |
17
|
|
|
|
|
|
|
has 'segment'; |
18
|
|
|
|
|
|
|
has filters => sub {[]}; |
19
|
|
|
|
|
|
|
has sort => sub {[]}; |
20
|
|
|
|
|
|
|
has start_date => &_today; |
21
|
|
|
|
|
|
|
has end_date => &_today; |
22
|
|
|
|
|
|
|
has start_index => 1; |
23
|
|
|
|
|
|
|
has max_results => 10_000; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# Public methods |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub params { |
28
|
2
|
|
|
2
|
1
|
3291
|
my $self = shift; |
29
|
2
|
|
|
|
|
8
|
my $param = Mojar::Google::Analytics::Request->new(%$self, @_); |
30
|
2
|
|
|
|
|
19
|
my $p = Mojo::Parameters->new; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# Absorb driver params, using defaults if necessary |
33
|
2
|
|
|
|
|
17
|
for (qw(start_date end_date start_index max_results)) { |
34
|
8
|
|
|
|
|
108
|
my $k = $_; |
35
|
8
|
|
|
|
|
17
|
my $v = $param->$k; |
36
|
8
|
|
|
|
|
26
|
delete $param->{$k}; |
37
|
8
|
|
|
|
|
26
|
$k =~ s/_/-/; |
38
|
8
|
|
|
|
|
15
|
$p = $p->append($k => $v); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
2
|
|
|
|
|
26
|
for my $k (qw(dimensions metrics)) { |
42
|
4
|
|
|
|
|
10
|
my $v = $param->$k; |
43
|
4
|
50
|
33
|
|
|
38
|
if (not ref $v or ref $v ne 'ARRAY') { |
|
|
50
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
0
|
|
|
|
|
44
|
0
|
|
|
|
|
0
|
croak "Field $k needs to be an arrayref"; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
elsif (@$v >= 2 and @$v % 2 == 0 and $v->[1] and $v->[1] !~ /[a-z]/) { |
47
|
|
|
|
|
|
|
# Assume hash (declaring datatypes) |
48
|
0
|
|
|
|
|
0
|
my $a = 'ga:'. $v->[2 * 0]; |
49
|
0
|
|
|
|
|
0
|
$a .= ',ga:'. $v->[2 * $_] for 1 .. (@$v / 2 - 1); |
50
|
0
|
|
|
|
|
0
|
$p = $p->append($k => $a); |
51
|
0
|
|
|
|
|
0
|
delete $param->{$k}; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# Absorb everything else |
56
|
2
|
|
|
|
|
5
|
for my $k (keys %$param) { |
57
|
6
|
|
|
|
|
50
|
my $v = $param->$k; |
58
|
6
|
|
|
|
|
19
|
$k =~ s/_/-/; |
59
|
6
|
100
|
|
|
|
8
|
if (ref $v) { |
60
|
|
|
|
|
|
|
# Array ref |
61
|
4
|
|
|
|
|
7
|
$v = join ',', map "ga:$_", @$v; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
else { |
64
|
|
|
|
|
|
|
# Scalar |
65
|
2
|
|
|
|
|
2
|
my $descending = 0; |
66
|
2
|
50
|
33
|
|
|
9
|
$k eq 'sort' and $v =~ s/^-// and $descending = 1; |
67
|
2
|
50
|
|
|
|
8
|
$v = ($descending ? '-ga:' : 'ga:') . $v if defined $v; |
|
|
50
|
|
|
|
|
|
68
|
|
|
|
|
|
|
} |
69
|
6
|
|
|
|
|
8
|
$p = $p->append($k => $v); |
70
|
|
|
|
|
|
|
} |
71
|
2
|
|
|
|
|
24
|
return $p->to_string; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
# Private methods |
75
|
|
|
|
|
|
|
|
76
|
8
|
|
|
8
|
|
889
|
sub _today { strftime '%F', localtime } |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
1; |
79
|
|
|
|
|
|
|
__END__ |