line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Easypost; |
2
|
|
|
|
|
|
|
$Net::Easypost::VERSION = '0.20'; |
3
|
6
|
|
|
6
|
|
57260
|
use Carp qw(croak); |
|
6
|
|
|
|
|
15
|
|
|
6
|
|
|
|
|
393
|
|
4
|
|
|
|
|
|
|
|
5
|
6
|
|
|
6
|
|
2161
|
use Net::Easypost::Address; |
|
6
|
|
|
|
|
26
|
|
|
6
|
|
|
|
|
241
|
|
6
|
6
|
|
|
6
|
|
2637
|
use Net::Easypost::Label; |
|
6
|
|
|
|
|
29
|
|
|
6
|
|
|
|
|
226
|
|
7
|
6
|
|
|
6
|
|
2896
|
use Net::Easypost::Parcel; |
|
6
|
|
|
|
|
24
|
|
|
6
|
|
|
|
|
220
|
|
8
|
6
|
|
|
6
|
|
2638
|
use Net::Easypost::Rate; |
|
6
|
|
|
|
|
22
|
|
|
6
|
|
|
|
|
203
|
|
9
|
6
|
|
|
6
|
|
54
|
use Net::Easypost::Request; |
|
6
|
|
|
|
|
18
|
|
|
6
|
|
|
|
|
129
|
|
10
|
6
|
|
|
6
|
|
2804
|
use Net::Easypost::Shipment; |
|
6
|
|
|
|
|
24
|
|
|
6
|
|
|
|
|
214
|
|
11
|
|
|
|
|
|
|
|
12
|
6
|
|
|
6
|
|
49
|
use Moo; |
|
6
|
|
|
|
|
14
|
|
|
6
|
|
|
|
|
28
|
|
13
|
6
|
|
|
6
|
|
1964
|
use namespace::autoclean; |
|
6
|
|
|
|
|
15
|
|
|
6
|
|
|
|
|
49
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# ABSTRACT: Perl client for the Easypost web service |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
has 'requester' => ( |
20
|
|
|
|
|
|
|
is => 'ro', |
21
|
|
|
|
|
|
|
lazy => 1, |
22
|
|
|
|
|
|
|
default => sub { return Net::Easypost::Request->new } |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub verify_address { |
27
|
8
|
|
|
8
|
1
|
33403
|
my ($self, $params) = @_; |
28
|
|
|
|
|
|
|
|
29
|
8
|
100
|
|
|
|
48
|
if ( ref($params) eq 'HASH' ) { |
|
|
100
|
|
|
|
|
|
30
|
5
|
|
|
|
|
82
|
return Net::Easypost::Address->new( $params )->verify; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
elsif ( ref($params) eq 'Net::Easypost::Address' ) { |
33
|
2
|
|
|
|
|
12
|
return $params->verify; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
else { |
36
|
1
|
|
|
|
|
11
|
croak "verify_address expects either a hashref or an instance of Net::Easypost::Address\n"; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub get_rates { |
42
|
4
|
|
|
4
|
1
|
129
|
my $self = shift; # shift is important here |
43
|
|
|
|
|
|
|
|
44
|
4
|
|
|
|
|
11
|
my $params; |
45
|
4
|
100
|
|
|
|
20
|
if ( scalar @_ == 1 ) { |
46
|
3
|
50
|
|
|
|
14
|
if ( ref( $_[0] ) ne 'HASH' ) { |
47
|
0
|
|
|
|
|
0
|
croak 'get_rates expects a hashref not a '. ref($params) .'\n'; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
else { |
50
|
3
|
|
|
|
|
11
|
$params = shift; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
else { |
54
|
1
|
|
|
|
|
6
|
$params = { @_ }; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
return Net::Easypost::Shipment->new( |
58
|
|
|
|
|
|
|
to_address => $params->{to}, |
59
|
|
|
|
|
|
|
from_address => $params->{from}, |
60
|
|
|
|
|
|
|
parcel => $params->{parcel}, |
61
|
4
|
|
|
|
|
80
|
)->rates; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub buy_label { |
66
|
2
|
|
|
2
|
1
|
1468
|
my ($self, $shipment, %options) = @_; |
67
|
|
|
|
|
|
|
|
68
|
2
|
50
|
33
|
|
|
14
|
croak 'Buy label expects a parameter of type Net::Easypost::Shipment' |
69
|
|
|
|
|
|
|
unless $shipment || ref($shipment) ne 'Net::Easypost::Shipment'; |
70
|
|
|
|
|
|
|
|
71
|
2
|
|
|
|
|
18
|
return $shipment->buy(%options); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub get_label { |
76
|
0
|
|
|
0
|
1
|
|
my ($self, $label_filename) = @_; |
77
|
|
|
|
|
|
|
|
78
|
0
|
|
|
|
|
|
my $resp = $self->requester->post( |
79
|
|
|
|
|
|
|
'/postage/get', |
80
|
|
|
|
|
|
|
{ label_file_name => $label_filename } |
81
|
|
|
|
|
|
|
); |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
return Net::Easypost::Label->new( |
84
|
|
|
|
|
|
|
rate => Net::Easypost::Rate->new( $resp->{rate} ), |
85
|
|
|
|
|
|
|
tracking_code => $resp->{tracking_code}, |
86
|
|
|
|
|
|
|
filename => $resp->{label_file_name}, |
87
|
|
|
|
|
|
|
filetype => $resp->{label_file_type}, |
88
|
|
|
|
|
|
|
url => $resp->{label_url} |
89
|
0
|
|
|
|
|
|
); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub list_labels { |
94
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
95
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
my $resp = $self->requester->get( |
97
|
|
|
|
|
|
|
$self->requester->_build_url('/postage/list') |
98
|
|
|
|
|
|
|
); |
99
|
|
|
|
|
|
|
|
100
|
0
|
|
|
|
|
|
return $resp->{postages}; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
1; |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
__END__ |