easypost 2.0.11 → 2.0.12
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.
- data/CHANGELOG +6 -0
- data/Gemfile.lock +3 -3
- data/VERSION +1 -1
- data/lib/easypost.rb +3 -0
- data/lib/easypost/container.rb +4 -0
- data/lib/easypost/item.rb +10 -0
- data/lib/easypost/order.rb +19 -0
- data/lib/easypost/shipment.rb +3 -9
- data/lib/easypost/util.rb +6 -0
- data/spec/address_spec.rb +16 -38
- data/spec/batch_spec.rb +24 -70
- data/spec/container_spec.rb +87 -0
- data/spec/fedex/domestic_spec.rb +170 -0
- data/spec/fedex/international_spec.rb +64 -0
- data/spec/item_spec.rb +102 -0
- data/spec/order_spec.rb +120 -0
- data/spec/shipment_spec.rb +22 -83
- data/spec/spec_helper.rb +83 -70
- data/spec/ups/domestic_spec.rb +64 -0
- data/spec/ups/international_spec.rb +64 -0
- data/spec/usps/domestic_spec.rb +66 -0
- data/spec/usps/electronic_merchandise_returns.rb +94 -0
- data/spec/usps/merchant_returns.rb +0 -0
- metadata +15 -4
- data/spec/refund_spec.rb +0 -65
- data/spec/scan_form_spec.rb +0 -63
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'fedex international' do
|
4
|
+
before(:all) do
|
5
|
+
@rates = {}
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'buys a ground label' do
|
9
|
+
shipment = EasyPost::Shipment.create(
|
10
|
+
:to_address => ADDRESS[:canada],
|
11
|
+
:from_address => ADDRESS[:california],
|
12
|
+
:parcel => PARCEL[:dimensions],
|
13
|
+
:customs_info => CUSTOMS_INFO[:shirt]
|
14
|
+
)
|
15
|
+
shipment.buy(:rate => shipment.lowest_rate("fedex", "FEDEX_GROUND"))
|
16
|
+
label = open(shipment.postage_label.label_url)
|
17
|
+
|
18
|
+
expect(shipment).to be_an_instance_of(EasyPost::Shipment)
|
19
|
+
expect(shipment.selected_rate).to be_an_instance_of(EasyPost::Rate)
|
20
|
+
expect(shipment.selected_rate.service).to eq("FEDEX_GROUND")
|
21
|
+
expect(shipment.postage_label.label_url).to end_with(".png")
|
22
|
+
expect(shipment.tracking_code).to start_with("8000")
|
23
|
+
expect(label.size).to be > 5000
|
24
|
+
|
25
|
+
@rates[:ground] = shipment.selected_rate
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'buys an air label' do
|
29
|
+
shipment = EasyPost::Shipment.create(
|
30
|
+
:to_address => ADDRESS[:canada],
|
31
|
+
:from_address => ADDRESS[:california],
|
32
|
+
:parcel => PARCEL[:dimensions],
|
33
|
+
:customs_info => CUSTOMS_INFO[:shirt]
|
34
|
+
)
|
35
|
+
shipment.buy(:rate => shipment.lowest_rate("fedex", "INTERNATIONAL_PRIORITY"))
|
36
|
+
label = open(shipment.postage_label.label_url)
|
37
|
+
|
38
|
+
expect(shipment.selected_rate.service).to eq("INTERNATIONAL_PRIORITY")
|
39
|
+
expect(shipment.tracking_code).to start_with("794")
|
40
|
+
expect(label.size).to be > 20000
|
41
|
+
|
42
|
+
@rates[:air] = shipment.selected_rate
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'returns no rates for an alcohol shipment', focus: true do
|
46
|
+
shipment = EasyPost::Shipment.create(
|
47
|
+
:to_address => ADDRESS[:canada],
|
48
|
+
:from_address => ADDRESS[:california],
|
49
|
+
:parcel => PARCEL[:dimensions],
|
50
|
+
:customs_info => CUSTOMS_INFO[:shirt],
|
51
|
+
:options => {:alcohol => true}
|
52
|
+
)
|
53
|
+
|
54
|
+
expect { shipment.lowest_rate("fedex") }.to raise_exception(EasyPost::Error, /No rates found/)
|
55
|
+
end
|
56
|
+
|
57
|
+
after(:all) do
|
58
|
+
begin
|
59
|
+
expect(@rates[:air].rate.to_i).to be > @rates[:ground].rate.to_i
|
60
|
+
rescue
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
data/spec/item_spec.rb
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
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
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe EasyPost::Order do
|
4
|
+
|
5
|
+
describe '#create' do
|
6
|
+
|
7
|
+
it 'creates an order out of a single shipment' do
|
8
|
+
|
9
|
+
order = EasyPost::Order.create(
|
10
|
+
to_address: ADDRESS[:california],
|
11
|
+
from_address: ADDRESS[:missouri],
|
12
|
+
shipments: [{
|
13
|
+
parcel: {length: 8, width: 6, height: 4, weight: 12}
|
14
|
+
}]
|
15
|
+
)
|
16
|
+
|
17
|
+
expect(order).to be_an_instance_of(EasyPost::Order)
|
18
|
+
expect(order.shipments.first).to be_an_instance_of(EasyPost::Shipment)
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'creates an order out of two shipments' do
|
22
|
+
|
23
|
+
order = EasyPost::Order.create(
|
24
|
+
to_address: ADDRESS[:california],
|
25
|
+
from_address: ADDRESS[:missouri],
|
26
|
+
shipments: [{
|
27
|
+
parcel: {length: 8, width: 6, height: 4, weight: 12}
|
28
|
+
},{
|
29
|
+
parcel: {length: 8, width: 6, height: 4, weight: 12}
|
30
|
+
}]
|
31
|
+
)
|
32
|
+
|
33
|
+
expect(order).to be_an_instance_of(EasyPost::Order)
|
34
|
+
expect(order.shipments.first).to be_an_instance_of(EasyPost::Shipment)
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'creates and buys an international order out of two shipments' do
|
38
|
+
|
39
|
+
order = EasyPost::Order.create(
|
40
|
+
# to_address: ADDRESS[:canada],
|
41
|
+
to_address: ADDRESS[:california],
|
42
|
+
from_address: ADDRESS[:missouri],
|
43
|
+
customs_info: CUSTOMS_INFO[:shirt],
|
44
|
+
shipments: [{
|
45
|
+
parcel: {length: 8, width: 6, height: 4, weight: 12}
|
46
|
+
},{
|
47
|
+
parcel: {length: 8, width: 6, height: 4, weight: 24}
|
48
|
+
}]
|
49
|
+
)
|
50
|
+
order.buy(carrier: "fedex", service: "FEDEX_GROUND")
|
51
|
+
|
52
|
+
expect(order).to be_an_instance_of(EasyPost::Order)
|
53
|
+
expect(order.shipments.first).to be_an_instance_of(EasyPost::Shipment)
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
# it 'creates an order object out of a single item' do
|
58
|
+
# order = EasyPost::Order.create(
|
59
|
+
# :to_address => ADDRESS[:california],
|
60
|
+
# :from_address => ADDRESS[:missouri],
|
61
|
+
# :containers => "*", # only uses your containers
|
62
|
+
# :items => [ITEM[:shirt]]
|
63
|
+
# )
|
64
|
+
# expect(order).to be_an_instance_of(EasyPost::Order)
|
65
|
+
# expect(order.shiments.first).to be_an_instance_of(EasyPost::Shipment)
|
66
|
+
# expect(order.shiments.first.from_address).to be_an_instance_of(EasyPost::Address)
|
67
|
+
# expect(order.shiments.length).to eq(1)
|
68
|
+
# end
|
69
|
+
|
70
|
+
# it 'creates an order object out of multiple items' do
|
71
|
+
# order = EasyPost::Order.create(
|
72
|
+
# :to_address => ADDRESS[:california],
|
73
|
+
# :from_address => ADDRESS[:missouri],
|
74
|
+
# :containers => ["USPS.FLAT_RATE.*", "USPS.REGIONAL_RATE.*"],
|
75
|
+
# :items => [ITEM[:shirt], ITEM[:pants]]
|
76
|
+
# )
|
77
|
+
# expect(order).to be_an_instance_of(EasyPost::Order)
|
78
|
+
# expect(order.shiments.first).to be_an_instance_of(EasyPost::Shipment)
|
79
|
+
# expect(order.shiments.first.from_address).to be_an_instance_of(EasyPost::Address)
|
80
|
+
# end
|
81
|
+
|
82
|
+
# it 'creates an order object with options' do
|
83
|
+
# order = EasyPost::Order.create(
|
84
|
+
# :to_address => ADDRESS[:california],
|
85
|
+
# :from_address => ADDRESS[:missouri],
|
86
|
+
# :containers => [{id: "container_USPSFR01"}, "USPS.REGIONAL_RATE.*"],
|
87
|
+
# :items => [ITEM[:shirt], ITEM[:pants]],
|
88
|
+
# :options => {alcohol: true}
|
89
|
+
# )
|
90
|
+
# expect(order).to be_an_instance_of(EasyPost::Order)
|
91
|
+
# expect(order.shiments.first).to be_an_instance_of(EasyPost::Shipment)
|
92
|
+
# expect(order.shiments.first.options[:alcohol]).to be_true
|
93
|
+
# end
|
94
|
+
|
95
|
+
# it 'creates an order object with custom item and passed without array' do
|
96
|
+
# item = EasyPost::Item.create(
|
97
|
+
# name: "Test Item",
|
98
|
+
# sku: "1234567890",
|
99
|
+
# length: 6.0,
|
100
|
+
# width: 8.0,
|
101
|
+
# height: 10,
|
102
|
+
# weight: 13,
|
103
|
+
# value: 13.00
|
104
|
+
# ))
|
105
|
+
# item.value = 9.99
|
106
|
+
|
107
|
+
# order = EasyPost::Order.create(
|
108
|
+
# :to_address => ADDRESS[:california],
|
109
|
+
# :from_address => ADDRESS[:missouri],
|
110
|
+
# :containers => EasyPost::Container::ALL,
|
111
|
+
# :items => item
|
112
|
+
# )
|
113
|
+
# expect(order.shiments.first.item).to be_an_instance_of(EasyPost::Item)
|
114
|
+
# expect(order.shiments.first.item.value).to eq(9.99)
|
115
|
+
# expect(order.shiments.first.item.sku).to eq("1234567890")
|
116
|
+
|
117
|
+
# end
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
data/spec/shipment_spec.rb
CHANGED
@@ -4,30 +4,11 @@ describe EasyPost::Shipment do
|
|
4
4
|
|
5
5
|
describe '#create' do
|
6
6
|
it 'creates a shipment object' do
|
7
|
-
from_address = EasyPost::Address.create(
|
8
|
-
:name => "Benchmark Merchandising",
|
9
|
-
:street1 => "329 W 18th Street",
|
10
|
-
:city => "Chicago",
|
11
|
-
:state => "IL",
|
12
|
-
:zip => "60616"
|
13
|
-
)
|
14
|
-
to_address = EasyPost::Address.create(
|
15
|
-
:street1 => "902 Broadway 4th Floor",
|
16
|
-
:city => "New York",
|
17
|
-
:state => "NY",
|
18
|
-
:zip => "10010"
|
19
|
-
)
|
20
|
-
parcel = EasyPost::Parcel.create(
|
21
|
-
:weight => 7.2,
|
22
|
-
:height => 2,
|
23
|
-
:width => 7.5,
|
24
|
-
:length => 10.5
|
25
|
-
)
|
26
7
|
|
27
8
|
shipment = EasyPost::Shipment.create(
|
28
|
-
:to_address
|
29
|
-
:from_address =>
|
30
|
-
:parcel
|
9
|
+
:to_address => ADDRESS[:california],
|
10
|
+
:from_address => ADDRESS[:missouri],
|
11
|
+
:parcel => PARCEL[:dimensions]
|
31
12
|
)
|
32
13
|
expect(shipment).to be_an_instance_of(EasyPost::Shipment)
|
33
14
|
expect(shipment.from_address).to be_an_instance_of(EasyPost::Address)
|
@@ -37,47 +18,31 @@ describe EasyPost::Shipment do
|
|
37
18
|
|
38
19
|
describe '#buy' do
|
39
20
|
it 'purchases postage for an international shipment' do
|
40
|
-
to_address = address_canada
|
41
|
-
from_address = address_california
|
42
|
-
expect(to_address).to be_an_instance_of(EasyPost::Address)
|
43
|
-
|
44
|
-
parcel = parcel_dimensions
|
45
|
-
expect(parcel).to be_an_instance_of(EasyPost::Parcel)
|
46
|
-
|
47
|
-
customs_info = customs_info_poor
|
48
|
-
expect(customs_info).to be_an_instance_of(EasyPost::CustomsInfo)
|
49
21
|
|
50
22
|
shipment = EasyPost::Shipment.create(
|
51
|
-
:to_address
|
52
|
-
:from_address =>
|
53
|
-
:parcel
|
54
|
-
:customs_info =>
|
23
|
+
:to_address => ADDRESS[:canada],
|
24
|
+
:from_address => ADDRESS[:california],
|
25
|
+
:parcel => PARCEL[:dimensions],
|
26
|
+
:customs_info => CUSTOMS_INFO[:shirt]
|
55
27
|
)
|
56
28
|
expect(shipment).to be_an_instance_of(EasyPost::Shipment)
|
57
29
|
|
58
30
|
shipment.buy(
|
59
|
-
:rate => shipment.lowest_rate(
|
31
|
+
:rate => shipment.lowest_rate("usps")
|
60
32
|
)
|
61
33
|
expect(shipment.postage_label.label_url.length).to be > 0
|
62
34
|
end
|
63
35
|
|
64
36
|
it 'purchases postage for a domestic shipment' do
|
65
|
-
to_address = address_california
|
66
|
-
from_address = address_missouri
|
67
|
-
expect(from_address).to be_an_instance_of(EasyPost::Address)
|
68
|
-
|
69
|
-
parcel = parcel_dimensions
|
70
|
-
expect(parcel).to be_an_instance_of(EasyPost::Parcel)
|
71
|
-
|
72
37
|
shipment = EasyPost::Shipment.create(
|
73
|
-
:to_address
|
74
|
-
:from_address =>
|
75
|
-
:parcel
|
38
|
+
:to_address => ADDRESS[:missouri],
|
39
|
+
:from_address => ADDRESS[:california],
|
40
|
+
:parcel => PARCEL[:dimensions]
|
76
41
|
)
|
77
42
|
expect(shipment).to be_an_instance_of(EasyPost::Shipment)
|
78
43
|
|
79
44
|
shipment.buy(
|
80
|
-
:rate => shipment.lowest_rate
|
45
|
+
:rate => shipment.lowest_rate("usps")
|
81
46
|
)
|
82
47
|
expect(shipment.postage_label.label_url.length).to be > 0
|
83
48
|
end
|
@@ -85,17 +50,10 @@ describe EasyPost::Shipment do
|
|
85
50
|
|
86
51
|
describe '#stamp' do
|
87
52
|
it 'returns a stamp for a domestic shipment' do
|
88
|
-
to_address = address_california
|
89
|
-
from_address = address_missouri
|
90
|
-
expect(from_address).to be_an_instance_of(EasyPost::Address)
|
91
|
-
|
92
|
-
parcel = parcel_dimensions
|
93
|
-
expect(parcel).to be_an_instance_of(EasyPost::Parcel)
|
94
|
-
|
95
53
|
shipment = EasyPost::Shipment.create(
|
96
|
-
:to_address
|
97
|
-
:from_address =>
|
98
|
-
:parcel
|
54
|
+
:to_address => ADDRESS[:missouri],
|
55
|
+
:from_address => ADDRESS[:california],
|
56
|
+
:parcel => PARCEL[:dimensions]
|
99
57
|
)
|
100
58
|
expect(shipment).to be_an_instance_of(EasyPost::Shipment)
|
101
59
|
|
@@ -111,17 +69,10 @@ describe EasyPost::Shipment do
|
|
111
69
|
|
112
70
|
describe '#barcode' do
|
113
71
|
it 'returns a barcode for a domestic shipment' do
|
114
|
-
to_address = address_california
|
115
|
-
from_address = address_missouri
|
116
|
-
expect(from_address).to be_an_instance_of(EasyPost::Address)
|
117
|
-
|
118
|
-
parcel = parcel_dimensions
|
119
|
-
expect(parcel).to be_an_instance_of(EasyPost::Parcel)
|
120
|
-
|
121
72
|
shipment = EasyPost::Shipment.create(
|
122
|
-
:to_address
|
123
|
-
:from_address =>
|
124
|
-
:parcel
|
73
|
+
:to_address => ADDRESS[:missouri],
|
74
|
+
:from_address => ADDRESS[:california],
|
75
|
+
:parcel => PARCEL[:dimensions]
|
125
76
|
)
|
126
77
|
expect(shipment).to be_an_instance_of(EasyPost::Shipment)
|
127
78
|
|
@@ -139,10 +90,10 @@ describe EasyPost::Shipment do
|
|
139
90
|
context 'domestic shipment' do
|
140
91
|
before :all do
|
141
92
|
@shipment = EasyPost::Shipment.create(
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
93
|
+
:to_address => ADDRESS[:missouri],
|
94
|
+
:from_address => ADDRESS[:california],
|
95
|
+
:parcel => PARCEL[:dimensions]
|
96
|
+
)
|
146
97
|
end
|
147
98
|
|
148
99
|
it 'filters negative services' do
|
@@ -153,16 +104,4 @@ describe EasyPost::Shipment do
|
|
153
104
|
end
|
154
105
|
end
|
155
106
|
|
156
|
-
describe '#track_with_code' do
|
157
|
-
it 'returns tracking information' do
|
158
|
-
tracking = EasyPost::Shipment.track_with_code({
|
159
|
-
:carrier => 'usps',
|
160
|
-
:tracking_code => '9499907123456123456781'
|
161
|
-
})
|
162
|
-
expect(tracking).to be_an_instance_of(Array)
|
163
|
-
expect(tracking[0][:status].length).to be > 0
|
164
|
-
expect(tracking[0][:message].length).to be > 0
|
165
|
-
end
|
166
|
-
end
|
167
|
-
|
168
107
|
end
|