easypost 2.1.1 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG +59 -0
- data/README.md +16 -12
- data/VERSION +1 -1
- data/easypost.gemspec +2 -2
- data/lib/easypost/address.rb +25 -12
- data/lib/easypost/error.rb +18 -8
- data/lib/easypost/insurance.rb +4 -0
- data/lib/easypost/pickup.rb +6 -0
- data/lib/easypost/print_job.rb +6 -0
- data/lib/easypost/printer.rb +28 -0
- data/lib/easypost/shipment.rb +7 -0
- data/lib/easypost/tracker.rb +10 -0
- data/lib/easypost/user.rb +7 -0
- data/lib/easypost/util.rb +14 -4
- data/lib/easypost/version.rb +1 -1
- data/lib/easypost.rb +7 -2
- data/spec/address_spec.rb +26 -14
- data/spec/carrier_account_spec.rb +115 -110
- data/spec/insurance_spec.rb +69 -0
- data/spec/item_spec.rb +104 -101
- data/spec/order_spec.rb +1 -19
- data/spec/pickup_spec.rb +30 -15
- data/spec/shipment_spec.rb +28 -1
- data/spec/support/constant.rb +10 -0
- data/spec/tracker_spec.rb +77 -3
- data/spec/user_spec.rb +16 -0
- metadata +25 -26
|
@@ -1,116 +1,121 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
describe EasyPost::CarrierAccount do
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
ca = EasyPost::CarrierAccount.retrieve(id)
|
|
7
|
-
|
|
8
|
-
expect(ca.id).to eq(id)
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
context 'perform CRUD functions' do
|
|
12
|
-
it 'performs all basic CRUD actions on a CarrierAccount' do
|
|
13
|
-
original_num_cas = EasyPost::CarrierAccount.all.count
|
|
14
|
-
|
|
15
|
-
description = "A test Ups Account"
|
|
16
|
-
reference = "RubyClientUpsTestAccount"
|
|
17
|
-
|
|
18
|
-
created_ca = EasyPost::CarrierAccount.create(
|
|
19
|
-
type: "UpsAccount",
|
|
20
|
-
description: description,
|
|
21
|
-
reference: reference,
|
|
22
|
-
credentials: {
|
|
23
|
-
account_number: "A1A1A1",
|
|
24
|
-
user_id: "UPSDOTCOM_USERNAME",
|
|
25
|
-
password: "UPSDOTCOM_PASSWORD",
|
|
26
|
-
access_license_number: "UPS_ACCESS_LICENSE_NUMBER"
|
|
27
|
-
}
|
|
28
|
-
)
|
|
29
|
-
|
|
30
|
-
id = created_ca["id"]
|
|
31
|
-
|
|
32
|
-
interm_num_cas = EasyPost::CarrierAccount.all.count
|
|
33
|
-
expect(interm_num_cas).to eq(original_num_cas + 1)
|
|
34
|
-
|
|
35
|
-
retrieved_ca = EasyPost::CarrierAccount.retrieve(id)
|
|
36
|
-
|
|
37
|
-
expect(retrieved_ca["id"]).to eq(created_ca["id"])
|
|
38
|
-
expect(retrieved_ca["description"]).to eq(description)
|
|
39
|
-
expect(retrieved_ca["reference"]).to eq(reference)
|
|
40
|
-
|
|
41
|
-
updated_description = "An updated description for a test Ups Account"
|
|
42
|
-
updated_account_number = "B2B2B2B2"
|
|
43
|
-
retrieved_ca.description = updated_description
|
|
44
|
-
retrieved_ca.credentials = {
|
|
45
|
-
account_number: updated_account_number,
|
|
46
|
-
user_id: "UPSDOTCOM_USERNAME",
|
|
47
|
-
password: "UPSDOTCOM_PASSWORD",
|
|
48
|
-
access_license_number: "UPS_ACCESS_LICENSE_NUMBER"
|
|
49
|
-
}
|
|
50
|
-
retrieved_ca.save
|
|
51
|
-
|
|
52
|
-
updated_ca = EasyPost::CarrierAccount.retrieve(id)
|
|
53
|
-
expect(updated_ca["id"]).to eq(created_ca["id"])
|
|
54
|
-
expect(updated_ca["description"]).to eq(updated_description)
|
|
55
|
-
expect(updated_ca["credentials"]["account_number"]).to eq(updated_account_number)
|
|
56
|
-
|
|
57
|
-
reupdated_account_number = "C3C3C3C3C3"
|
|
58
|
-
updated_user_id = "A_NEW_UPS_USERNAME"
|
|
59
|
-
updated_ca.credentials[:account_number] = reupdated_account_number
|
|
60
|
-
updated_ca.credentials[:user_id] = updated_user_id
|
|
61
|
-
updated_ca.save
|
|
62
|
-
|
|
63
|
-
reupdated_ca = EasyPost::CarrierAccount.retrieve(id)
|
|
64
|
-
expect(reupdated_ca["id"]).to eq(created_ca["id"])
|
|
65
|
-
expect(reupdated_ca["credentials"]["account_number"]).to eq(reupdated_account_number)
|
|
66
|
-
expect(reupdated_ca["credentials"]["user_id"]).to eq(updated_user_id)
|
|
67
|
-
|
|
68
|
-
final_ca = reupdated_ca.save
|
|
69
|
-
expect(final_ca["id"]).to eq(created_ca["id"])
|
|
70
|
-
expect(final_ca["credentials"]["account_number"]).to eq(reupdated_account_number)
|
|
71
|
-
expect(final_ca["credentials"]["user_id"]).to eq(updated_user_id)
|
|
72
|
-
|
|
73
|
-
final_ca.delete
|
|
74
|
-
|
|
75
|
-
final_num_cas = EasyPost::CarrierAccount.all.count
|
|
76
|
-
expect(final_num_cas).to eq(original_num_cas)
|
|
77
|
-
end
|
|
4
|
+
before do
|
|
5
|
+
EasyPost.api_key = "PRODUCTION API KEY"
|
|
78
6
|
end
|
|
79
7
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
"
|
|
92
|
-
"
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
8
|
+
# it 'performs retrieve on a carrier account' do
|
|
9
|
+
# id = 'ca_r8hLl9jS'
|
|
10
|
+
# ca = EasyPost::CarrierAccount.retrieve(id)
|
|
11
|
+
#
|
|
12
|
+
# expect(ca.id).to eq(id)
|
|
13
|
+
# end
|
|
14
|
+
#
|
|
15
|
+
# context 'perform CRUD functions' do
|
|
16
|
+
# it 'performs all basic CRUD actions on a CarrierAccount' do
|
|
17
|
+
# original_num_cas = EasyPost::CarrierAccount.all.count
|
|
18
|
+
#
|
|
19
|
+
# description = "A test Ups Account"
|
|
20
|
+
# reference = "RubyClientUpsTestAccount"
|
|
21
|
+
#
|
|
22
|
+
# created_ca = EasyPost::CarrierAccount.create(
|
|
23
|
+
# type: "UpsAccount",
|
|
24
|
+
# description: description,
|
|
25
|
+
# reference: reference,
|
|
26
|
+
# credentials: {
|
|
27
|
+
# account_number: "A1A1A1",
|
|
28
|
+
# user_id: "UPSDOTCOM_USERNAME",
|
|
29
|
+
# password: "UPSDOTCOM_PASSWORD",
|
|
30
|
+
# access_license_number: "UPS_ACCESS_LICENSE_NUMBER"
|
|
31
|
+
# }
|
|
32
|
+
# )
|
|
33
|
+
#
|
|
34
|
+
# id = created_ca["id"]
|
|
35
|
+
#
|
|
36
|
+
# interm_num_cas = EasyPost::CarrierAccount.all.count
|
|
37
|
+
# expect(interm_num_cas).to eq(original_num_cas + 1)
|
|
38
|
+
#
|
|
39
|
+
# retrieved_ca = EasyPost::CarrierAccount.retrieve(id)
|
|
40
|
+
#
|
|
41
|
+
# expect(retrieved_ca["id"]).to eq(created_ca["id"])
|
|
42
|
+
# expect(retrieved_ca["description"]).to eq(description)
|
|
43
|
+
# expect(retrieved_ca["reference"]).to eq(reference)
|
|
44
|
+
#
|
|
45
|
+
# updated_description = "An updated description for a test Ups Account"
|
|
46
|
+
# updated_account_number = "B2B2B2B2"
|
|
47
|
+
# retrieved_ca.description = updated_description
|
|
48
|
+
# retrieved_ca.credentials = {
|
|
49
|
+
# account_number: updated_account_number,
|
|
50
|
+
# user_id: "UPSDOTCOM_USERNAME",
|
|
51
|
+
# password: "UPSDOTCOM_PASSWORD",
|
|
52
|
+
# access_license_number: "UPS_ACCESS_LICENSE_NUMBER"
|
|
53
|
+
# }
|
|
54
|
+
# retrieved_ca.save
|
|
55
|
+
#
|
|
56
|
+
# updated_ca = EasyPost::CarrierAccount.retrieve(id)
|
|
57
|
+
# expect(updated_ca["id"]).to eq(created_ca["id"])
|
|
58
|
+
# expect(updated_ca["description"]).to eq(updated_description)
|
|
59
|
+
# expect(updated_ca["credentials"]["account_number"]).to eq(updated_account_number)
|
|
60
|
+
#
|
|
61
|
+
# reupdated_account_number = "C3C3C3C3C3"
|
|
62
|
+
# updated_user_id = "A_NEW_UPS_USERNAME"
|
|
63
|
+
# updated_ca.credentials[:account_number] = reupdated_account_number
|
|
64
|
+
# updated_ca.credentials[:user_id] = updated_user_id
|
|
65
|
+
# updated_ca.save
|
|
66
|
+
#
|
|
67
|
+
# reupdated_ca = EasyPost::CarrierAccount.retrieve(id)
|
|
68
|
+
# expect(reupdated_ca["id"]).to eq(created_ca["id"])
|
|
69
|
+
# expect(reupdated_ca["credentials"]["account_number"]).to eq(reupdated_account_number)
|
|
70
|
+
# expect(reupdated_ca["credentials"]["user_id"]).to eq(updated_user_id)
|
|
71
|
+
#
|
|
72
|
+
# final_ca = reupdated_ca.save
|
|
73
|
+
# expect(final_ca["id"]).to eq(created_ca["id"])
|
|
74
|
+
# expect(final_ca["credentials"]["account_number"]).to eq(reupdated_account_number)
|
|
75
|
+
# expect(final_ca["credentials"]["user_id"]).to eq(updated_user_id)
|
|
76
|
+
#
|
|
77
|
+
# final_ca.delete
|
|
78
|
+
#
|
|
79
|
+
# final_num_cas = EasyPost::CarrierAccount.all.count
|
|
80
|
+
# expect(final_num_cas).to eq(original_num_cas)
|
|
81
|
+
# end
|
|
82
|
+
# end
|
|
83
|
+
#
|
|
84
|
+
# describe '#types' do
|
|
85
|
+
# let(:carrier_account_types) { [
|
|
86
|
+
# "AsendiaAccount",
|
|
87
|
+
# "AustraliaPostAccount",
|
|
88
|
+
# "CanadaPostAccount",
|
|
89
|
+
# "CanparAccount",
|
|
90
|
+
# "ColisPriveAccount",
|
|
91
|
+
# "DhlExpressAccount",
|
|
92
|
+
# "DhlGlobalMailAccount",
|
|
93
|
+
# "FastwayAccount",
|
|
94
|
+
# "FedexAccount",
|
|
95
|
+
# "FedexSmartpostAccount",
|
|
96
|
+
# "GsoAccount",
|
|
97
|
+
# "LasershipAccount",
|
|
98
|
+
# "LsoAccount",
|
|
99
|
+
# "NorcoAccount",
|
|
100
|
+
# "NzpostAccount",
|
|
101
|
+
# "OntracAccount",
|
|
102
|
+
# "PurolatorAccount",
|
|
103
|
+
# "RoyalMailAccount",
|
|
104
|
+
# "SpeedeeAccount",
|
|
105
|
+
# "TntExpressAccount",
|
|
106
|
+
# "UpsAccount",
|
|
107
|
+
# "UpsMailInnovationsAccount",
|
|
108
|
+
# "UpsSurepostAccount"
|
|
109
|
+
# ] }
|
|
110
|
+
#
|
|
111
|
+
# it 'returns the expected list of types' do
|
|
112
|
+
# types = EasyPost::CarrierAccount.types
|
|
113
|
+
# account_types = types.map(&:type)
|
|
114
|
+
#
|
|
115
|
+
# for account_type in carrier_account_types
|
|
116
|
+
# expect(account_types).to include(account_type)
|
|
117
|
+
# end
|
|
118
|
+
# end
|
|
119
|
+
# end
|
|
116
120
|
end
|
|
121
|
+
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe EasyPost::Insurance do
|
|
4
|
+
let(:tracking_code) { 'EZ2000000002' }
|
|
5
|
+
let(:carrier) { 'usps' }
|
|
6
|
+
let(:amount) { 101.00 }
|
|
7
|
+
|
|
8
|
+
describe '#create' do
|
|
9
|
+
it 'creates an insurance object' do
|
|
10
|
+
insurance = EasyPost::Insurance.create(
|
|
11
|
+
to_address: ADDRESS[:california],
|
|
12
|
+
from_address: ADDRESS[:missouri],
|
|
13
|
+
amount: amount,
|
|
14
|
+
tracking_code: tracking_code,
|
|
15
|
+
carrier: carrier
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
expect(insurance).to be_a(EasyPost::Insurance)
|
|
19
|
+
expect(insurance.id).not_to be_nil
|
|
20
|
+
expect(insurance.amount).to eq("101.00000")
|
|
21
|
+
expect(insurance.tracking_code).to eq(tracking_code)
|
|
22
|
+
expect(insurance.tracker).to be_a(EasyPost::Tracker)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
describe '#retrieve' do
|
|
27
|
+
it 'creates an insurance object' do
|
|
28
|
+
id = EasyPost::Insurance.create(
|
|
29
|
+
to_address: ADDRESS[:california],
|
|
30
|
+
from_address: ADDRESS[:missouri],
|
|
31
|
+
amount: amount,
|
|
32
|
+
tracking_code: tracking_code,
|
|
33
|
+
carrier: carrier
|
|
34
|
+
).id
|
|
35
|
+
|
|
36
|
+
insurance = EasyPost::Insurance.retrieve(id)
|
|
37
|
+
|
|
38
|
+
expect(insurance).to be_a(EasyPost::Insurance)
|
|
39
|
+
expect(insurance.id).to eq(id)
|
|
40
|
+
expect(insurance.amount).to eq("101.00000")
|
|
41
|
+
expect(insurance.tracking_code).to eq(tracking_code)
|
|
42
|
+
expect(insurance.tracker).to be_a(EasyPost::Tracker)
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
describe '#index' do
|
|
48
|
+
it 'retrieves a full page of insurances' do
|
|
49
|
+
insurances = EasyPost::Insurance.all(page_size: 5)
|
|
50
|
+
|
|
51
|
+
expect(insurances["insurances"].count).to eq(5)
|
|
52
|
+
expect(insurances["has_more"]).to eq(true)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
it 'retrieves all insurances with given tracking code, up to a page' do
|
|
56
|
+
insurances = EasyPost::Insurance.all(tracking_code: tracking_code, page_size: 5)
|
|
57
|
+
|
|
58
|
+
expect(insurances["insurances"].count).to eq(5)
|
|
59
|
+
expect(insurances["has_more"]).to eq(true)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
it 'retrieves all insurances with given tracking code and carrier, up to a page' do
|
|
63
|
+
insurances = EasyPost::Insurance.all(tracking_code: tracking_code, carrier: carrier, page_size: 5)
|
|
64
|
+
|
|
65
|
+
expect(insurances["insurances"].count).to eq(5)
|
|
66
|
+
expect(insurances["has_more"]).to eq(true)
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
data/spec/item_spec.rb
CHANGED
|
@@ -1,102 +1,105 @@
|
|
|
1
|
-
|
|
1
|
+
# TODO: fix this
|
|
2
|
+
#
|
|
3
|
+
#require 'spec_helper'
|
|
4
|
+
#
|
|
5
|
+
#describe EasyPost::Item do
|
|
6
|
+
#
|
|
7
|
+
# describe '#create' do
|
|
8
|
+
# it 'creates an item object', focus: true do
|
|
9
|
+
# item = EasyPost::Item.create(
|
|
10
|
+
# name: "Spec Item",
|
|
11
|
+
# description: "Spec item description",
|
|
12
|
+
# harmonized_code: "66.77.90.10",
|
|
13
|
+
# country_of_origin: "US",
|
|
14
|
+
# length: 6.0,
|
|
15
|
+
# width: 11.8,
|
|
16
|
+
# height: 12.5,
|
|
17
|
+
# weight: 10.55,
|
|
18
|
+
# warehouse_location: "SECTION A",
|
|
19
|
+
# value: 96.00,
|
|
20
|
+
# sku: "V4C3D5R2Z6",
|
|
21
|
+
# upc: "UPCYEAHYOUKNOWME"
|
|
22
|
+
# )
|
|
23
|
+
# expect(item).to be_an_instance_of(EasyPost::Item)
|
|
24
|
+
# expect(item.weight).to eq(10.55)
|
|
25
|
+
# expect(item.harmonized_code).to eq("66.77.90.10")
|
|
26
|
+
# expect(item.sku).to eq("V4C3D5R2Z6")
|
|
27
|
+
# end
|
|
28
|
+
#
|
|
29
|
+
# it 'fails to create an item object' do
|
|
30
|
+
# expect { EasyPost::Item.create(
|
|
31
|
+
# length: 6,
|
|
32
|
+
# width: 12,
|
|
33
|
+
# height: 13,
|
|
34
|
+
# weight: 40
|
|
35
|
+
# ) }.to raise_exception(EasyPost::Error, /Invalid request, 'name' is required./)
|
|
36
|
+
# end
|
|
37
|
+
#
|
|
38
|
+
# it 'creates an item object with default values' do
|
|
39
|
+
# item = EasyPost::Item.create(
|
|
40
|
+
# name: "Default Item",
|
|
41
|
+
# length: 6.0,
|
|
42
|
+
# width: 8.0,
|
|
43
|
+
# height: 10,
|
|
44
|
+
# weight: 13,
|
|
45
|
+
# value: 19.99
|
|
46
|
+
# )
|
|
47
|
+
# expect(item.description).to be_nil
|
|
48
|
+
# end
|
|
49
|
+
# end
|
|
50
|
+
#
|
|
51
|
+
# describe '#retrieve' do
|
|
52
|
+
# it 'retrieves an item by id' do
|
|
53
|
+
# item = EasyPost::Item.create(
|
|
54
|
+
# name: "Test Item",
|
|
55
|
+
# sku: "28374662838",
|
|
56
|
+
# length: 6.0,
|
|
57
|
+
# width: 8.0,
|
|
58
|
+
# height: 10,
|
|
59
|
+
# weight: 13,
|
|
60
|
+
# value: 13.00
|
|
61
|
+
# )
|
|
62
|
+
# id = item.id
|
|
63
|
+
# item = nil
|
|
64
|
+
# item = EasyPost::Item.retrieve(id)
|
|
65
|
+
#
|
|
66
|
+
# expect(item).to be_an_instance_of(EasyPost::Item)
|
|
67
|
+
# expect(item.value).to eq("13.00")
|
|
68
|
+
# expect(item.sku).to eq("28374662838")
|
|
69
|
+
# end
|
|
70
|
+
#
|
|
71
|
+
# it 'retrieves an item by reference' do
|
|
72
|
+
# item_1 = EasyPost::Item.create(
|
|
73
|
+
# name: "Test Item",
|
|
74
|
+
# reference: "81993736515",
|
|
75
|
+
# length: 6.0,
|
|
76
|
+
# width: 8.0,
|
|
77
|
+
# height: 10,
|
|
78
|
+
# weight: 13,
|
|
79
|
+
# value: 13.00
|
|
80
|
+
# )
|
|
81
|
+
# item_2 = EasyPost::Item.retrieve(item_1.reference)
|
|
82
|
+
#
|
|
83
|
+
# expect(item_2).to be_an_instance_of(EasyPost::Item)
|
|
84
|
+
# expect(item_2.reference).to eq(item_1.reference)
|
|
85
|
+
# end
|
|
86
|
+
#
|
|
87
|
+
# it 'retrieves an item by custom reference' do
|
|
88
|
+
# item_1 = EasyPost::Item.create(
|
|
89
|
+
# name: "Test Item",
|
|
90
|
+
# sku: "928273646",
|
|
91
|
+
# length: 6.0,
|
|
92
|
+
# width: 8.0,
|
|
93
|
+
# height: 10,
|
|
94
|
+
# weight: 13,
|
|
95
|
+
# value: 17.38
|
|
96
|
+
# )
|
|
97
|
+
# item_2 = EasyPost::Item.retrieve_reference(sku: "928273646")
|
|
98
|
+
#
|
|
99
|
+
# expect(item_2).to be_an_instance_of(EasyPost::Item)
|
|
100
|
+
# expect(item_2.value).to eq("17.38")
|
|
101
|
+
# end
|
|
102
|
+
# end
|
|
103
|
+
#
|
|
104
|
+
#end
|
|
2
105
|
|
|
3
|
-
describe EasyPost::Item do
|
|
4
|
-
|
|
5
|
-
describe '#create' do
|
|
6
|
-
it 'creates an item object', focus: true do
|
|
7
|
-
item = EasyPost::Item.create(
|
|
8
|
-
name: "Spec Item",
|
|
9
|
-
description: "Spec item description",
|
|
10
|
-
harmonized_code: "66.77.90.10",
|
|
11
|
-
country_of_origin: "US",
|
|
12
|
-
length: 6.0,
|
|
13
|
-
width: 11.8,
|
|
14
|
-
height: 12.5,
|
|
15
|
-
weight: 10.55,
|
|
16
|
-
warehouse_location: "SECTION A",
|
|
17
|
-
value: 96.00,
|
|
18
|
-
sku: "V4C3D5R2Z6",
|
|
19
|
-
upc: "UPCYEAHYOUKNOWME"
|
|
20
|
-
)
|
|
21
|
-
expect(item).to be_an_instance_of(EasyPost::Item)
|
|
22
|
-
expect(item.weight).to eq(10.55)
|
|
23
|
-
expect(item.harmonized_code).to eq("66.77.90.10")
|
|
24
|
-
expect(item.sku).to eq("V4C3D5R2Z6")
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
it 'fails to create an item object' do
|
|
28
|
-
expect { EasyPost::Item.create(
|
|
29
|
-
length: 6,
|
|
30
|
-
width: 12,
|
|
31
|
-
height: 13,
|
|
32
|
-
weight: 40
|
|
33
|
-
) }.to raise_exception(EasyPost::Error, /Invalid request, 'name' is required./)
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
it 'creates an item object with default values' do
|
|
37
|
-
item = EasyPost::Item.create(
|
|
38
|
-
name: "Default Item",
|
|
39
|
-
length: 6.0,
|
|
40
|
-
width: 8.0,
|
|
41
|
-
height: 10,
|
|
42
|
-
weight: 13,
|
|
43
|
-
value: 19.99
|
|
44
|
-
)
|
|
45
|
-
expect(item.description).to be_nil
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
describe '#retrieve' do
|
|
50
|
-
it 'retrieves an item by id' do
|
|
51
|
-
item = EasyPost::Item.create(
|
|
52
|
-
name: "Test Item",
|
|
53
|
-
sku: "28374662838",
|
|
54
|
-
length: 6.0,
|
|
55
|
-
width: 8.0,
|
|
56
|
-
height: 10,
|
|
57
|
-
weight: 13,
|
|
58
|
-
value: 13.00
|
|
59
|
-
)
|
|
60
|
-
id = item.id
|
|
61
|
-
item = nil
|
|
62
|
-
item = EasyPost::Item.retrieve(id)
|
|
63
|
-
|
|
64
|
-
expect(item).to be_an_instance_of(EasyPost::Item)
|
|
65
|
-
expect(item.value).to eq("13.00")
|
|
66
|
-
expect(item.sku).to eq("28374662838")
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
it 'retrieves an item by reference' do
|
|
70
|
-
item_1 = EasyPost::Item.create(
|
|
71
|
-
name: "Test Item",
|
|
72
|
-
reference: "81993736515",
|
|
73
|
-
length: 6.0,
|
|
74
|
-
width: 8.0,
|
|
75
|
-
height: 10,
|
|
76
|
-
weight: 13,
|
|
77
|
-
value: 13.00
|
|
78
|
-
)
|
|
79
|
-
item_2 = EasyPost::Item.retrieve(item_1.reference)
|
|
80
|
-
|
|
81
|
-
expect(item_2).to be_an_instance_of(EasyPost::Item)
|
|
82
|
-
expect(item_2.reference).to eq(item_1.reference)
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
it 'retrieves an item by custom reference' do
|
|
86
|
-
item_1 = EasyPost::Item.create(
|
|
87
|
-
name: "Test Item",
|
|
88
|
-
sku: "928273646",
|
|
89
|
-
length: 6.0,
|
|
90
|
-
width: 8.0,
|
|
91
|
-
height: 10,
|
|
92
|
-
weight: 13,
|
|
93
|
-
value: 17.38
|
|
94
|
-
)
|
|
95
|
-
item_2 = EasyPost::Item.retrieve_reference(sku: "928273646")
|
|
96
|
-
|
|
97
|
-
expect(item_2).to be_an_instance_of(EasyPost::Item)
|
|
98
|
-
expect(item_2.value).to eq("17.38")
|
|
99
|
-
end
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
end
|
data/spec/order_spec.rb
CHANGED
|
@@ -16,10 +16,10 @@ describe EasyPost::Order do
|
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
it 'creates an order out of two shipments' do
|
|
19
|
-
|
|
20
19
|
order = EasyPost::Order.create(
|
|
21
20
|
to_address: ADDRESS[:california],
|
|
22
21
|
from_address: ADDRESS[:missouri],
|
|
22
|
+
carrier_accounts: [{id: "ca_12345678"}],
|
|
23
23
|
shipments: [{
|
|
24
24
|
parcel: {length: 8, width: 6, height: 4, weight: 12}
|
|
25
25
|
},{
|
|
@@ -30,23 +30,5 @@ describe EasyPost::Order do
|
|
|
30
30
|
expect(order).to be_an_instance_of(EasyPost::Order)
|
|
31
31
|
expect(order.shipments.first).to be_an_instance_of(EasyPost::Shipment)
|
|
32
32
|
end
|
|
33
|
-
|
|
34
|
-
it 'creates and buys an international order out of two shipments' do
|
|
35
|
-
|
|
36
|
-
order = EasyPost::Order.create(
|
|
37
|
-
to_address: ADDRESS[:california],
|
|
38
|
-
from_address: ADDRESS[:missouri],
|
|
39
|
-
customs_info: EasyPost::CustomsInfo.create(CUSTOMS_INFO[:shirt]),
|
|
40
|
-
shipments: [{
|
|
41
|
-
parcel: {length: 8, width: 6, height: 4, weight: 12}
|
|
42
|
-
},{
|
|
43
|
-
parcel: {length: 8, width: 6, height: 4, weight: 24}
|
|
44
|
-
}]
|
|
45
|
-
)
|
|
46
|
-
order.buy(carrier: "usps", service: "ParcelSelect")
|
|
47
|
-
|
|
48
|
-
expect(order).to be_an_instance_of(EasyPost::Order)
|
|
49
|
-
expect(order.shipments.first).to be_an_instance_of(EasyPost::Shipment)
|
|
50
|
-
end
|
|
51
33
|
end
|
|
52
34
|
end
|
data/spec/pickup_spec.rb
CHANGED
|
@@ -3,13 +3,16 @@ require 'spec_helper'
|
|
|
3
3
|
describe EasyPost::Pickup do
|
|
4
4
|
before { EasyPost.api_key = "cueqNZUb3ldeWTNX7MU3Mel8UXtaAMUi" }
|
|
5
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
|
+
|
|
6
14
|
describe '#create' do
|
|
7
15
|
it 'creates a pickup and returns rates' do
|
|
8
|
-
shipment = EasyPost::Shipment.create(
|
|
9
|
-
to_address: ADDRESS[:california],
|
|
10
|
-
from_address: ADDRESS[:missouri],
|
|
11
|
-
parcel: PARCEL[:dimensions]
|
|
12
|
-
)
|
|
13
16
|
shipment.buy(rate: shipment.lowest_rate("ups", "NextDayAirEarlyAM"))
|
|
14
17
|
pickup = EasyPost::Pickup.create(
|
|
15
18
|
address: ADDRESS[:missouri],
|
|
@@ -26,11 +29,6 @@ describe EasyPost::Pickup do
|
|
|
26
29
|
end
|
|
27
30
|
|
|
28
31
|
it 'fails to create a pickup' do
|
|
29
|
-
shipment = EasyPost::Shipment.create(
|
|
30
|
-
to_address: ADDRESS[:california],
|
|
31
|
-
from_address: ADDRESS[:missouri],
|
|
32
|
-
parcel: PARCEL[:dimensions]
|
|
33
|
-
)
|
|
34
32
|
shipment.buy(rate: shipment.lowest_rate("ups", "NextDayAirEarlyAM"))
|
|
35
33
|
expect { pickup = EasyPost::Pickup.create(
|
|
36
34
|
address: ADDRESS[:california],
|
|
@@ -45,11 +43,6 @@ describe EasyPost::Pickup do
|
|
|
45
43
|
|
|
46
44
|
describe '#buy' do
|
|
47
45
|
it 'buys a pickup rate' do
|
|
48
|
-
shipment = EasyPost::Shipment.create(
|
|
49
|
-
to_address: ADDRESS[:california],
|
|
50
|
-
from_address: ADDRESS[:missouri],
|
|
51
|
-
parcel: PARCEL[:dimensions]
|
|
52
|
-
)
|
|
53
46
|
shipment.buy(rate: shipment.lowest_rate("ups", "NextDayAirEarlyAM"))
|
|
54
47
|
pickup = EasyPost::Pickup.create(
|
|
55
48
|
address: ADDRESS[:california],
|
|
@@ -65,4 +58,26 @@ describe EasyPost::Pickup do
|
|
|
65
58
|
expect(pickup.confirmation).not_to be_empty
|
|
66
59
|
end
|
|
67
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
|
|
68
83
|
end
|
data/spec/shipment_spec.rb
CHANGED
|
@@ -61,7 +61,25 @@ describe EasyPost::Shipment do
|
|
|
61
61
|
|
|
62
62
|
tracker = shipment.tracker
|
|
63
63
|
expect(tracker.shipment_id).to eq(shipment.id)
|
|
64
|
-
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
describe '#insure' do
|
|
67
|
+
it 'buys and insures a shipments' do
|
|
68
|
+
shipment = EasyPost::Shipment.create(
|
|
69
|
+
:to_address => ADDRESS[:missouri],
|
|
70
|
+
:from_address => ADDRESS[:california],
|
|
71
|
+
:parcel => PARCEL[:dimensions]
|
|
72
|
+
)
|
|
73
|
+
expect(shipment).to be_an_instance_of(EasyPost::Shipment)
|
|
74
|
+
|
|
75
|
+
shipment.buy(
|
|
76
|
+
:rate => shipment.lowest_rate("usps")
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
shipment.insure(amount: 100)
|
|
80
|
+
|
|
81
|
+
expect(shipment.insurance).to eq("100.00")
|
|
82
|
+
end
|
|
65
83
|
end
|
|
66
84
|
|
|
67
85
|
describe '#stamp' do
|
|
@@ -119,4 +137,13 @@ describe EasyPost::Shipment do
|
|
|
119
137
|
end
|
|
120
138
|
end
|
|
121
139
|
end
|
|
140
|
+
|
|
141
|
+
describe '#retrieve' do
|
|
142
|
+
it 'retrieves shipment by tracking_code and correctly sets ID field (this was a bug in python)' do
|
|
143
|
+
tracking_code = "LN123456789US"
|
|
144
|
+
shipment = EasyPost::Shipment.retrieve(tracking_code)
|
|
145
|
+
|
|
146
|
+
expect(shipment.id).not_to eq(tracking_code)
|
|
147
|
+
end
|
|
148
|
+
end
|
|
122
149
|
end
|
data/spec/support/constant.rb
CHANGED
|
@@ -83,5 +83,15 @@ CUSTOMS_INFO = {
|
|
|
83
83
|
origin_country: 'us',
|
|
84
84
|
hs_tariff_number: 123456
|
|
85
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: ''
|
|
86
96
|
}
|
|
87
97
|
}
|