easypost 2.1.0 → 2.1.1

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.
@@ -1,7 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe EasyPost::Container do
4
-
5
4
  describe '#create' do
6
5
  it 'creates a container object' do
7
6
  container = EasyPost::Container.create(
@@ -73,15 +72,5 @@ describe EasyPost::Container do
73
72
  expect(container_2.height).to eq(container_1.height)
74
73
  expect(container_1.type).to eq("BOX")
75
74
  end
76
-
77
- it 'retrieves global containers' do
78
- container_1 = EasyPost::Container.retrieve("container_USPSFR03")
79
- container_2 = EasyPost::Container.retrieve("container_USPSFR02")
80
-
81
- expect(container_1).to be_an_instance_of(EasyPost::Container)
82
- expect(container_2).to be_an_instance_of(EasyPost::Container)
83
- expect(container_1.reference).to eq(container_2.reference)
84
- end
85
75
  end
86
-
87
76
  end
@@ -1,11 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe EasyPost::Order do
4
-
5
4
  describe '#create' do
6
-
7
5
  it 'creates an order out of a single shipment' do
8
-
9
6
  order = EasyPost::Order.create(
10
7
  to_address: ADDRESS[:california],
11
8
  from_address: ADDRESS[:missouri],
@@ -37,84 +34,19 @@ describe EasyPost::Order do
37
34
  it 'creates and buys an international order out of two shipments' do
38
35
 
39
36
  order = EasyPost::Order.create(
40
- # to_address: ADDRESS[:canada],
41
37
  to_address: ADDRESS[:california],
42
38
  from_address: ADDRESS[:missouri],
43
- customs_info: CUSTOMS_INFO[:shirt],
39
+ customs_info: EasyPost::CustomsInfo.create(CUSTOMS_INFO[:shirt]),
44
40
  shipments: [{
45
41
  parcel: {length: 8, width: 6, height: 4, weight: 12}
46
42
  },{
47
43
  parcel: {length: 8, width: 6, height: 4, weight: 24}
48
44
  }]
49
45
  )
50
- order.buy(carrier: "fedex", service: "FEDEX_GROUND")
46
+ order.buy(carrier: "usps", service: "ParcelSelect")
51
47
 
52
48
  expect(order).to be_an_instance_of(EasyPost::Order)
53
49
  expect(order.shipments.first).to be_an_instance_of(EasyPost::Shipment)
54
50
  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
51
  end
119
-
120
52
  end
@@ -1,15 +1,16 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe EasyPost::Pickup do
4
+ before { EasyPost.api_key = "cueqNZUb3ldeWTNX7MU3Mel8UXtaAMUi" }
4
5
 
5
6
  describe '#create' do
6
7
  it 'creates a pickup and returns rates' do
7
8
  shipment = EasyPost::Shipment.create(
8
- :to_address => ADDRESS[:california],
9
- :from_address => ADDRESS[:missouri],
10
- :parcel => PARCEL[:dimensions]
9
+ to_address: ADDRESS[:california],
10
+ from_address: ADDRESS[:missouri],
11
+ parcel: PARCEL[:dimensions]
11
12
  )
12
- shipment.buy(:rate => shipment.lowest_rate("ups", "ground"))
13
+ shipment.buy(rate: shipment.lowest_rate("ups", "NextDayAirEarlyAM"))
13
14
  pickup = EasyPost::Pickup.create(
14
15
  address: ADDRESS[:missouri],
15
16
  reference: "12345678",
@@ -22,16 +23,15 @@ describe EasyPost::Pickup do
22
23
 
23
24
  expect(pickup).to be_an_instance_of(EasyPost::Pickup)
24
25
  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 => ADDRESS[:california],
31
- :from_address => ADDRESS[:missouri],
32
- :parcel => PARCEL[:dimensions]
30
+ to_address: ADDRESS[:california],
31
+ from_address: ADDRESS[:missouri],
32
+ parcel: PARCEL[:dimensions]
33
33
  )
34
- shipment.buy(:rate => shipment.lowest_rate("ups", "ground"))
34
+ shipment.buy(rate: shipment.lowest_rate("ups", "NextDayAirEarlyAM"))
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 => ADDRESS[:california],
50
- :from_address => ADDRESS[:missouri],
51
- :parcel => PARCEL[:dimensions]
49
+ to_address: ADDRESS[:california],
50
+ from_address: ADDRESS[:missouri],
51
+ parcel: PARCEL[:dimensions]
52
52
  )
53
- shipment.buy(:rate => shipment.lowest_rate("ups", "ground"))
53
+ shipment.buy(rate: shipment.lowest_rate("ups", "NextDayAirEarlyAM"))
54
54
  pickup = EasyPost::Pickup.create(
55
55
  address: ADDRESS[:california],
56
56
  reference: "buy12345678",
@@ -65,5 +65,4 @@ describe EasyPost::Pickup do
65
65
  expect(pickup.confirmation).not_to be_empty
66
66
  end
67
67
  end
68
-
69
68
  end
@@ -1,14 +1,13 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe EasyPost::Shipment do
4
-
5
4
  describe '#create' do
6
5
  it 'creates a shipment object' do
7
6
 
8
7
  shipment = EasyPost::Shipment.create(
9
- :to_address => ADDRESS[:california],
10
- :from_address => ADDRESS[:missouri],
11
- :parcel => PARCEL[:dimensions]
8
+ to_address: ADDRESS[:california],
9
+ from_address: EasyPost::Address.create(ADDRESS[:missouri]),
10
+ parcel: EasyPost::Parcel.create(PARCEL[:dimensions])
12
11
  )
13
12
  expect(shipment).to be_an_instance_of(EasyPost::Shipment)
14
13
  expect(shipment.from_address).to be_an_instance_of(EasyPost::Address)
@@ -20,20 +19,35 @@ describe EasyPost::Shipment do
20
19
  it 'purchases postage for an international shipment' do
21
20
 
22
21
  shipment = EasyPost::Shipment.create(
23
- :to_address => ADDRESS[:canada],
24
- :from_address => ADDRESS[:california],
25
- :parcel => PARCEL[:dimensions],
26
- :customs_info => CUSTOMS_INFO[:shirt]
22
+ to_address: EasyPost::Address.create(ADDRESS[:canada]),
23
+ from_address: ADDRESS[:california],
24
+ parcel: EasyPost::Parcel.create(PARCEL[:dimensions]),
25
+ customs_info: EasyPost::CustomsInfo.create(CUSTOMS_INFO[:shirt])
27
26
  )
28
27
  expect(shipment).to be_an_instance_of(EasyPost::Shipment)
29
28
 
30
29
  shipment.buy(
31
- :rate => shipment.lowest_rate("usps")
30
+ rate: shipment.lowest_rate("usps")
32
31
  )
33
32
  expect(shipment.postage_label.label_url.length).to be > 0
34
33
  end
35
34
 
36
35
  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
37
51
  shipment = EasyPost::Shipment.create(
38
52
  :to_address => ADDRESS[:missouri],
39
53
  :from_address => ADDRESS[:california],
@@ -44,21 +58,23 @@ describe EasyPost::Shipment do
44
58
  shipment.buy(
45
59
  :rate => shipment.lowest_rate("usps")
46
60
  )
47
- expect(shipment.postage_label.label_url.length).to be > 0
48
- end
61
+
62
+ tracker = shipment.tracker
63
+ expect(tracker.shipment_id).to eq(shipment.id)
64
+ expect(tracker.tracking_details.length).to be > 0
49
65
  end
50
66
 
51
67
  describe '#stamp' do
52
68
  it 'returns a stamp for a domestic shipment' do
53
69
  shipment = EasyPost::Shipment.create(
54
- :to_address => ADDRESS[:missouri],
55
- :from_address => ADDRESS[:california],
56
- :parcel => PARCEL[:dimensions]
70
+ to_address: EasyPost::Address.create(ADDRESS[:missouri]),
71
+ from_address: ADDRESS[:california],
72
+ parcel: EasyPost::Parcel.create(PARCEL[:dimensions])
57
73
  )
58
74
  expect(shipment).to be_an_instance_of(EasyPost::Shipment)
59
75
 
60
76
  shipment.buy(
61
- :rate => shipment.lowest_rate(['USPS', 'UPS'], 'priority, express')
77
+ rate: shipment.lowest_rate(['USPS', 'UPS'], 'priority, express')
62
78
  )
63
79
 
64
80
  stamp_url = shipment.stamp
@@ -70,14 +86,14 @@ describe EasyPost::Shipment do
70
86
  describe '#barcode' do
71
87
  it 'returns a barcode for a domestic shipment' do
72
88
  shipment = EasyPost::Shipment.create(
73
- :to_address => ADDRESS[:missouri],
74
- :from_address => ADDRESS[:california],
75
- :parcel => PARCEL[:dimensions]
89
+ to_address: EasyPost::Address.create(ADDRESS[:missouri]),
90
+ from_address: ADDRESS[:california],
91
+ parcel: EasyPost::Parcel.create(PARCEL[:dimensions])
76
92
  )
77
93
  expect(shipment).to be_an_instance_of(EasyPost::Shipment)
78
94
 
79
95
  shipment.buy(
80
- :rate => shipment.lowest_rate('usps', ['Priority'])
96
+ rate: shipment.lowest_rate('usps', ['Priority'])
81
97
  )
82
98
 
83
99
  barcode_url = shipment.barcode
@@ -90,9 +106,9 @@ describe EasyPost::Shipment do
90
106
  context 'domestic shipment' do
91
107
  before :all do
92
108
  @shipment = EasyPost::Shipment.create(
93
- :to_address => ADDRESS[:missouri],
94
- :from_address => ADDRESS[:california],
95
- :parcel => PARCEL[:dimensions]
109
+ to_address: EasyPost::Address.create(ADDRESS[:missouri]),
110
+ from_address: ADDRESS[:california],
111
+ parcel: EasyPost::Parcel.create(PARCEL[:dimensions])
96
112
  )
97
113
  end
98
114
 
@@ -103,5 +119,4 @@ describe EasyPost::Shipment do
103
119
  end
104
120
  end
105
121
  end
106
-
107
122
  end
@@ -1,96 +1,10 @@
1
1
  require 'open-uri'
2
2
  require 'easypost'
3
- EasyPost.api_key = 'cueqNZUb3ldeWTNX7MU3Mel8UXtaAMUi'
4
- EasyPost.api_base = 'http://ep-vm-whatever:5000/v2'
5
3
 
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
- }
4
+ Dir["./spec/support/**/*.rb"].each { |f| require f }
16
5
 
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
- )
6
+ RSpec.configure do |config|
7
+ config.before(:each) do
8
+ EasyPost.api_key = 'cueqNZUb3ldeWTNX7MU3Mel8UXtaAMUi'
9
+ end
10
+ end
@@ -0,0 +1,87 @@
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
+ }