line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WebService::Pixela; |
2
|
6
|
|
|
6
|
|
227444
|
use 5.010001; |
|
6
|
|
|
|
|
29
|
|
3
|
6
|
|
|
6
|
|
30
|
use strict; |
|
6
|
|
|
|
|
15
|
|
|
6
|
|
|
|
|
150
|
|
4
|
6
|
|
|
6
|
|
30
|
use warnings; |
|
6
|
|
|
|
|
9
|
|
|
6
|
|
|
|
|
146
|
|
5
|
6
|
|
|
6
|
|
4140
|
use HTTP::Tiny; |
|
6
|
|
|
|
|
256313
|
|
|
6
|
|
|
|
|
248
|
|
6
|
6
|
|
|
6
|
|
54
|
use Carp; |
|
6
|
|
|
|
|
14
|
|
|
6
|
|
|
|
|
345
|
|
7
|
6
|
|
|
6
|
|
2376
|
use WebService::Pixela::User; |
|
6
|
|
|
|
|
20
|
|
|
6
|
|
|
|
|
176
|
|
8
|
6
|
|
|
6
|
|
2128
|
use WebService::Pixela::Graph; |
|
6
|
|
|
|
|
19
|
|
|
6
|
|
|
|
|
193
|
|
9
|
6
|
|
|
6
|
|
2111
|
use WebService::Pixela::Pixel; |
|
6
|
|
|
|
|
17
|
|
|
6
|
|
|
|
|
206
|
|
10
|
6
|
|
|
6
|
|
2078
|
use WebService::Pixela::Webhook; |
|
6
|
|
|
|
|
16
|
|
|
6
|
|
|
|
|
182
|
|
11
|
6
|
|
|
6
|
|
3093
|
use URI; |
|
6
|
|
|
|
|
25986
|
|
|
6
|
|
|
|
|
187
|
|
12
|
6
|
|
|
6
|
|
40
|
use JSON; |
|
6
|
|
|
|
|
16
|
|
|
6
|
|
|
|
|
35
|
|
13
|
|
|
|
|
|
|
use Class::Accessor::Lite( |
14
|
6
|
|
|
|
|
51
|
new => 0, |
15
|
|
|
|
|
|
|
ro => [qw/ |
16
|
|
|
|
|
|
|
user |
17
|
|
|
|
|
|
|
graph |
18
|
|
|
|
|
|
|
pixel |
19
|
|
|
|
|
|
|
webhook |
20
|
|
|
|
|
|
|
_agent |
21
|
|
|
|
|
|
|
/], |
22
|
|
|
|
|
|
|
rw => [qw/ |
23
|
|
|
|
|
|
|
username |
24
|
|
|
|
|
|
|
token |
25
|
|
|
|
|
|
|
base_url |
26
|
|
|
|
|
|
|
/], |
27
|
6
|
|
|
6
|
|
3420
|
); |
|
6
|
|
|
|
|
7298
|
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
our $VERSION = "0.01"; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub new { |
32
|
43
|
|
|
43
|
1
|
109651
|
my ($class,%args) = @_; |
33
|
43
|
|
|
|
|
114
|
my $self = bless +{}, $class; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# initalize |
36
|
43
|
|
66
|
|
|
432
|
$self->{username} = $args{username} // croak 'require username'; |
37
|
42
|
|
66
|
|
|
218
|
$self->{token} = $args{token} // (carp('not input token'), undef); |
38
|
42
|
|
100
|
|
|
191
|
$self->{base_url} = $args{base_url} // "https://pixe.la/"; |
39
|
42
|
|
100
|
|
|
148
|
$self->{decode} = $args{decode} // 1; |
40
|
42
|
|
|
|
|
165
|
$self->{_agent} = HTTP::Tiny->new(); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
#WebService::Pixela instances |
43
|
42
|
|
|
|
|
3584
|
$self->{user} = WebService::Pixela::User->new($self); |
44
|
42
|
|
|
|
|
154
|
$self->{graph} = WebService::Pixela::Graph->new($self); |
45
|
42
|
|
|
|
|
141
|
$self->{pixel} = WebService::Pixela::Pixel->new($self); |
46
|
42
|
|
|
|
|
151
|
$self->{webhook} = WebService::Pixela::Webhook->new($self); |
47
|
|
|
|
|
|
|
|
48
|
42
|
|
|
|
|
147
|
return $self; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub decode { |
52
|
20
|
|
|
20
|
1
|
2441
|
my $self = shift; |
53
|
20
|
100
|
|
|
|
48
|
if (@_){ |
54
|
7
|
|
|
|
|
16
|
$self->{decode} = shift; |
55
|
7
|
|
|
|
|
17
|
return $self; |
56
|
|
|
|
|
|
|
} |
57
|
13
|
|
|
|
|
85
|
return $self->{decode}; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub _decode_or_simple_return_from_json { |
61
|
2
|
|
|
2
|
|
9
|
my ($self,$rev_json) = @_; |
62
|
|
|
|
|
|
|
|
63
|
2
|
100
|
|
|
|
6
|
unless ($self->decode){ |
64
|
1
|
|
|
|
|
5
|
return $rev_json; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
1
|
|
|
|
|
22
|
return decode_json($rev_json); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub _request { |
71
|
1
|
|
|
1
|
|
13
|
my ($self,$method,$path,$params) = @_; |
72
|
|
|
|
|
|
|
|
73
|
1
|
|
|
|
|
13
|
my $uri = URI->new('v1/'.$path)->abs($self->base_url); |
74
|
|
|
|
|
|
|
|
75
|
1
|
|
|
|
|
9531
|
my $receive_json = $self->_agent->request($method, $uri->as_string, $params)->{"content"}; |
76
|
|
|
|
|
|
|
|
77
|
1
|
|
|
|
|
35
|
return $self->_decode_or_simple_return_from_json($receive_json); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub query_request { |
81
|
1
|
|
|
1
|
0
|
13
|
my ($self,$method,$path,$query) = @_; |
82
|
|
|
|
|
|
|
|
83
|
1
|
|
|
|
|
7
|
my $uri = URI->new('v1/'.$path)->abs($self->base_url); |
84
|
|
|
|
|
|
|
|
85
|
1
|
50
|
|
|
|
335
|
if ($query){ |
86
|
1
|
|
|
|
|
11
|
$uri->query_form($query); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
1
|
|
|
|
|
125
|
return $self->_agent->request($method, $uri->as_string)->{"content"}; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub request { |
94
|
1
|
|
|
1
|
0
|
10
|
my ($self,$method,$path,$content) = @_; |
95
|
|
|
|
|
|
|
|
96
|
1
|
|
|
|
|
4
|
my $params = {}; |
97
|
1
|
50
|
33
|
|
|
9
|
if (defined $content && %$content){ |
98
|
1
|
|
|
|
|
9
|
$params->{content} = encode_json($content); |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
1
|
|
|
|
|
5
|
return $self->_request($method,$path,$params); |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub request_with_xuser_in_header { |
105
|
1
|
|
|
1
|
0
|
11
|
my ($self,$method,$path,$content) = @_; |
106
|
|
|
|
|
|
|
|
107
|
1
|
|
|
|
|
5
|
my $params = { |
108
|
|
|
|
|
|
|
headers => { 'X-USER-TOKEN' => $self->token }, |
109
|
|
|
|
|
|
|
}; |
110
|
|
|
|
|
|
|
|
111
|
1
|
50
|
33
|
|
|
13
|
if (defined $content && %$content){ |
112
|
1
|
|
|
|
|
7
|
$params->{content} = encode_json($content); |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
1
|
|
|
|
|
5
|
return $self->_request($method,$path,$params); |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub request_with_content_length_in_header { |
119
|
0
|
|
|
0
|
0
|
|
my ($self,$method,$path,$length) = @_; |
120
|
|
|
|
|
|
|
|
121
|
0
|
|
0
|
|
|
|
$length //= 0; |
122
|
|
|
|
|
|
|
|
123
|
0
|
|
|
|
|
|
my $params = { |
124
|
|
|
|
|
|
|
headers => { 'Content-Length' => $length }, |
125
|
|
|
|
|
|
|
}; |
126
|
|
|
|
|
|
|
|
127
|
0
|
|
|
|
|
|
return $self->_request($method,$path); |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub request_with_dual_in_header { |
131
|
0
|
|
|
0
|
0
|
|
my ($self,$method,$path,$length) = @_; |
132
|
|
|
|
|
|
|
|
133
|
0
|
|
0
|
|
|
|
$length //= 0; |
134
|
|
|
|
|
|
|
|
135
|
0
|
|
|
|
|
|
my $params = { |
136
|
|
|
|
|
|
|
headers => { |
137
|
|
|
|
|
|
|
'X-USER-TOKEN' => $self->token, |
138
|
|
|
|
|
|
|
'Content-Length' => $length, |
139
|
|
|
|
|
|
|
}, |
140
|
|
|
|
|
|
|
}; |
141
|
|
|
|
|
|
|
|
142
|
0
|
|
|
|
|
|
return $self->_request($method,$path,$params); |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
1; |
147
|
|
|
|
|
|
|
__END__ |