easypost 2.0.15 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +13 -5
- data/.gitignore +1 -2
- data/CHANGELOG +0 -17
- data/README.md +0 -3
- data/VERSION +1 -1
- data/lib/easypost.rb +1 -4
- data/lib/easypost/address.rb +3 -10
- data/lib/easypost/object.rb +2 -2
- data/lib/easypost/util.rb +2 -6
- data/spec/address_spec.rb +7 -7
- data/spec/batch_spec.rb +33 -20
- data/spec/container_spec.rb +11 -0
- data/spec/fedex/domestic_spec.rb +180 -0
- data/spec/fedex/international_spec.rb +64 -0
- data/spec/order_spec.rb +70 -2
- data/spec/pickup_spec.rb +14 -13
- data/spec/shipment_spec.rb +23 -38
- data/spec/spec_helper.rb +92 -6
- data/spec/ups/domestic_spec.rb +79 -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 +31 -27
- data/lib/easypost/carrier_account.rb +0 -21
- data/lib/easypost/user.rb +0 -42
- data/spec/carrier_account_spec.rb +0 -83
- data/spec/support/constant.rb +0 -87
- data/spec/tracker_spec.rb +0 -20
- data/spec/user_spec.rb +0 -72
@@ -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/order_spec.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe EasyPost::Order do
|
4
|
+
|
4
5
|
describe '#create' do
|
6
|
+
|
5
7
|
it 'creates an order out of a single shipment' do
|
8
|
+
|
6
9
|
order = EasyPost::Order.create(
|
7
10
|
to_address: ADDRESS[:california],
|
8
11
|
from_address: ADDRESS[:missouri],
|
@@ -34,19 +37,84 @@ describe EasyPost::Order do
|
|
34
37
|
it 'creates and buys an international order out of two shipments' do
|
35
38
|
|
36
39
|
order = EasyPost::Order.create(
|
40
|
+
# to_address: ADDRESS[:canada],
|
37
41
|
to_address: ADDRESS[:california],
|
38
42
|
from_address: ADDRESS[:missouri],
|
39
|
-
customs_info:
|
43
|
+
customs_info: CUSTOMS_INFO[:shirt],
|
40
44
|
shipments: [{
|
41
45
|
parcel: {length: 8, width: 6, height: 4, weight: 12}
|
42
46
|
},{
|
43
47
|
parcel: {length: 8, width: 6, height: 4, weight: 24}
|
44
48
|
}]
|
45
49
|
)
|
46
|
-
order.buy(carrier: "
|
50
|
+
order.buy(carrier: "fedex", service: "FEDEX_GROUND")
|
47
51
|
|
48
52
|
expect(order).to be_an_instance_of(EasyPost::Order)
|
49
53
|
expect(order.shipments.first).to be_an_instance_of(EasyPost::Shipment)
|
50
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
|
51
118
|
end
|
119
|
+
|
52
120
|
end
|
data/spec/pickup_spec.rb
CHANGED
@@ -1,16 +1,15 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe EasyPost::Pickup do
|
4
|
-
before { EasyPost.api_key = "cueqNZUb3ldeWTNX7MU3Mel8UXtaAMUi" }
|
5
4
|
|
6
5
|
describe '#create' do
|
7
6
|
it 'creates a pickup and returns rates' do
|
8
7
|
shipment = EasyPost::Shipment.create(
|
9
|
-
to_address
|
10
|
-
from_address
|
11
|
-
parcel
|
8
|
+
:to_address => ADDRESS[:california],
|
9
|
+
:from_address => ADDRESS[:missouri],
|
10
|
+
:parcel => PARCEL[:dimensions]
|
12
11
|
)
|
13
|
-
shipment.buy(rate
|
12
|
+
shipment.buy(:rate => shipment.lowest_rate("ups", "ground"))
|
14
13
|
pickup = EasyPost::Pickup.create(
|
15
14
|
address: ADDRESS[:missouri],
|
16
15
|
reference: "12345678",
|
@@ -23,15 +22,16 @@ describe EasyPost::Pickup do
|
|
23
22
|
|
24
23
|
expect(pickup).to be_an_instance_of(EasyPost::Pickup)
|
25
24
|
expect(pickup.pickup_rates.first).to be_an_instance_of(EasyPost::PickupRate)
|
25
|
+
|
26
26
|
end
|
27
27
|
|
28
28
|
it 'fails to create a pickup' do
|
29
29
|
shipment = EasyPost::Shipment.create(
|
30
|
-
to_address
|
31
|
-
from_address
|
32
|
-
parcel
|
30
|
+
:to_address => ADDRESS[:california],
|
31
|
+
:from_address => ADDRESS[:missouri],
|
32
|
+
:parcel => PARCEL[:dimensions]
|
33
33
|
)
|
34
|
-
shipment.buy(rate
|
34
|
+
shipment.buy(:rate => shipment.lowest_rate("ups", "ground"))
|
35
35
|
expect { pickup = EasyPost::Pickup.create(
|
36
36
|
address: ADDRESS[:california],
|
37
37
|
reference: "12345678",
|
@@ -46,11 +46,11 @@ describe EasyPost::Pickup do
|
|
46
46
|
describe '#buy' do
|
47
47
|
it 'buys a pickup rate' do
|
48
48
|
shipment = EasyPost::Shipment.create(
|
49
|
-
to_address
|
50
|
-
from_address
|
51
|
-
parcel
|
49
|
+
:to_address => ADDRESS[:california],
|
50
|
+
:from_address => ADDRESS[:missouri],
|
51
|
+
:parcel => PARCEL[:dimensions]
|
52
52
|
)
|
53
|
-
shipment.buy(rate
|
53
|
+
shipment.buy(:rate => shipment.lowest_rate("ups", "ground"))
|
54
54
|
pickup = EasyPost::Pickup.create(
|
55
55
|
address: ADDRESS[:california],
|
56
56
|
reference: "buy12345678",
|
@@ -65,4 +65,5 @@ describe EasyPost::Pickup do
|
|
65
65
|
expect(pickup.confirmation).not_to be_empty
|
66
66
|
end
|
67
67
|
end
|
68
|
+
|
68
69
|
end
|
data/spec/shipment_spec.rb
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe EasyPost::Shipment do
|
4
|
+
|
4
5
|
describe '#create' do
|
5
6
|
it 'creates a shipment object' do
|
6
7
|
|
7
8
|
shipment = EasyPost::Shipment.create(
|
8
|
-
to_address
|
9
|
-
from_address
|
10
|
-
parcel
|
9
|
+
:to_address => ADDRESS[:california],
|
10
|
+
:from_address => ADDRESS[:missouri],
|
11
|
+
:parcel => PARCEL[:dimensions]
|
11
12
|
)
|
12
13
|
expect(shipment).to be_an_instance_of(EasyPost::Shipment)
|
13
14
|
expect(shipment.from_address).to be_an_instance_of(EasyPost::Address)
|
@@ -19,35 +20,20 @@ describe EasyPost::Shipment do
|
|
19
20
|
it 'purchases postage for an international shipment' do
|
20
21
|
|
21
22
|
shipment = EasyPost::Shipment.create(
|
22
|
-
to_address
|
23
|
-
from_address
|
24
|
-
parcel
|
25
|
-
customs_info
|
23
|
+
:to_address => ADDRESS[:canada],
|
24
|
+
:from_address => ADDRESS[:california],
|
25
|
+
:parcel => PARCEL[:dimensions],
|
26
|
+
:customs_info => CUSTOMS_INFO[:shirt]
|
26
27
|
)
|
27
28
|
expect(shipment).to be_an_instance_of(EasyPost::Shipment)
|
28
29
|
|
29
30
|
shipment.buy(
|
30
|
-
rate
|
31
|
+
:rate => shipment.lowest_rate("usps")
|
31
32
|
)
|
32
33
|
expect(shipment.postage_label.label_url.length).to be > 0
|
33
34
|
end
|
34
35
|
|
35
36
|
it 'purchases postage for a domestic shipment' do
|
36
|
-
shipment = EasyPost::Shipment.create(
|
37
|
-
to_address: EasyPost::Address.create(ADDRESS[:missouri]),
|
38
|
-
from_address: ADDRESS[:california],
|
39
|
-
parcel: EasyPost::Parcel.create(PARCEL[:dimensions])
|
40
|
-
)
|
41
|
-
expect(shipment).to be_an_instance_of(EasyPost::Shipment)
|
42
|
-
|
43
|
-
shipment.buy(
|
44
|
-
rate: shipment.lowest_rate("usps")
|
45
|
-
)
|
46
|
-
expect(shipment.postage_label.label_url.length).to be > 0
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
it 'creates and returns a tracker with shipment purchase' do
|
51
37
|
shipment = EasyPost::Shipment.create(
|
52
38
|
:to_address => ADDRESS[:missouri],
|
53
39
|
:from_address => ADDRESS[:california],
|
@@ -58,23 +44,21 @@ describe EasyPost::Shipment do
|
|
58
44
|
shipment.buy(
|
59
45
|
:rate => shipment.lowest_rate("usps")
|
60
46
|
)
|
61
|
-
|
62
|
-
|
63
|
-
expect(tracker.shipment_id).to eq(shipment.id)
|
64
|
-
expect(tracker.tracking_details.length).to be > 0
|
47
|
+
expect(shipment.postage_label.label_url.length).to be > 0
|
48
|
+
end
|
65
49
|
end
|
66
50
|
|
67
51
|
describe '#stamp' do
|
68
52
|
it 'returns a stamp for a domestic shipment' do
|
69
53
|
shipment = EasyPost::Shipment.create(
|
70
|
-
to_address
|
71
|
-
from_address
|
72
|
-
parcel
|
54
|
+
:to_address => ADDRESS[:missouri],
|
55
|
+
:from_address => ADDRESS[:california],
|
56
|
+
:parcel => PARCEL[:dimensions]
|
73
57
|
)
|
74
58
|
expect(shipment).to be_an_instance_of(EasyPost::Shipment)
|
75
59
|
|
76
60
|
shipment.buy(
|
77
|
-
rate
|
61
|
+
:rate => shipment.lowest_rate(['USPS', 'UPS'], 'priority, express')
|
78
62
|
)
|
79
63
|
|
80
64
|
stamp_url = shipment.stamp
|
@@ -86,14 +70,14 @@ describe EasyPost::Shipment do
|
|
86
70
|
describe '#barcode' do
|
87
71
|
it 'returns a barcode for a domestic shipment' do
|
88
72
|
shipment = EasyPost::Shipment.create(
|
89
|
-
to_address
|
90
|
-
from_address
|
91
|
-
parcel
|
73
|
+
:to_address => ADDRESS[:missouri],
|
74
|
+
:from_address => ADDRESS[:california],
|
75
|
+
:parcel => PARCEL[:dimensions]
|
92
76
|
)
|
93
77
|
expect(shipment).to be_an_instance_of(EasyPost::Shipment)
|
94
78
|
|
95
79
|
shipment.buy(
|
96
|
-
rate
|
80
|
+
:rate => shipment.lowest_rate('usps', ['Priority'])
|
97
81
|
)
|
98
82
|
|
99
83
|
barcode_url = shipment.barcode
|
@@ -106,9 +90,9 @@ describe EasyPost::Shipment do
|
|
106
90
|
context 'domestic shipment' do
|
107
91
|
before :all do
|
108
92
|
@shipment = EasyPost::Shipment.create(
|
109
|
-
|
110
|
-
from_address
|
111
|
-
parcel
|
93
|
+
:to_address => ADDRESS[:missouri],
|
94
|
+
:from_address => ADDRESS[:california],
|
95
|
+
:parcel => PARCEL[:dimensions]
|
112
96
|
)
|
113
97
|
end
|
114
98
|
|
@@ -119,4 +103,5 @@ describe EasyPost::Shipment do
|
|
119
103
|
end
|
120
104
|
end
|
121
105
|
end
|
106
|
+
|
122
107
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,10 +1,96 @@
|
|
1
1
|
require 'open-uri'
|
2
2
|
require 'easypost'
|
3
|
+
EasyPost.api_key = 'cueqNZUb3ldeWTNX7MU3Mel8UXtaAMUi'
|
4
|
+
EasyPost.api_base = 'http://ep-vm-whatever:5000/v2'
|
3
5
|
|
4
|
-
|
6
|
+
ADDRESS = {}
|
7
|
+
ADDRESS[:california] = {
|
8
|
+
:company => 'EasyPost',
|
9
|
+
:street1 => '164 Townsend Street',
|
10
|
+
:street2 => 'Unit 1',
|
11
|
+
:city => 'San Francisco',
|
12
|
+
:state => 'CA',
|
13
|
+
:zip => '94107',
|
14
|
+
:phone => '415-123-4567'
|
15
|
+
}
|
5
16
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
17
|
+
ADDRESS[:california_no_phone] = {
|
18
|
+
:company => 'EasyPost',
|
19
|
+
:street1 => '164 Townsend Street',
|
20
|
+
:street2 => 'Unit 1',
|
21
|
+
:city => 'San Francisco',
|
22
|
+
:state => 'CA',
|
23
|
+
:zip => '94107'
|
24
|
+
}
|
25
|
+
|
26
|
+
|
27
|
+
ADDRESS[:missouri] = EasyPost::Address.create(
|
28
|
+
:company => 'Airport Shipping',
|
29
|
+
:street1 => '601 Brasilia Avenue',
|
30
|
+
:city => 'Kansas City',
|
31
|
+
:state => 'MO',
|
32
|
+
:zip => '64153',
|
33
|
+
:phone => '314-924-0383',
|
34
|
+
:email => 'kansas_shipping@example.com'
|
35
|
+
)
|
36
|
+
|
37
|
+
ADDRESS[:canada] = EasyPost::Address.create(
|
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-123-4567'
|
45
|
+
)
|
46
|
+
|
47
|
+
ADDRESS[:canada_no_phone] = {
|
48
|
+
:name => 'Sawyer Bateman',
|
49
|
+
:street1 => '58 Larkspur Cres.',
|
50
|
+
:city => 'St. Albert',
|
51
|
+
:state => 'AB',
|
52
|
+
:zip => 't8n2m4',
|
53
|
+
:country => 'CA',
|
54
|
+
:phone => '780-273-8374'
|
55
|
+
}
|
56
|
+
|
57
|
+
PARCEL = {}
|
58
|
+
PARCEL[:dimensions] = EasyPost::Parcel.create(
|
59
|
+
:width => 12,
|
60
|
+
:length => 16.5,
|
61
|
+
:height => 9.5,
|
62
|
+
:weight => 40.1
|
63
|
+
)
|
64
|
+
|
65
|
+
PARCEL[:dimensions_light] = EasyPost::Parcel.create(
|
66
|
+
:width => 15.2,
|
67
|
+
:length => 18,
|
68
|
+
:height => 9.5,
|
69
|
+
:weight => 3
|
70
|
+
)
|
71
|
+
|
72
|
+
PARCEL[:predefined_medium_flat_rate_box] = EasyPost::Parcel.create(
|
73
|
+
:predefined_package => 'MediumFlatRateBox',
|
74
|
+
:weight => 17
|
75
|
+
)
|
76
|
+
|
77
|
+
CUSTOMS_INFO = {}
|
78
|
+
CUSTOMS_INFO[:shirt] = EasyPost::CustomsInfo.create(
|
79
|
+
:integrated_form_type => 'form_2976',
|
80
|
+
:customs_certify => true,
|
81
|
+
:customs_signer => 'Dr. Pepper',
|
82
|
+
:contents_type => 'gift',
|
83
|
+
:contents_explanation => '', # only required when contents_type => 'other'
|
84
|
+
:eel_pfc => 'NOEEI 30.37(a)',
|
85
|
+
:non_delivery_option => 'abandon',
|
86
|
+
:restriction_type => 'none',
|
87
|
+
:restriction_comments => '',
|
88
|
+
:customs_items => [{
|
89
|
+
:description => 'EasyPost T-shirts',
|
90
|
+
:quantity => 2,
|
91
|
+
:value => 23.56,
|
92
|
+
:weight => 20,
|
93
|
+
:origin_country => 'us',
|
94
|
+
:hs_tariff_number => 123456
|
95
|
+
}]
|
96
|
+
)
|