line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Easypost; |
2
|
|
|
|
|
|
|
$Net::Easypost::VERSION = '0.23'; |
3
|
6
|
|
|
6
|
|
171601
|
use Carp qw(croak); |
|
6
|
|
|
|
|
35
|
|
|
6
|
|
|
|
|
324
|
|
4
|
|
|
|
|
|
|
|
5
|
6
|
|
|
6
|
|
2060
|
use Net::Easypost::Address; |
|
6
|
|
|
|
|
18
|
|
|
6
|
|
|
|
|
189
|
|
6
|
6
|
|
|
6
|
|
2116
|
use Net::Easypost::Label; |
|
6
|
|
|
|
|
16
|
|
|
6
|
|
|
|
|
142
|
|
7
|
6
|
|
|
6
|
|
3071
|
use Net::Easypost::Parcel; |
|
6
|
|
|
|
|
14
|
|
|
6
|
|
|
|
|
170
|
|
8
|
6
|
|
|
6
|
|
2007
|
use Net::Easypost::Rate; |
|
6
|
|
|
|
|
17
|
|
|
6
|
|
|
|
|
162
|
|
9
|
6
|
|
|
6
|
|
33
|
use Net::Easypost::Request; |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
132
|
|
10
|
6
|
|
|
6
|
|
2153
|
use Net::Easypost::Shipment; |
|
6
|
|
|
|
|
14
|
|
|
6
|
|
|
|
|
181
|
|
11
|
|
|
|
|
|
|
|
12
|
6
|
|
|
6
|
|
38
|
use Moo; |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
21
|
|
13
|
6
|
|
|
6
|
|
1684
|
use namespace::autoclean; |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
33
|
|
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
|
256077
|
my ($self, $params) = @_; |
28
|
|
|
|
|
|
|
|
29
|
8
|
100
|
|
|
|
44
|
if ( ref($params) eq 'HASH' ) { |
|
|
100
|
|
|
|
|
|
30
|
5
|
|
|
|
|
72
|
return Net::Easypost::Address->new( $params )->verify; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
elsif ( ref($params) eq 'Net::Easypost::Address' ) { |
33
|
2
|
|
|
|
|
14
|
return $params->verify; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
else { |
36
|
1
|
|
|
|
|
10
|
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
|
89
|
my $self = shift; # shift is important here |
43
|
|
|
|
|
|
|
|
44
|
4
|
|
|
|
|
10
|
my $params; |
45
|
4
|
100
|
|
|
|
20
|
if ( scalar @_ == 1 ) { |
46
|
3
|
50
|
|
|
|
9
|
if ( ref( $_[0] ) ne 'HASH' ) { |
47
|
0
|
|
|
|
|
0
|
croak 'get_rates expects a hashref not a '. ref($params) .'\n'; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
else { |
50
|
3
|
|
|
|
|
6
|
$params = shift; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
else { |
54
|
1
|
|
|
|
|
5
|
$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
|
|
|
|
|
74
|
)->rates; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub buy_label { |
66
|
2
|
|
|
2
|
1
|
1134
|
my ($self, $shipment, %options) = @_; |
67
|
|
|
|
|
|
|
|
68
|
2
|
50
|
33
|
|
|
21
|
croak 'Buy label expects a parameter of type Net::Easypost::Shipment' |
69
|
|
|
|
|
|
|
unless $shipment || ref($shipment) ne 'Net::Easypost::Shipment'; |
70
|
|
|
|
|
|
|
|
71
|
2
|
|
|
|
|
17
|
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__ |