line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Easypost; |
2
|
|
|
|
|
|
|
$Net::Easypost::VERSION = '0.21'; |
3
|
6
|
|
|
6
|
|
156803
|
use Carp qw(croak); |
|
6
|
|
|
|
|
16
|
|
|
6
|
|
|
|
|
365
|
|
4
|
|
|
|
|
|
|
|
5
|
6
|
|
|
6
|
|
1717
|
use Net::Easypost::Address; |
|
6
|
|
|
|
|
19
|
|
|
6
|
|
|
|
|
1050
|
|
6
|
6
|
|
|
6
|
|
1758
|
use Net::Easypost::Label; |
|
6
|
|
|
|
|
18
|
|
|
6
|
|
|
|
|
174
|
|
7
|
6
|
|
|
6
|
|
1931
|
use Net::Easypost::Parcel; |
|
6
|
|
|
|
|
15
|
|
|
6
|
|
|
|
|
199
|
|
8
|
6
|
|
|
6
|
|
1780
|
use Net::Easypost::Rate; |
|
6
|
|
|
|
|
18
|
|
|
6
|
|
|
|
|
177
|
|
9
|
6
|
|
|
6
|
|
36
|
use Net::Easypost::Request; |
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
104
|
|
10
|
6
|
|
|
6
|
|
1678
|
use Net::Easypost::Shipment; |
|
6
|
|
|
|
|
21
|
|
|
6
|
|
|
|
|
220
|
|
11
|
|
|
|
|
|
|
|
12
|
6
|
|
|
6
|
|
55
|
use Moo; |
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
30
|
|
13
|
6
|
|
|
6
|
|
1973
|
use namespace::autoclean; |
|
6
|
|
|
|
|
15
|
|
|
6
|
|
|
|
|
58
|
|
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
|
51765
|
my ($self, $params) = @_; |
28
|
|
|
|
|
|
|
|
29
|
8
|
100
|
|
|
|
54
|
if ( ref($params) eq 'HASH' ) { |
|
|
100
|
|
|
|
|
|
30
|
5
|
|
|
|
|
108
|
return Net::Easypost::Address->new( $params )->verify; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
elsif ( ref($params) eq 'Net::Easypost::Address' ) { |
33
|
2
|
|
|
|
|
9
|
return $params->verify; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
else { |
36
|
1
|
|
|
|
|
23
|
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
|
117
|
my $self = shift; # shift is important here |
43
|
|
|
|
|
|
|
|
44
|
4
|
|
|
|
|
20
|
my $params; |
45
|
4
|
100
|
|
|
|
22
|
if ( scalar @_ == 1 ) { |
46
|
3
|
50
|
|
|
|
19
|
if ( ref( $_[0] ) ne 'HASH' ) { |
47
|
0
|
|
|
|
|
0
|
croak 'get_rates expects a hashref not a '. ref($params) .'\n'; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
else { |
50
|
3
|
|
|
|
|
9
|
$params = shift; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
else { |
54
|
1
|
|
|
|
|
7
|
$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
|
|
|
|
|
126
|
)->rates; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub buy_label { |
66
|
2
|
|
|
2
|
1
|
1812
|
my ($self, $shipment, %options) = @_; |
67
|
|
|
|
|
|
|
|
68
|
2
|
50
|
33
|
|
|
179
|
croak 'Buy label expects a parameter of type Net::Easypost::Shipment' |
69
|
|
|
|
|
|
|
unless $shipment || ref($shipment) ne 'Net::Easypost::Shipment'; |
70
|
|
|
|
|
|
|
|
71
|
2
|
|
|
|
|
24
|
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__ |