easypost 3.0.1 → 3.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +22 -0
- data/CHANGELOG +44 -3
- data/README.md +2 -1
- data/VERSION +1 -1
- data/easypost.gemspec +24 -20
- data/lib/easypost.rb +109 -118
- data/lib/easypost/address.rb +47 -47
- data/lib/easypost/batch.rb +34 -38
- data/lib/easypost/carrier_account.rb +3 -6
- data/lib/easypost/carrier_type.rb +2 -0
- data/lib/easypost/customs_info.rb +3 -2
- data/lib/easypost/customs_item.rb +3 -2
- data/lib/easypost/error.rb +25 -33
- data/lib/easypost/event.rb +3 -6
- data/lib/easypost/insurance.rb +1 -3
- data/lib/easypost/item.rb +4 -8
- data/lib/easypost/object.rb +111 -113
- data/lib/easypost/order.rb +20 -18
- data/lib/easypost/parcel.rb +1 -3
- data/lib/easypost/pickup.rb +19 -18
- data/lib/easypost/pickup_rate.rb +1 -3
- data/lib/easypost/postage_label.rb +1 -3
- data/lib/easypost/print_job.rb +1 -5
- data/lib/easypost/printer.rb +18 -22
- data/lib/easypost/rate.rb +1 -3
- data/lib/easypost/refund.rb +1 -3
- data/lib/easypost/report.rb +22 -24
- data/lib/easypost/resource.rb +58 -60
- data/lib/easypost/scan_form.rb +4 -6
- data/lib/easypost/shipment.rb +90 -92
- data/lib/easypost/tracker.rb +10 -12
- data/lib/easypost/user.rb +33 -37
- data/lib/easypost/util.rb +99 -136
- data/lib/easypost/webhook.rb +22 -21
- metadata +35 -62
- data/circle.yml +0 -3
- data/spec/address_spec.rb +0 -81
- data/spec/batch_spec.rb +0 -48
- data/spec/carrier_account_spec.rb +0 -121
- data/spec/insurance_spec.rb +0 -69
- data/spec/item_spec.rb +0 -105
- data/spec/order_spec.rb +0 -58
- data/spec/pickup_spec.rb +0 -83
- data/spec/report_spec.rb +0 -59
- data/spec/scan_form_spec.rb +0 -46
- data/spec/shipment_spec.rb +0 -144
- data/spec/spec_helper.rb +0 -10
- data/spec/support/constant.rb +0 -106
- data/spec/tracker_spec.rb +0 -94
- data/spec/user_spec.rb +0 -88
- data/spec/webhook_spec.rb +0 -75
data/spec/pickup_spec.rb
DELETED
@@ -1,83 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe EasyPost::Pickup do
|
4
|
-
before { EasyPost.api_key = "cueqNZUb3ldeWTNX7MU3Mel8UXtaAMUi" }
|
5
|
-
|
6
|
-
let(:shipment) do
|
7
|
-
shipment = EasyPost::Shipment.create(
|
8
|
-
to_address: ADDRESS[:california],
|
9
|
-
from_address: ADDRESS[:missouri],
|
10
|
-
parcel: PARCEL[:dimensions]
|
11
|
-
)
|
12
|
-
end
|
13
|
-
|
14
|
-
describe '#create' do
|
15
|
-
it 'creates a pickup and returns rates' do
|
16
|
-
shipment.buy(rate: shipment.lowest_rate("ups", "NextDayAirEarlyAM"))
|
17
|
-
pickup = EasyPost::Pickup.create(
|
18
|
-
address: ADDRESS[:missouri],
|
19
|
-
reference: "12345678",
|
20
|
-
min_datetime: DateTime.now(),
|
21
|
-
max_datetime: DateTime.now() + 14400,
|
22
|
-
is_account_address: false,
|
23
|
-
instructions: "",
|
24
|
-
shipment: shipment
|
25
|
-
)
|
26
|
-
|
27
|
-
expect(pickup).to be_an_instance_of(EasyPost::Pickup)
|
28
|
-
expect(pickup.pickup_rates.first).to be_an_instance_of(EasyPost::PickupRate)
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'fails to create a pickup' do
|
32
|
-
shipment.buy(rate: shipment.lowest_rate("ups", "NextDayAirEarlyAM"))
|
33
|
-
expect { pickup = EasyPost::Pickup.create(
|
34
|
-
address: ADDRESS[:california],
|
35
|
-
reference: "12345678",
|
36
|
-
max_datetime: DateTime.now() + 14400,
|
37
|
-
is_account_address: false,
|
38
|
-
instructions: "",
|
39
|
-
shipment: shipment
|
40
|
-
) }.to raise_exception(EasyPost::Error, /Invalid request, 'min_datetime' is required./)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
describe '#buy' do
|
45
|
-
it 'buys a pickup rate' do
|
46
|
-
shipment.buy(rate: shipment.lowest_rate("ups", "NextDayAirEarlyAM"))
|
47
|
-
pickup = EasyPost::Pickup.create(
|
48
|
-
address: ADDRESS[:california],
|
49
|
-
reference: "buy12345678",
|
50
|
-
min_datetime: DateTime.now(),
|
51
|
-
max_datetime: DateTime.now() + 14400,
|
52
|
-
is_account_address: false,
|
53
|
-
instructions: "",
|
54
|
-
shipment: shipment
|
55
|
-
)
|
56
|
-
pickup.buy(pickup.pickup_rates.first)
|
57
|
-
|
58
|
-
expect(pickup.confirmation).not_to be_empty
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
describe '#cancel' do
|
63
|
-
it 'cancels a pickup' do
|
64
|
-
shipment.buy(rate: shipment.lowest_rate("ups", "NextDayAirEarlyAM"))
|
65
|
-
pickup = EasyPost::Pickup.create(
|
66
|
-
address: ADDRESS[:california],
|
67
|
-
reference: "buy12345678",
|
68
|
-
min_datetime: DateTime.now(),
|
69
|
-
max_datetime: DateTime.now() + 14400,
|
70
|
-
is_account_address: false,
|
71
|
-
instructions: "",
|
72
|
-
shipment: shipment
|
73
|
-
)
|
74
|
-
pickup.buy(pickup.pickup_rates.first)
|
75
|
-
|
76
|
-
expect(pickup.status).to eq("scheduled")
|
77
|
-
|
78
|
-
pickup.cancel
|
79
|
-
|
80
|
-
expect(pickup.status).to eq("canceled")
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
data/spec/report_spec.rb
DELETED
@@ -1,59 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe EasyPost::Report do
|
4
|
-
TYPE = 'shipment'
|
5
|
-
describe '#create' do
|
6
|
-
it 'creates a report object' do
|
7
|
-
report = EasyPost::Report.create(
|
8
|
-
start_date: Date.today - 30,
|
9
|
-
end_date: Date.today,
|
10
|
-
type: TYPE
|
11
|
-
)
|
12
|
-
expect(report.object).to eq 'ShipmentReport'
|
13
|
-
expect(['available', 'new']).to include(report.status)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
describe '#retrieve' do
|
18
|
-
it 'retrieves a user created report by public_id as a hash' do
|
19
|
-
report_1 = EasyPost::Report.create(
|
20
|
-
start_date: Date.today - 30,
|
21
|
-
end_date: Date.today,
|
22
|
-
type: TYPE
|
23
|
-
)
|
24
|
-
report_2 = EasyPost::Report.retrieve(id: report_1.id)
|
25
|
-
|
26
|
-
expect(report_2.id).to eq(report_1.id)
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'retrieves a user created report by public_id as a string' do
|
30
|
-
report_1 = EasyPost::Report.create(
|
31
|
-
start_date: Date.today - 30,
|
32
|
-
end_date: Date.today,
|
33
|
-
type: TYPE
|
34
|
-
)
|
35
|
-
report_2 = EasyPost::Report.retrieve(report_1.id)
|
36
|
-
|
37
|
-
expect(report_2.id).to eq(report_1.id)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
describe '#all' do
|
42
|
-
it 'retrieves all user created reports' do
|
43
|
-
report_1 = EasyPost::Report.create(
|
44
|
-
start_date: Date.today - 25,
|
45
|
-
end_date: Date.today,
|
46
|
-
type: TYPE
|
47
|
-
)
|
48
|
-
|
49
|
-
report_2 = EasyPost::Report.create(
|
50
|
-
start_date: Date.today - 29,
|
51
|
-
end_date: Date.today,
|
52
|
-
type: TYPE
|
53
|
-
)
|
54
|
-
reports = EasyPost::Report.all(type: TYPE)
|
55
|
-
|
56
|
-
expect(reports.count).to eq 2
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
data/spec/scan_form_spec.rb
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe EasyPost::ScanForm do
|
4
|
-
let(:shipment) do
|
5
|
-
shipment = EasyPost::Shipment.create(
|
6
|
-
to_address: ADDRESS[:canada],
|
7
|
-
from_address: ADDRESS[:california],
|
8
|
-
parcel: PARCEL[:dimensions],
|
9
|
-
customs_info: CUSTOMS_INFO[:shirt]
|
10
|
-
)
|
11
|
-
|
12
|
-
shipment.buy(
|
13
|
-
rate: shipment.lowest_rate("usps")
|
14
|
-
)
|
15
|
-
end
|
16
|
-
|
17
|
-
describe '#create' do
|
18
|
-
it 'purchases postage for an international shipment' do
|
19
|
-
scan_form = EasyPost::ScanForm.create(shipments: [shipment])
|
20
|
-
|
21
|
-
expect(scan_form.id).not_to be_nil
|
22
|
-
expect(scan_form.tracking_codes.first).to eq(shipment.tracking_code)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
describe '#retrieve' do
|
27
|
-
let(:scan_form) { EasyPost::ScanForm.create(shipments: [shipment]) }
|
28
|
-
|
29
|
-
it 'retrieves the same scan_form' do
|
30
|
-
scan_form2 = EasyPost::ScanForm.retrieve(scan_form.id)
|
31
|
-
|
32
|
-
expect(scan_form2.id).to eq(scan_form.id)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
describe '#all' do
|
37
|
-
let!(:scan_form) { EasyPost::ScanForm.create(shipments: [shipment]) }
|
38
|
-
|
39
|
-
it 'indexes the scan_forms' do
|
40
|
-
params = {page_size: 2}
|
41
|
-
scan_forms = EasyPost::ScanForm.all(params)
|
42
|
-
|
43
|
-
expect(scan_forms["scan_forms"].first.id).to eq(scan_form.id)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
data/spec/shipment_spec.rb
DELETED
@@ -1,144 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe EasyPost::Shipment do
|
4
|
-
describe '#create' do
|
5
|
-
it 'creates a shipment object' do
|
6
|
-
|
7
|
-
shipment = EasyPost::Shipment.create(
|
8
|
-
to_address: ADDRESS[:california],
|
9
|
-
from_address: EasyPost::Address.create(ADDRESS[:missouri]),
|
10
|
-
parcel: EasyPost::Parcel.create(PARCEL[:dimensions])
|
11
|
-
)
|
12
|
-
expect(shipment).to be_an_instance_of(EasyPost::Shipment)
|
13
|
-
expect(shipment.from_address).to be_an_instance_of(EasyPost::Address)
|
14
|
-
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'creates a shipment object when options hash contains id' do
|
18
|
-
|
19
|
-
shipment = EasyPost::Shipment.create(
|
20
|
-
to_address: ADDRESS[:california],
|
21
|
-
from_address: EasyPost::Address.create(ADDRESS[:missouri]),
|
22
|
-
parcel: EasyPost::Parcel.create(PARCEL[:dimensions]),
|
23
|
-
options: OPTIONS[:mws]
|
24
|
-
)
|
25
|
-
expect(shipment).to be_an_instance_of(EasyPost::Shipment)
|
26
|
-
expect(shipment.options.fulfiller_order_items.first).to be_an_instance_of(EasyPost::EasyPostObject)
|
27
|
-
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
describe '#buy' do
|
32
|
-
it 'purchases postage for an international shipment' do
|
33
|
-
|
34
|
-
shipment = EasyPost::Shipment.create(
|
35
|
-
to_address: EasyPost::Address.create(ADDRESS[:canada]),
|
36
|
-
from_address: ADDRESS[:california],
|
37
|
-
parcel: EasyPost::Parcel.create(PARCEL[:dimensions]),
|
38
|
-
customs_info: EasyPost::CustomsInfo.create(CUSTOMS_INFO[:shirt])
|
39
|
-
)
|
40
|
-
expect(shipment).to be_an_instance_of(EasyPost::Shipment)
|
41
|
-
|
42
|
-
shipment.buy(
|
43
|
-
rate: shipment.lowest_rate("usps")
|
44
|
-
)
|
45
|
-
expect(shipment.postage_label.label_url.length).to be > 0
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'purchases postage for a domestic shipment' do
|
49
|
-
shipment = EasyPost::Shipment.create(
|
50
|
-
to_address: EasyPost::Address.create(ADDRESS[:missouri]),
|
51
|
-
from_address: ADDRESS[:california],
|
52
|
-
parcel: EasyPost::Parcel.create(PARCEL[:dimensions])
|
53
|
-
)
|
54
|
-
expect(shipment).to be_an_instance_of(EasyPost::Shipment)
|
55
|
-
|
56
|
-
shipment.buy(
|
57
|
-
rate: shipment.lowest_rate("usps")
|
58
|
-
)
|
59
|
-
expect(shipment.postage_label.label_url.length).to be > 0
|
60
|
-
end
|
61
|
-
|
62
|
-
it 'creates and returns a tracker with shipment purchase' do
|
63
|
-
shipment = EasyPost::Shipment.create(
|
64
|
-
:to_address => ADDRESS[:missouri],
|
65
|
-
:from_address => ADDRESS[:california],
|
66
|
-
:parcel => PARCEL[:dimensions]
|
67
|
-
)
|
68
|
-
expect(shipment).to be_an_instance_of(EasyPost::Shipment)
|
69
|
-
|
70
|
-
shipment.buy(
|
71
|
-
:rate => shipment.lowest_rate("usps")
|
72
|
-
)
|
73
|
-
|
74
|
-
tracker = shipment.tracker
|
75
|
-
expect(tracker.shipment_id).to eq(shipment.id)
|
76
|
-
end
|
77
|
-
|
78
|
-
it 'purchases postage when only a rate id is provided' do
|
79
|
-
shipment = EasyPost::Shipment.create(
|
80
|
-
:to_address => ADDRESS[:missouri],
|
81
|
-
:from_address => ADDRESS[:california],
|
82
|
-
:parcel => PARCEL[:dimensions]
|
83
|
-
)
|
84
|
-
expect(shipment).to be_an_instance_of(EasyPost::Shipment)
|
85
|
-
|
86
|
-
rate = shipment.rates.first
|
87
|
-
rate_hash = {id: rate.id}
|
88
|
-
|
89
|
-
shipment.buy(
|
90
|
-
:rate => rate_hash
|
91
|
-
)
|
92
|
-
|
93
|
-
expect(shipment.postage_label.label_url.length).to be > 0
|
94
|
-
tracker = shipment.tracker
|
95
|
-
expect(tracker.shipment_id).to eq(shipment.id)
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
describe '#insure' do
|
100
|
-
it 'buys and insures a shipments' do
|
101
|
-
shipment = EasyPost::Shipment.create(
|
102
|
-
:to_address => ADDRESS[:missouri],
|
103
|
-
:from_address => ADDRESS[:california],
|
104
|
-
:parcel => PARCEL[:dimensions]
|
105
|
-
)
|
106
|
-
expect(shipment).to be_an_instance_of(EasyPost::Shipment)
|
107
|
-
|
108
|
-
shipment.buy(
|
109
|
-
:rate => shipment.lowest_rate("usps")
|
110
|
-
)
|
111
|
-
|
112
|
-
shipment.insure(amount: 100)
|
113
|
-
|
114
|
-
expect(shipment.insurance).to eq("100.00")
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
describe '#lowest_rate' do
|
119
|
-
context 'domestic shipment' do
|
120
|
-
before :all do
|
121
|
-
@shipment = EasyPost::Shipment.create(
|
122
|
-
to_address: EasyPost::Address.create(ADDRESS[:missouri]),
|
123
|
-
from_address: ADDRESS[:california],
|
124
|
-
parcel: EasyPost::Parcel.create(PARCEL[:dimensions])
|
125
|
-
)
|
126
|
-
end
|
127
|
-
|
128
|
-
it 'filters negative services' do
|
129
|
-
rate = @shipment.lowest_rate('USPS', '!MediaMail, !LibraryMail')
|
130
|
-
|
131
|
-
expect(rate.service).to eql('ParcelSelect')
|
132
|
-
end
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
describe '#retrieve' do
|
137
|
-
it 'retrieves shipment by tracking_code and correctly sets ID field (this was a bug in python)' do
|
138
|
-
tracking_code = "LN123456789US"
|
139
|
-
shipment = EasyPost::Shipment.retrieve(tracking_code)
|
140
|
-
|
141
|
-
expect(shipment.id).not_to eq(tracking_code)
|
142
|
-
end
|
143
|
-
end
|
144
|
-
end
|
data/spec/spec_helper.rb
DELETED
data/spec/support/constant.rb
DELETED
@@ -1,106 +0,0 @@
|
|
1
|
-
ADDRESS = {
|
2
|
-
california: {
|
3
|
-
company: 'EasyPost',
|
4
|
-
street1: '164 Townsend Street',
|
5
|
-
street2: 'Unit 1',
|
6
|
-
city: 'San Francisco',
|
7
|
-
state: 'CA',
|
8
|
-
zip: '94107',
|
9
|
-
phone: '415-123-4567'
|
10
|
-
},
|
11
|
-
california_no_phone: {
|
12
|
-
company: 'EasyPost',
|
13
|
-
street1: '164 Townsend Street',
|
14
|
-
street2: 'Unit 1',
|
15
|
-
city: 'San Francisco',
|
16
|
-
state: 'CA',
|
17
|
-
zip: '94107'
|
18
|
-
},
|
19
|
-
missouri: {
|
20
|
-
company: 'Airport Shipping',
|
21
|
-
street1: '601 Brasilia Avenue',
|
22
|
-
city: 'Kansas City',
|
23
|
-
state: 'MO',
|
24
|
-
zip: '64153',
|
25
|
-
phone: '314-924-0383',
|
26
|
-
email: 'kansas_shipping@example.com'
|
27
|
-
},
|
28
|
-
canada: {
|
29
|
-
name: 'Sawyer Bateman',
|
30
|
-
street1: '58 Larkspur Cres.',
|
31
|
-
city: 'St. Albert',
|
32
|
-
state: 'AB',
|
33
|
-
zip: 'T8N2M4',
|
34
|
-
country: 'CA',
|
35
|
-
phone: '780-123-4567'
|
36
|
-
},
|
37
|
-
canada_no_phone: {
|
38
|
-
name: 'Sawyer Bateman',
|
39
|
-
street1: '58 Larkspur Cres.',
|
40
|
-
city: 'St. Albert',
|
41
|
-
state: 'AB',
|
42
|
-
zip: 't8n2m4',
|
43
|
-
country: 'CA',
|
44
|
-
phone: '780-273-8374'
|
45
|
-
}
|
46
|
-
}
|
47
|
-
|
48
|
-
PARCEL = {
|
49
|
-
dimensions: {
|
50
|
-
width: 12,
|
51
|
-
length: 16.5,
|
52
|
-
height: 9.5,
|
53
|
-
weight: 40.1
|
54
|
-
},
|
55
|
-
dimensions_light: {
|
56
|
-
width: 15.2,
|
57
|
-
length: 18,
|
58
|
-
height: 9.5,
|
59
|
-
weight: 3
|
60
|
-
},
|
61
|
-
predefined_medium_flat_rate_box: {
|
62
|
-
predefined_package: 'MediumFlatRateBox',
|
63
|
-
weight: 17
|
64
|
-
}
|
65
|
-
}
|
66
|
-
|
67
|
-
CUSTOMS_INFO = {
|
68
|
-
shirt: {
|
69
|
-
integrated_form_type: 'form_2976',
|
70
|
-
customs_certify: true,
|
71
|
-
customs_signer: 'Dr. Pepper',
|
72
|
-
contents_type: 'gift',
|
73
|
-
contents_explanation: '', # only required when contents_type: 'other'
|
74
|
-
eel_pfc: 'NOEEI 30.37(a)',
|
75
|
-
non_delivery_option: 'abandon',
|
76
|
-
restriction_type: 'none',
|
77
|
-
restriction_comments: '',
|
78
|
-
customs_items: [{
|
79
|
-
description: 'EasyPost T-shirts',
|
80
|
-
quantity: 2,
|
81
|
-
value: 23.56,
|
82
|
-
weight: 20,
|
83
|
-
origin_country: 'us',
|
84
|
-
hs_tariff_number: 123456
|
85
|
-
}]
|
86
|
-
},
|
87
|
-
merchandise: {
|
88
|
-
customs_certify: true,
|
89
|
-
customs_signer: 'Dr. Pepper',
|
90
|
-
contents_type: 'merchandise',
|
91
|
-
contents_explanation: '', # only required when contents_type: 'other'
|
92
|
-
eel_pfc: 'NOEEI 30.37(a)',
|
93
|
-
non_delivery_option: 'abandon',
|
94
|
-
restriction_type: 'none',
|
95
|
-
restriction_comments: ''
|
96
|
-
}
|
97
|
-
}
|
98
|
-
|
99
|
-
OPTIONS = {
|
100
|
-
mws: {
|
101
|
-
fulfiller_order_items: [{
|
102
|
-
id: '12345678901234',
|
103
|
-
quantity: 1
|
104
|
-
}]
|
105
|
-
}
|
106
|
-
}
|