| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Net::Iugu::Request; |
|
2
|
|
|
|
|
|
|
$Net::Iugu::Request::VERSION = '0.000001'; |
|
3
|
8
|
|
|
8
|
|
3136
|
use Moo; |
|
|
8
|
|
|
|
|
8
|
|
|
|
8
|
|
|
|
|
33
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
8
|
|
|
8
|
|
6652
|
use LWP::UserAgent; |
|
|
8
|
|
|
|
|
251350
|
|
|
|
8
|
|
|
|
|
361
|
|
|
6
|
8
|
|
|
8
|
|
67
|
use HTTP::Headers; |
|
|
8
|
|
|
|
|
10
|
|
|
|
8
|
|
|
|
|
156
|
|
|
7
|
8
|
|
|
8
|
|
29
|
use HTTP::Request; |
|
|
8
|
|
|
|
|
11
|
|
|
|
8
|
|
|
|
|
173
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
8
|
|
|
8
|
|
1650
|
use JSON qw{ from_json to_json }; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use MIME::Base64 qw{ encode_base64 }; |
|
11
|
|
|
|
|
|
|
use String::CamelCase qw{ decamelize }; |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
has 'base_uri' => ( |
|
14
|
|
|
|
|
|
|
is => 'ro', |
|
15
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
my ($self) = @_; |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
return $self->base_uri . '/' . $self->object; |
|
40
|
|
|
|
|
|
|
}, |
|
41
|
|
|
|
|
|
|
); |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
has 'ua' => ( |
|
44
|
|
|
|
|
|
|
is => 'ro', |
|
45
|
|
|
|
|
|
|
lazy => 1, |
|
46
|
|
|
|
|
|
|
builder => sub { LWP::UserAgent->new }, |
|
47
|
|
|
|
|
|
|
); |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
has 'headers' => ( |
|
50
|
|
|
|
|
|
|
is => 'ro', |
|
51
|
|
|
|
|
|
|
lazy => 1, |
|
52
|
|
|
|
|
|
|
builder => sub { |
|
53
|
|
|
|
|
|
|
my ($self) = @_; |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
my $auth = 'Basic ' . encode_base64( $self->token . ':', '' ); |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
return HTTP::Headers->new( |
|
58
|
|
|
|
|
|
|
'Authorization' => $auth, |
|
59
|
|
|
|
|
|
|
'Content-Type' => 'application/json', |
|
60
|
|
|
|
|
|
|
); |
|
61
|
|
|
|
|
|
|
}, |
|
62
|
|
|
|
|
|
|
); |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub request { |
|
65
|
|
|
|
|
|
|
my ( $self, $method, $uri, $data ) = @_; |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
my $content = $data ? to_json $data : undef; |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
my $req = HTTP::Request->new( |
|
70
|
|
|
|
|
|
|
$method => $uri, |
|
71
|
|
|
|
|
|
|
$self->headers, |
|
72
|
|
|
|
|
|
|
$content, |
|
73
|
|
|
|
|
|
|
); |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
my $res = $self->ua->request($req); |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
return from_json $res->content; |
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
1; |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
# ABSTRACT: Net::Iugu::Request - General HTTP requests to Iugu API |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
__END__ |