line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Iugu::Request; |
2
|
|
|
|
|
|
|
$Net::Iugu::Request::VERSION = '0.000002'; |
3
|
8
|
|
|
8
|
|
3255
|
use Moo; |
|
8
|
|
|
|
|
14
|
|
|
8
|
|
|
|
|
29
|
|
4
|
|
|
|
|
|
|
|
5
|
8
|
|
|
8
|
|
6806
|
use LWP::UserAgent; |
|
8
|
|
|
|
|
265526
|
|
|
8
|
|
|
|
|
383
|
|
6
|
8
|
|
|
8
|
|
73
|
use HTTP::Headers; |
|
8
|
|
|
|
|
8
|
|
|
8
|
|
|
|
|
336
|
|
7
|
8
|
|
|
8
|
|
33
|
use HTTP::Request; |
|
8
|
|
|
|
|
8
|
|
|
8
|
|
|
|
|
202
|
|
8
|
|
|
|
|
|
|
|
9
|
8
|
|
|
8
|
|
5607
|
use JSON qw{ from_json to_json }; |
|
8
|
|
|
|
|
79612
|
|
|
8
|
|
|
|
|
45
|
|
10
|
8
|
|
|
8
|
|
5171
|
use MIME::Base64 qw{ encode_base64 }; |
|
8
|
|
|
|
|
4645
|
|
|
8
|
|
|
|
|
550
|
|
11
|
8
|
|
|
8
|
|
3518
|
use String::CamelCase qw{ decamelize }; |
|
8
|
|
|
|
|
3503
|
|
|
8
|
|
|
|
|
2645
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
has 'base_uri' => ( |
14
|
|
|
|
|
|
|
is => 'ro', |
15
|
0
|
|
|
0
|
|
|
builder => sub { 'https://api.iugu.com/v1' }, |
16
|
|
|
|
|
|
|
); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
has 'object' => ( |
19
|
|
|
|
|
|
|
is => 'rw', |
20
|
|
|
|
|
|
|
default => sub { |
21
|
|
|
|
|
|
|
my $pkg = ref shift; |
22
|
|
|
|
|
|
|
my @parts = split /::/, $pkg; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
return decamelize $parts[-1]; |
25
|
|
|
|
|
|
|
}, |
26
|
|
|
|
|
|
|
); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
has 'token' => ( |
29
|
|
|
|
|
|
|
is => 'rw', |
30
|
|
|
|
|
|
|
required => 1, |
31
|
|
|
|
|
|
|
); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
has 'endpoint' => ( |
34
|
|
|
|
|
|
|
is => 'ro', |
35
|
|
|
|
|
|
|
lazy => 1, |
36
|
|
|
|
|
|
|
builder => sub { |
37
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
38
|
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
|
return $self->base_uri . '/' . $self->object; |
40
|
|
|
|
|
|
|
}, |
41
|
|
|
|
|
|
|
); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
has 'ua' => ( |
44
|
|
|
|
|
|
|
is => 'ro', |
45
|
|
|
|
|
|
|
lazy => 1, |
46
|
0
|
|
|
0
|
|
|
builder => sub { LWP::UserAgent->new }, |
47
|
|
|
|
|
|
|
); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
has 'headers' => ( |
50
|
|
|
|
|
|
|
is => 'ro', |
51
|
|
|
|
|
|
|
lazy => 1, |
52
|
|
|
|
|
|
|
builder => sub { |
53
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
my $auth = 'Basic ' . encode_base64( $self->token . ':', '' ); |
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
|
return HTTP::Headers->new( |
58
|
|
|
|
|
|
|
'Authorization' => $auth, |
59
|
|
|
|
|
|
|
'Content-Type' => 'application/json', |
60
|
|
|
|
|
|
|
); |
61
|
|
|
|
|
|
|
}, |
62
|
|
|
|
|
|
|
); |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub request { |
65
|
0
|
|
|
0
|
1
|
|
my ( $self, $method, $uri, $data ) = @_; |
66
|
|
|
|
|
|
|
|
67
|
0
|
0
|
|
|
|
|
my $content = $data ? to_json $data : undef; |
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
my $req = HTTP::Request->new( |
70
|
|
|
|
|
|
|
$method => $uri, |
71
|
|
|
|
|
|
|
$self->headers, |
72
|
|
|
|
|
|
|
$content, |
73
|
|
|
|
|
|
|
); |
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
my $res = $self->ua->request($req); |
76
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
|
return from_json $res->content; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
1; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
# ABSTRACT: Net::Iugu::Request - General HTTP requests to Iugu API |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
__END__ |