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
|
|
|
|
|
19
|
|
4
|
2
|
|
|
2
|
|
302
|
use MIME::Base64; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
107
|
|
5
|
2
|
|
|
2
|
|
8
|
use Furl; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
58
|
|
6
|
2
|
|
|
2
|
|
8
|
use JSON::MaybeXS (); |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
30
|
|
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
8
|
use Moo; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
11
|
|
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
|
|
7
|
my $self = shift; |
40
|
6
|
100
|
|
|
|
19
|
if ($self->{is_oauth}) { |
41
|
2
|
100
|
|
|
|
25
|
my $access_token = $self->access_token |
42
|
|
|
|
|
|
|
or die "Can't build OAuth authorization. access_token is missing."; |
43
|
|
|
|
|
|
|
|
44
|
1
|
|
|
|
|
17
|
return "OAuth $access_token"; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
4
|
|
|
|
|
101
|
$self->_basic_auth_token; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub get { |
52
|
5
|
|
|
5
|
0
|
8
|
my ($self, $id) = @_; |
53
|
|
|
|
|
|
|
|
54
|
5
|
|
66
|
|
|
38
|
my $url = join '/', $self->url, $id || (); |
55
|
5
|
|
|
|
|
18
|
$self->ua->get($url, [ |
56
|
|
|
|
|
|
|
'Content-Type' => 'application/json', |
57
|
|
|
|
|
|
|
'Authorization' => $self->_authorization_string |
58
|
|
|
|
|
|
|
]); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub post { |
62
|
1
|
|
|
1
|
1
|
3
|
my ($self, $data) = @_; |
63
|
|
|
|
|
|
|
|
64
|
1
|
|
|
|
|
8
|
$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
|
3
|
my $self = shift; |
74
|
2
|
|
|
|
|
5
|
local $self->{is_oauth} = 1; |
75
|
2
|
|
|
|
|
5
|
$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__ |