line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Google::Plus; |
2
|
|
|
|
|
|
|
{ |
3
|
|
|
|
|
|
|
$Google::Plus::VERSION = '0.004'; |
4
|
|
|
|
|
|
|
} |
5
|
1
|
|
|
1
|
|
86368
|
use Mojo::Base -base; |
|
1
|
|
|
|
|
11178
|
|
|
1
|
|
|
|
|
8
|
|
6
|
1
|
|
|
1
|
|
230
|
use v5.10.1; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
44
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
880
|
use Mojo::URL; |
|
1
|
|
|
|
|
100328
|
|
|
1
|
|
|
|
|
13
|
|
9
|
1
|
|
|
1
|
|
1104
|
use Mojo::UserAgent; |
|
1
|
|
|
|
|
773668
|
|
|
1
|
|
|
|
|
18
|
|
10
|
1
|
|
|
1
|
|
51
|
use IO::Socket::SSL 1.37; |
|
1
|
|
|
|
|
42
|
|
|
1
|
|
|
|
|
10
|
|
11
|
1
|
|
|
1
|
|
212
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1090
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
has [qw/key ua/]; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our $service = 'https://www.googleapis.com/plus/v1'; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our %API = ( |
18
|
|
|
|
|
|
|
person => '/people/ID', |
19
|
|
|
|
|
|
|
activities => '/people/ID/activities/COLLECTION', |
20
|
|
|
|
|
|
|
activity => '/activities/ID' |
21
|
|
|
|
|
|
|
); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# transform our api dispatch above into an HTTPS request |
24
|
|
|
|
|
|
|
# returns JSON decoded result or throws exception otherwise |
25
|
|
|
|
|
|
|
sub _request { |
26
|
0
|
|
|
0
|
|
|
my ($self, $api, $id, $args) = @_; |
27
|
|
|
|
|
|
|
|
28
|
0
|
|
|
|
|
|
my $key = $self->key; |
29
|
0
|
|
|
|
|
|
my $ua = $self->ua; |
30
|
|
|
|
|
|
|
|
31
|
0
|
|
|
|
|
|
$api =~ s/ID/$id/; |
32
|
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
|
my $url = Mojo::URL->new(join '', $service => $api); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# $args is a hashref corresponding to optional query parameters (such |
36
|
|
|
|
|
|
|
# as nextPageToken) |
37
|
0
|
0
|
|
|
|
|
if (ref $args eq 'HASH') { |
38
|
0
|
|
|
|
|
|
PARAM: while (my ($k, $v) = each %$args) { |
39
|
0
|
0
|
|
|
|
|
$k eq 'collection' and do { |
40
|
0
|
|
|
|
|
|
my $p = $url->path->to_string; |
41
|
0
|
|
|
|
|
|
$p =~ s/COLLECTION/$v/; |
42
|
0
|
|
|
|
|
|
$url = $url->path($p); |
43
|
0
|
|
|
|
|
|
next PARAM; |
44
|
|
|
|
|
|
|
}; |
45
|
0
|
|
|
|
|
|
$url = $url->query({$k => $v}); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
} |
48
|
0
|
|
|
|
|
|
$url = $url->query({key => $key}); |
49
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
my $tx = $ua->get($url); |
51
|
0
|
0
|
|
|
|
|
$tx->success and return $tx->res->json; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# we never get here, unless something went wrong |
54
|
0
|
|
|
|
|
|
my $message = $tx->error; |
55
|
0
|
0
|
|
|
|
|
$tx->res->json and do { |
56
|
0
|
|
|
|
|
|
my $json_err = $tx->res->json->{error}->{message}; |
57
|
0
|
|
|
|
|
|
$message = join ' ', $message => $json_err; |
58
|
|
|
|
|
|
|
}; |
59
|
0
|
|
|
|
|
|
die "Error: $message"; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub new { |
63
|
0
|
|
|
0
|
1
|
|
my $self = bless {}, shift; |
64
|
|
|
|
|
|
|
|
65
|
0
|
0
|
0
|
|
|
|
croak "API key required" unless $_[0] and $_[0] eq 'key'; |
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
$self->key($_[1]); |
68
|
0
|
|
|
|
|
|
$self->ua(Mojo::UserAgent->new->detect_proxy); |
69
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
$self; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub person { |
74
|
0
|
|
|
0
|
1
|
|
my ($self, $user_id, $fields) = @_; |
75
|
|
|
|
|
|
|
|
76
|
0
|
0
|
|
|
|
|
croak 'user ID required' unless $user_id; |
77
|
0
|
0
|
|
|
|
|
croak 'Invalid user ID' unless $user_id =~ /[0-9]+/; |
78
|
|
|
|
|
|
|
|
79
|
0
|
0
|
|
|
|
|
$fields |
80
|
|
|
|
|
|
|
? $self->_request($API{person} => $user_id, {fields => $fields}) |
81
|
|
|
|
|
|
|
: $self->_request($API{person} => $user_id); |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub activities { |
85
|
0
|
|
|
0
|
1
|
|
my ($self, $user_id, $collection, $next, $fields) = @_; |
86
|
|
|
|
|
|
|
|
87
|
0
|
0
|
|
|
|
|
croak 'user ID required' unless $user_id; |
88
|
0
|
0
|
|
|
|
|
croak 'Invalid user ID' unless $user_id =~ /[0-9]+/; |
89
|
|
|
|
|
|
|
|
90
|
0
|
|
0
|
|
|
|
$collection //= 'public'; |
91
|
|
|
|
|
|
|
|
92
|
0
|
|
|
|
|
|
my %args = (collection => $collection); |
93
|
0
|
0
|
|
|
|
|
$args{pageToken} = $next if $next; |
94
|
0
|
0
|
|
|
|
|
$args{fields} = $fields if $fields; |
95
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
$self->_request($API{activities} => $user_id, \%args); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub activity { |
100
|
0
|
|
|
0
|
1
|
|
my ($self, $activity_id, $fields) = @_; |
101
|
|
|
|
|
|
|
|
102
|
0
|
0
|
|
|
|
|
croak 'activity ID required' unless $activity_id; |
103
|
0
|
0
|
|
|
|
|
croak 'Invalid activity ID' unless $activity_id =~ /\w+/; |
104
|
|
|
|
|
|
|
|
105
|
0
|
0
|
|
|
|
|
$fields |
106
|
|
|
|
|
|
|
? $self->_request($API{activity} => $activity_id, {fields => $fields}) |
107
|
|
|
|
|
|
|
: $self->_request($API{activity} => $activity_id); |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
"Inspired by tempire's Google::Voice :3"; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
__END__ |