line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
7
|
|
|
7
|
|
40
|
use strict; |
|
7
|
|
|
|
|
15
|
|
|
7
|
|
|
|
|
211
|
|
2
|
7
|
|
|
7
|
|
39
|
use warnings; |
|
7
|
|
|
|
|
14
|
|
|
7
|
|
|
|
|
213
|
|
3
|
7
|
|
|
7
|
|
38
|
use MRO::Compat 'c3'; |
|
7
|
|
|
|
|
18
|
|
|
7
|
|
|
|
|
414
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package WebService::Shippo::Addresses; |
6
|
|
|
|
|
|
|
require WebService::Shippo::Address; |
7
|
7
|
|
|
|
|
4299
|
use base qw( |
8
|
|
|
|
|
|
|
WebService::Shippo::Collection |
9
|
|
|
|
|
|
|
WebService::Shippo::Create |
10
|
|
|
|
|
|
|
WebService::Shippo::Fetch |
11
|
7
|
|
|
7
|
|
38
|
); |
|
7
|
|
|
|
|
16
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub item_class () { 'WebService::Shippo::Address' } |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub collection_class () { __PACKAGE__ } |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
BEGIN { |
18
|
7
|
|
|
7
|
|
38
|
no warnings 'once'; |
|
7
|
|
|
|
|
15
|
|
|
7
|
|
|
|
|
233
|
|
19
|
7
|
|
|
7
|
|
355
|
*Shippo::Addresses:: = *WebService::Shippo::Addresses::; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
1; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=pod |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=encoding utf8 |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head1 NAME |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# This file can be found in the distribution: |
31
|
|
|
|
|
|
|
# bin/synopses/addresses.pl |
32
|
|
|
|
|
|
|
# |
33
|
|
|
|
|
|
|
use strict; |
34
|
|
|
|
|
|
|
use WebService::Shippo; |
35
|
|
|
|
|
|
|
use Test::More; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 VERSION |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
version 0.0.19 |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# If your client doesn't use a configuration file and you haven't set the |
42
|
|
|
|
|
|
|
# SHIPPO_TOKEN environment variable, you should provide authentication |
43
|
|
|
|
|
|
|
# details below: |
44
|
|
|
|
|
|
|
# |
45
|
|
|
|
|
|
|
Shippo->api_key( 'PASTE YOUR PRIVATE AUTH TOKEN HERE' ) |
46
|
|
|
|
|
|
|
unless Shippo->api_key; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
diag 'Create an address'; |
49
|
|
|
|
|
|
|
my $address = Shippo::Address->create( |
50
|
|
|
|
|
|
|
object_purpose => 'PURCHASE', |
51
|
|
|
|
|
|
|
name => 'John Smith', |
52
|
|
|
|
|
|
|
street1 => '6512 Greene Rd.', |
53
|
|
|
|
|
|
|
street2 => '', |
54
|
|
|
|
|
|
|
company => 'Initech', |
55
|
|
|
|
|
|
|
phone => '+1 234 346 7333', |
56
|
|
|
|
|
|
|
city => 'Woodridge', |
57
|
|
|
|
|
|
|
state => 'IL', |
58
|
|
|
|
|
|
|
zip => '60517', |
59
|
|
|
|
|
|
|
country => 'US', |
60
|
|
|
|
|
|
|
email => 'user@gmail.com', |
61
|
|
|
|
|
|
|
metadata => 'Customer ID 123456' |
62
|
|
|
|
|
|
|
); |
63
|
|
|
|
|
|
|
diag $address->to_string; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
my $id = $address->object_id; |
66
|
|
|
|
|
|
|
diag "Fetch an address object identified by its object_id ($id)"; |
67
|
|
|
|
|
|
|
$address = Shippo::Address->fetch( $id ); |
68
|
|
|
|
|
|
|
diag $address->to_string; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
diag 'Validate the address object'; |
71
|
|
|
|
|
|
|
my $val_1 = $address->validate; |
72
|
|
|
|
|
|
|
diag $val_1->to_string; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
diag "Validate an address object identified by its object_id ($id)"; |
75
|
|
|
|
|
|
|
my $val_2 = Shippo::Address->validate( $id ); |
76
|
|
|
|
|
|
|
diag $val_2->to_string; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
diag "Get 'all' (but really the first 200 or less) address objects"; |
79
|
|
|
|
|
|
|
{ |
80
|
|
|
|
|
|
|
my $collection = Shippo::Addresses->all; |
81
|
|
|
|
|
|
|
for my $address ( $collection->results ) { |
82
|
|
|
|
|
|
|
print "$address->{object_id}\n"; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
diag "Really get all address objects"; |
87
|
|
|
|
|
|
|
{ |
88
|
|
|
|
|
|
|
my $collection = Shippo::Addresses->all; |
89
|
|
|
|
|
|
|
while ( $collection ) { |
90
|
|
|
|
|
|
|
for my $address ( $collection->results ) { |
91
|
|
|
|
|
|
|
print "$address->{object_id}\n"; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
$collection = $collection->next_page; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
diag "Simple iteration through entire object collection"; |
98
|
|
|
|
|
|
|
{ |
99
|
|
|
|
|
|
|
my $it = Shippo::Address->iterator(); |
100
|
|
|
|
|
|
|
while ( my ( $address ) = $it->() ) { |
101
|
|
|
|
|
|
|
print "$address->{object_id}\n"; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
diag "Specialised iterator using a sequence of lambda functions as a filter"; |
106
|
|
|
|
|
|
|
{ |
107
|
|
|
|
|
|
|
my $next_validated_purchase_address = Shippo::Address->iterator( |
108
|
|
|
|
|
|
|
callback { |
109
|
|
|
|
|
|
|
my ( $address ) = @_; |
110
|
|
|
|
|
|
|
# Discard address unless validated and valid |
111
|
|
|
|
|
|
|
return |
112
|
|
|
|
|
|
|
unless $address->object_source eq 'VALIDATOR' |
113
|
|
|
|
|
|
|
&& $address->object_state eq 'VALID'; |
114
|
|
|
|
|
|
|
# Else, keep address |
115
|
|
|
|
|
|
|
return $address; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
callback { |
118
|
|
|
|
|
|
|
my ( $address ) = @_; |
119
|
|
|
|
|
|
|
# Discard address unless created for transaction |
120
|
|
|
|
|
|
|
return |
121
|
|
|
|
|
|
|
unless $address->object_purpose eq 'PURCHASE'; |
122
|
|
|
|
|
|
|
# Else, keep address |
123
|
|
|
|
|
|
|
return $address; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
); |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
while ( my ( $address ) = $next_validated_purchase_address->() ) { |
128
|
|
|
|
|
|
|
print $address; # Automatically stringified using "to_string"; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
diag "Collector using a sequence of lambda functions as a filter"; |
133
|
|
|
|
|
|
|
{ |
134
|
|
|
|
|
|
|
my $all_validated_purchase_addresses = Shippo::Address->collector( |
135
|
|
|
|
|
|
|
callback { |
136
|
|
|
|
|
|
|
my ( $address ) = @_; |
137
|
|
|
|
|
|
|
# Discard address unless validated and valid |
138
|
|
|
|
|
|
|
return |
139
|
|
|
|
|
|
|
unless $address->object_source eq 'VALIDATOR' |
140
|
|
|
|
|
|
|
&& $address->object_state eq 'VALID'; |
141
|
|
|
|
|
|
|
# Else, keep address |
142
|
|
|
|
|
|
|
return $address; |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
callback { |
145
|
|
|
|
|
|
|
my ( $address ) = @_; |
146
|
|
|
|
|
|
|
# Discard address unless created for transaction |
147
|
|
|
|
|
|
|
return |
148
|
|
|
|
|
|
|
unless $address->object_purpose eq 'PURCHASE'; |
149
|
|
|
|
|
|
|
# Else, keep address |
150
|
|
|
|
|
|
|
return $address; |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
); |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
for my $address ( $all_validated_purchase_addresses->() ) { |
155
|
|
|
|
|
|
|
print $address; |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=head1 DESCRIPTION |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
Address objects are used for creating Shipments, obtaining Rates and printing |
162
|
|
|
|
|
|
|
Labels, and thus are one of the fundamental building blocks of the Shippo |
163
|
|
|
|
|
|
|
API. |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=head1 API DOCUMENTATION |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
For more information about Addresses, consult the Shippo API documentation: |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=over 2 |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=item * L |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=back |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=head1 REPOSITORY |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=over 2 |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=item * L |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=item * L |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=back |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=head1 AUTHOR |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
Iain Campbell |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
This software is copyright (c) 2015 by Iain Campbell. |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
You may distribute this software under the terms of either the GNU General |
194
|
|
|
|
|
|
|
Public License or the Artistic License, as specified in the Perl README |
195
|
|
|
|
|
|
|
file. |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=cut |