line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Dimona; |
2
|
1
|
|
|
1
|
|
71555
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
32
|
|
3
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
30
|
|
4
|
1
|
|
|
1
|
|
675
|
use LWP::UserAgent; |
|
1
|
|
|
|
|
48644
|
|
|
1
|
|
|
|
|
56
|
|
5
|
1
|
|
|
1
|
|
634
|
use JSON::MaybeXS qw( encode_json decode_json ); |
|
1
|
|
|
|
|
6229
|
|
|
1
|
|
|
|
|
547
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = 0.02; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub new { |
10
|
1
|
|
|
1
|
1
|
654
|
my ($class, %params) = @_; |
11
|
1
|
50
|
|
|
|
6
|
die 'api_key required' unless defined $params{api_key}; |
12
|
|
|
|
|
|
|
return bless { |
13
|
|
|
|
|
|
|
debug => $params{debug}, |
14
|
|
|
|
|
|
|
api_key => ($params{api_key} || die 'api_key is required'), |
15
|
|
|
|
|
|
|
ua => LWP::UserAgent->new( |
16
|
1
|
50
|
50
|
|
|
17
|
timeout => exists $params{timeout} ? $params{timeout} : 5, |
17
|
|
|
|
|
|
|
), |
18
|
|
|
|
|
|
|
}, $class; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub _request { |
22
|
0
|
|
|
0
|
|
|
my ($self, $method, $url, $params) = @_; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
my $res = $self->{ua}->$method( |
25
|
|
|
|
|
|
|
'https://camisadimona.com.br/api/' . $url, |
26
|
|
|
|
|
|
|
'api-key' => $self->{api_key}, |
27
|
0
|
0
|
|
|
|
|
'Accept' => 'application/json', |
28
|
|
|
|
|
|
|
'Content-Type' => 'application/json', |
29
|
|
|
|
|
|
|
($params ? ('Content' => encode_json($params)) : ()) |
30
|
|
|
|
|
|
|
); |
31
|
0
|
|
|
|
|
|
my $data; |
32
|
0
|
|
|
|
|
|
eval { $data = decode_json($res->decoded_content) }; |
|
0
|
|
|
|
|
|
|
33
|
0
|
0
|
|
|
|
|
$data = { error => $res->decoded_content } unless $data; |
34
|
0
|
|
|
|
|
|
return $data; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub create_order { |
38
|
0
|
|
|
0
|
1
|
|
my ($self, $params) = @_; |
39
|
0
|
|
|
|
|
|
return $self->_request('post', 'v2/order', $params); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub list_orders { |
43
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
44
|
0
|
|
|
|
|
|
return $self->_request('get', 'v2/orders'); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub get_order { |
48
|
0
|
|
|
0
|
1
|
|
my ($self, $order_id) = @_; |
49
|
0
|
|
|
|
|
|
return $self->_request('get', 'v2/order/' . $order_id); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub get_order_tracking { |
53
|
0
|
|
|
0
|
1
|
|
my ($self, $order_id) = @_; |
54
|
0
|
|
|
|
|
|
return $self->_request('get', 'v2/order/' . $order_id . '/tracking'); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub get_order_timeline { |
58
|
0
|
|
|
0
|
1
|
|
my ($self, $order_id) = @_; |
59
|
0
|
|
|
|
|
|
return $self->_request('get', 'v2/order/' . $order_id . '/timeline'); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub product_availability { |
63
|
0
|
|
|
0
|
1
|
|
my ($self, $sku) = @_; |
64
|
0
|
|
|
|
|
|
return $self->_request('get', 'v2/sku/' . $sku . '/availability'); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub quote_shipping { |
68
|
0
|
|
|
0
|
0
|
|
my ($self, $params) = @_; |
69
|
0
|
|
|
|
|
|
return $self->_request('post', 'v2/shipping', $params); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
1; |
74
|
|
|
|
|
|
|
__END__ |