line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Moip::V2::Endpoint; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
7
|
use IO::Socket::SSL; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
12
|
|
4
|
2
|
|
|
2
|
|
294
|
use MIME::Base64; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
97
|
|
5
|
2
|
|
|
2
|
|
7
|
use Furl; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
43
|
|
6
|
2
|
|
|
2
|
|
6
|
use JSON::MaybeXS (); |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
22
|
|
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
5
|
use Moo; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
10
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
my $JSON = JSON::MaybeXS->new->utf8; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has 'path', is => 'ro', required => 1; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
has 'api_url', is => 'ro',required => 1; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
has 'ua', is => 'ro', required => 1; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
has 'token', is => 'ro', required => 1; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
has 'key', is => 'ro', required => 1; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
has 'client_id', is => 'ro'; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
has 'client_secret', is => 'ro'; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
has 'access_token', is => 'ro'; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
has '_basic_auth_token', is => 'ro', lazy => 1, default => sub { |
29
|
|
|
|
|
|
|
my $self = shift; |
30
|
|
|
|
|
|
|
'Basic '.MIME::Base64::encode_base64( $self->token .':'. $self->key, ''); |
31
|
|
|
|
|
|
|
}; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
has 'url', is => 'ro', init_arg => undef, default => sub { |
34
|
|
|
|
|
|
|
my $self = shift; |
35
|
|
|
|
|
|
|
join '/', $self->api_url, $self->path; |
36
|
|
|
|
|
|
|
}; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub _authorization_string { |
39
|
6
|
|
|
6
|
|
6
|
my $self = shift; |
40
|
6
|
100
|
|
|
|
9
|
if ($self->{is_oauth}) { |
41
|
2
|
100
|
|
|
|
15
|
my $access_token = $self->access_token |
42
|
|
|
|
|
|
|
or die "Can't build OAuth authorization. access_token is missing."; |
43
|
|
|
|
|
|
|
|
44
|
1
|
|
|
|
|
6
|
return "OAuth $access_token"; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
4
|
|
|
|
|
57
|
$self->_basic_auth_token; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub get { |
52
|
5
|
|
|
5
|
0
|
6
|
my ($self, $id) = @_; |
53
|
|
|
|
|
|
|
|
54
|
5
|
|
66
|
|
|
25
|
my $url = join '/', $self->url, $id || (); |
55
|
5
|
|
|
|
|
10
|
$self->ua->get($url, [ |
56
|
|
|
|
|
|
|
'Content-Type' => 'application/json', |
57
|
|
|
|
|
|
|
'Authorization' => $self->_authorization_string |
58
|
|
|
|
|
|
|
]); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub post { |
62
|
1
|
|
|
1
|
1
|
1
|
my ($self, $data) = @_; |
63
|
|
|
|
|
|
|
|
64
|
1
|
|
|
|
|
5
|
$self->ua->post($self->url, [ |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
'Content-Type' => 'application/json', |
67
|
|
|
|
|
|
|
'Authorization' => $self->_authorization_string |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
], $JSON->encode($data) ); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub oauth_get { |
73
|
2
|
|
|
2
|
0
|
4
|
my $self = shift; |
74
|
2
|
|
|
|
|
4
|
local $self->{is_oauth} = 1; |
75
|
2
|
|
|
|
|
3
|
$self->get(@_); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub oauth_post { |
79
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
80
|
0
|
|
|
|
|
|
local $self->{is_oauth} = 1; |
81
|
0
|
|
|
|
|
|
$self->post(@_); |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub decode_json { |
86
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
87
|
0
|
|
|
|
|
|
$JSON->decode($_[0]); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
1; |
93
|
|
|
|
|
|
|
__END__ |