line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Nakamap; |
2
|
6
|
|
|
6
|
|
978409
|
use 5.008_001; |
|
6
|
|
|
|
|
25
|
|
|
6
|
|
|
|
|
315
|
|
3
|
6
|
|
|
6
|
|
5680
|
use HTTP::Request::Common; |
|
6
|
|
|
|
|
134153
|
|
|
6
|
|
|
|
|
571
|
|
4
|
6
|
|
|
6
|
|
7920
|
use JSON::XS; |
|
6
|
|
|
|
|
88915
|
|
|
6
|
|
|
|
|
519
|
|
5
|
6
|
|
|
6
|
|
2571
|
use LWP::UserAgent; |
|
6
|
|
|
|
|
101741
|
|
|
6
|
|
|
|
|
185
|
|
6
|
6
|
|
|
6
|
|
12200
|
use Mouse; |
|
6
|
|
|
|
|
267215
|
|
|
6
|
|
|
|
|
40
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
has ua => ( |
11
|
|
|
|
|
|
|
is => 'rw', |
12
|
|
|
|
|
|
|
lazy => 1, |
13
|
|
|
|
|
|
|
default => sub { |
14
|
|
|
|
|
|
|
return LWP::UserAgent->new(), |
15
|
|
|
|
|
|
|
}, |
16
|
|
|
|
|
|
|
); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
has client_id => ( is => 'rw', isa => 'Str' ); |
19
|
|
|
|
|
|
|
has client_secret => ( is => 'rw', isa => 'Str' ); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
has token => ( |
22
|
|
|
|
|
|
|
is => 'rw', |
23
|
|
|
|
|
|
|
isa => 'Str', |
24
|
|
|
|
|
|
|
lazy => 1, |
25
|
|
|
|
|
|
|
default => sub { '' }, |
26
|
|
|
|
|
|
|
); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
has auth_ep => ( |
29
|
|
|
|
|
|
|
is => 'rw', |
30
|
|
|
|
|
|
|
isa => 'Str', |
31
|
|
|
|
|
|
|
lazy => 1, |
32
|
|
|
|
|
|
|
default => sub { 'https://nakamap.com' }, |
33
|
|
|
|
|
|
|
); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
has api_ep => ( |
36
|
|
|
|
|
|
|
is => 'rw', |
37
|
|
|
|
|
|
|
isa => 'Str', |
38
|
|
|
|
|
|
|
lazy => 1, |
39
|
|
|
|
|
|
|
default => sub { 'https://thanks.nakamap.com' }, |
40
|
|
|
|
|
|
|
); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
has last_error => ( |
43
|
|
|
|
|
|
|
is => 'rw', |
44
|
|
|
|
|
|
|
isa => 'Str', |
45
|
|
|
|
|
|
|
lazy => 1, |
46
|
|
|
|
|
|
|
default => sub { '' }, |
47
|
|
|
|
|
|
|
); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub auth_uri { |
50
|
1
|
|
|
1
|
1
|
4716
|
my ($self, $params) = @_; |
51
|
|
|
|
|
|
|
|
52
|
1
|
|
|
|
|
13
|
my $uri = URI->new($self->auth_ep . '/dialog/oauth'); |
53
|
1
|
50
|
|
|
|
10475
|
$uri->query_form( |
54
|
|
|
|
|
|
|
client_id => $self->client_id, |
55
|
|
|
|
|
|
|
response_type => $params->{response_type}, |
56
|
|
|
|
|
|
|
scope => $params->{scope}, |
57
|
|
|
|
|
|
|
($params->{redirect_uri} ? (redirect_uri => $params->{redirect_uri}) : ()), |
58
|
|
|
|
|
|
|
); |
59
|
|
|
|
|
|
|
|
60
|
1
|
|
|
|
|
238
|
return $uri; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub auth_code { |
64
|
1
|
|
|
1
|
1
|
2505
|
my ($self, $params) = @_; |
65
|
|
|
|
|
|
|
|
66
|
1
|
|
|
|
|
12
|
my $uri = URI->new($self->api_ep . '/oauth/access_token'); |
67
|
1
|
50
|
|
|
|
81
|
$uri->query_form( |
68
|
|
|
|
|
|
|
client_id => $self->client_id, |
69
|
|
|
|
|
|
|
client_secret => $self->client_secret, |
70
|
|
|
|
|
|
|
grant_type => 'authorization_code', |
71
|
|
|
|
|
|
|
code => $params->{code}, |
72
|
|
|
|
|
|
|
($params->{redirect_uri} ? (redirect_uri => $params->{redirect_uri}) : ()), |
73
|
|
|
|
|
|
|
); |
74
|
|
|
|
|
|
|
|
75
|
1
|
|
|
|
|
159
|
my $res = $self->ua->post($uri); |
76
|
|
|
|
|
|
|
|
77
|
1
|
50
|
|
|
|
137
|
if ($res->is_success) { |
78
|
1
|
|
|
|
|
77
|
return decode_json($res->content); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
else { |
81
|
0
|
|
|
|
|
0
|
$self->last_error($res->content); |
82
|
0
|
|
|
|
|
0
|
return undef; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub get { |
87
|
2
|
|
|
2
|
1
|
7298
|
my ($self, $path, $params) = @_; |
88
|
|
|
|
|
|
|
|
89
|
2
|
|
50
|
|
|
23
|
$params ||= {}; |
90
|
|
|
|
|
|
|
|
91
|
2
|
|
33
|
|
|
14
|
my $token = $params->{token} || $self->token; |
92
|
|
|
|
|
|
|
|
93
|
2
|
|
|
|
|
14
|
my $uri = URI->new($self->api_ep . $path); |
94
|
2
|
50
|
|
|
|
17579
|
$uri->query_form( |
95
|
|
|
|
|
|
|
( $token ? ( token => $token ) : () ), |
96
|
|
|
|
|
|
|
%$params, |
97
|
|
|
|
|
|
|
); |
98
|
|
|
|
|
|
|
|
99
|
2
|
|
|
|
|
312
|
my $res = $self->ua->get($uri); |
100
|
|
|
|
|
|
|
|
101
|
2
|
100
|
|
|
|
201
|
if ($res->is_success) { |
102
|
1
|
|
|
|
|
72
|
return decode_json($res->content); |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
else { |
105
|
1
|
|
|
|
|
63
|
$self->last_error($res->content); |
106
|
1
|
|
|
|
|
51
|
return undef; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub post { |
111
|
4
|
|
|
4
|
1
|
15524
|
my ($self, $path, $params, $files) = @_; |
112
|
|
|
|
|
|
|
|
113
|
4
|
|
100
|
|
|
30
|
$params ||= {}; |
114
|
|
|
|
|
|
|
|
115
|
4
|
|
33
|
|
|
43
|
my $token = $params->{token} || $self->token; |
116
|
4
|
50
|
|
|
|
28
|
$params->{token} = $token if $token; |
117
|
|
|
|
|
|
|
|
118
|
4
|
|
|
|
|
7
|
my $res; |
119
|
|
|
|
|
|
|
|
120
|
4
|
100
|
|
|
|
28
|
if ($files) { |
121
|
2
|
|
|
|
|
19
|
for my $name (keys %$files) { |
122
|
2
|
|
|
|
|
7
|
my $file = $files->{$name}; |
123
|
|
|
|
|
|
|
|
124
|
2
|
100
|
|
|
|
10
|
if (ref $file) { |
125
|
1
|
|
|
|
|
10
|
$params->{$name} = [ |
126
|
|
|
|
|
|
|
undef, |
127
|
|
|
|
|
|
|
'upload', |
128
|
|
|
|
|
|
|
'Content-Type' => 'application/octet-stream', |
129
|
|
|
|
|
|
|
'Content' => $$file, |
130
|
|
|
|
|
|
|
]; |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
else { |
133
|
1
|
|
|
|
|
7
|
$params->{$name} = [$files->{$name}]; |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
2
|
|
|
|
|
26
|
$res = $self->ua->request( |
138
|
|
|
|
|
|
|
POST $self->api_ep . $path, |
139
|
|
|
|
|
|
|
Content_Type => 'form-data', |
140
|
|
|
|
|
|
|
Content => [%$params], |
141
|
|
|
|
|
|
|
); |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
else { |
144
|
2
|
|
|
|
|
25
|
my $uri = URI->new($self->api_ep . $path); |
145
|
2
|
|
|
|
|
11711
|
$uri->query_form(%$params); |
146
|
|
|
|
|
|
|
|
147
|
2
|
|
|
|
|
378
|
$res = $self->ua->post($uri); |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
4
|
100
|
|
|
|
35549
|
if ($res->is_success) { |
151
|
3
|
|
|
|
|
264
|
return decode_json($res->content); |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
else { |
154
|
1
|
|
|
|
|
64
|
$self->last_error($res->content); |
155
|
1
|
|
|
|
|
61
|
return undef; |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable(); |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
__END__ |