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 CHANGED
@@ -1,7 +1,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 131297bd3896582b77eebf257940afee1118215c
4
- data.tar.gz: 7ef855b3b817a0ba6b7314c4f7d92594640a066a
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZDRiZmUzZDYxMmEzNmNlNWRhNjMxNzZkYjdhMzQ4MGZjZTMxOTM5Mw==
5
+ data.tar.gz: !binary |-
6
+ ZTcxNzNjN2ZhMzYxODA3NmFhMGY5NzQ4NTg2ZTk5NmNjOTAwODI5ZA==
5
7
  SHA512:
6
- metadata.gz: 48f352fc1099de1a4995e96b1dc077133f4bba456407baf89d73263990278676d204da5979f8b3cf3e87154798b1d799f42c03d3714484727640d9a5f544718e
7
- data.tar.gz: 3a9ea6325239c5649348d8c08c9c73648ab469b6509eade346c2914584f8fa1dbd5ba4e071d19f4a6cd90137bfd9bb6b1c452b076a20499c2f8177ff3b5ce78c
8
+ metadata.gz: !binary |-
9
+ MzlmYzQ1YjZkMjQ0YWMzYTVjMzU5ZDI4NzJhYzAzODcxYmQ0MDBiMDVjYTAw
10
+ OTQ2NjE0YjQwMzcyZmY4ZTkyMzcwYjMxODBjM2I3Y2ZhMmQ0NzAzMThhOWNm
11
+ OTEzYjVkNzMzNmFmZTMyNmMyODBjNjJiYzRkZmM3N2Q0NDcxNjU=
12
+ data.tar.gz: !binary |-
13
+ NjNlMmY0ZmI5MDdjNWI1ODM0MDBkZTBhMjQ0OTk3NDhkMjIxNTNlMTZhOWQ0
14
+ OGVlYjVlYjRkMjhkMThiMDZlMmRhZmM4NTIxMWJmMWI4NTc1ODRmMDNjMzk1
15
+ ODExMzE1MmE0OWMxOTY4ZWRmMTg3YThiOWE4NGE2NWY1Mzk5ZGU=
data/.gitignore CHANGED
@@ -25,5 +25,4 @@ doc/
25
25
  Icon
26
26
  ._*
27
27
  .Spotlight-V100
28
- .Trashes
29
- vendor/
28
+ .Trashes
data/CHANGELOG CHANGED
@@ -1,20 +1,3 @@
1
- === 2.0.15 2015-04-15
2
-
3
- * Added tracker to shipment buy response
4
- * Updated tracker tests
5
-
6
-
7
- === 2.0.14 2015-04-15
8
-
9
- * Added User and CarrierAccount models with CRUD functionality
10
-
11
-
12
- === 2.0.13 2014-10-30
13
-
14
- * Added Pickup, PickupRate resources.
15
- * Added ability to pass api_key to a few resources that were missing it.
16
-
17
-
18
1
  === 2.0.12 2014-07-07
19
2
 
20
3
  * Added Item, Container, and Order resources.
data/README.md CHANGED
@@ -1,8 +1,5 @@
1
1
  # EasyPost Ruby Client Library
2
2
 
3
- [<img src="https://circleci.com/gh/EasyPost/easypost-ruby.png?circle-token=80adb5236ed1fdce20810b055af79c63c3d5796b">](https://circleci.com/gh/EasyPost/easypost-ruby)
4
-
5
-
6
3
  EasyPost is a simple shipping API. You can sign up for an account at https://easypost.com
7
4
 
8
5
  Installation
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.15
1
+ 2.1.0
data/lib/easypost.rb CHANGED
@@ -26,8 +26,6 @@ require 'easypost/container'
26
26
  require 'easypost/order'
27
27
  require 'easypost/pickup'
28
28
  require 'easypost/pickup_rate'
29
- require 'easypost/carrier_account'
30
- require 'easypost/user'
31
29
 
32
30
  require 'easypost/error'
33
31
 
@@ -70,8 +68,7 @@ module EasyPost
70
68
  @@http_config ||= {
71
69
  timeout: 60,
72
70
  open_timeout: 30,
73
- verify_ssl: false,
74
- ssl_version: "TLSv1",
71
+ verify_ssl: false
75
72
  }
76
73
  end
77
74
 
@@ -14,16 +14,12 @@ module EasyPost
14
14
  verified_address = EasyPost::Util::convert_to_easypost_object(response[:address], api_key)
15
15
  return verified_address
16
16
  else
17
- raise_verification_failure
17
+ raise Error.new("Unable to verify address.")
18
18
  end
19
19
  end
20
20
 
21
21
  def verify(params={}, carrier=nil)
22
- begin
23
- response, api_key = EasyPost.request(:get, url + '/verify?carrier=' + String(carrier), @api_key, params)
24
- rescue
25
- raise_verification_failure
26
- end
22
+ response, api_key = EasyPost.request(:get, url + '/verify?carrier=' + String(carrier), @api_key, params)
27
23
 
28
24
  if response.has_key?(:address)
29
25
  if response.has_key?(:message)
@@ -32,14 +28,11 @@ module EasyPost
32
28
  verified_address = EasyPost::Util::convert_to_easypost_object(response[:address], api_key)
33
29
  return verified_address
34
30
  else
35
- raise_verification_failure
31
+ raise Error.new("Unable to verify address.")
36
32
  end
37
33
 
38
34
  return self
39
35
  end
40
36
 
41
- def raise_verification_failure
42
- raise Error.new("Unable to verify address.")
43
- end
44
37
  end
45
38
  end
@@ -32,11 +32,11 @@ module EasyPost
32
32
  @api_key = api_key
33
33
 
34
34
  added = Set.new(values.keys - @values.keys)
35
-
35
+
36
36
  instance_eval do
37
37
  add_accessors(added)
38
38
  end
39
-
39
+
40
40
  values.each do |k, v|
41
41
  @values[k] = Util.convert_to_easypost_object(v, api_key)
42
42
  @transient_values.delete(k)
data/lib/easypost/util.rb CHANGED
@@ -32,9 +32,7 @@ module EasyPost
32
32
  'Order' => Order,
33
33
  'Pickup' => Pickup,
34
34
  'PickupRate' => PickupRate,
35
- 'PostageLabel' => PostageLabel,
36
- 'CarrierAccount' => CarrierAccount,
37
- 'User' => User }
35
+ 'PostageLabel' => PostageLabel }
38
36
 
39
37
  prefixes = { 'adr' => Address,
40
38
  'sf' => ScanForm,
@@ -52,9 +50,7 @@ module EasyPost
52
50
  'order' => Order,
53
51
  'pickup' => Pickup,
54
52
  'pickuprate' => PickupRate,
55
- 'pl' => PostageLabel,
56
- 'ca' => CarrierAccount,
57
- 'user' => User }
53
+ 'pl' => PostageLabel }
58
54
 
59
55
  case response
60
56
  when Array
data/spec/address_spec.rb CHANGED
@@ -55,15 +55,15 @@ describe EasyPost::Address do
55
55
 
56
56
  it 'is not able to verify address' do
57
57
  address = EasyPost::Address.create(
58
- company: 'Simpler Postage Inc',
59
- street1: '388 Junk Teerts',
60
- street2: 'Apt 20',
61
- city: 'San Francisco',
62
- state: 'CA',
63
- zip: '941abc07'
58
+ :company => 'Simpler Postage Inc',
59
+ :street1 => '388 Junk Teerts',
60
+ :street2 => 'Apt 20',
61
+ :city => 'San Francisco',
62
+ :state => 'CA',
63
+ :zip => '941abc07'
64
64
  )
65
65
 
66
- expect { verified_address = address.verify() }.to raise_error(EasyPost::Error, /Unable to verify addres/)
66
+ expect { verified_address = address.verify() }.to raise_error(EasyPost::Error, /Unable to verify address./)
67
67
  end
68
68
  end
69
69
  end
data/spec/batch_spec.rb CHANGED
@@ -1,48 +1,61 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe EasyPost::Batch do
4
+
4
5
  describe '#create' do
5
6
  it 'creates a batch object' do
6
7
  batch = EasyPost::Batch.create({
7
- shipment: [{
8
- from_address: ADDRESS[:california],
9
- to_address: EasyPost::Address.create(ADDRESS[:missouri]),
10
- parcel: EasyPost::Parcel.create(PARCEL[:dimensions])
8
+ :shipment => [{
9
+ :from_address => ADDRESS[:california],
10
+ :to_address => ADDRESS[:missouri],
11
+ :parcel => PARCEL[:dimensions]
11
12
  }, {
12
- from_address: ADDRESS[:california],
13
- to_address: EasyPost::Address.create(ADDRESS[:canada]),
14
- parcel: EasyPost::Parcel.create(PARCEL[:dimensions]),
13
+ :from_address => ADDRESS[:california],
14
+ :to_address => ADDRESS[:canada],
15
+ :parcel => PARCEL[:dimensions],
15
16
  }],
16
- reference: "batch123456789"
17
+ :reference => "batch123456789"
17
18
  })
18
19
  expect(batch).to be_an_instance_of(EasyPost::Batch)
19
20
  expect(batch.num_shipments).to eq(2)
20
21
  expect(batch.reference).to eq("batch123456789")
21
22
  expect(batch.state).to eq("creating")
23
+
24
+ # sleeps_left = 10
25
+ # while (batch.state == "creating" && sleeps_left > 0) do
26
+ # sleep(3)
27
+ # batch.refresh
28
+ # sleeps_left -= 1
29
+ # end
30
+
31
+ # expect(batch.state).to equal("created")
32
+ # expect(batch.status[:created]).to equal(2)
33
+
22
34
  end
23
35
  end
24
36
 
25
37
  describe '#create_and_buy' do
26
38
  it 'creates a batch object and delayed jobs for purchasing the postage_labels' do
27
39
  batch = EasyPost::Batch.create({
28
- shipment: [{
29
- from_address: ADDRESS[:california],
30
- to_address: EasyPost::Address.create(ADDRESS[:missouri]),
31
- parcel: EasyPost::Parcel.create(PARCEL[:dimensions]),
32
- carrier: "usps",
33
- service: "priority"
40
+ :shipment => [{
41
+ :from_address => ADDRESS[:california],
42
+ :to_address => ADDRESS[:missouri],
43
+ :parcel => PARCEL[:dimensions],
44
+ :carrier => "usps",
45
+ :service => "priority"
34
46
  }, {
35
- from_address: ADDRESS[:california],
36
- to_address: EasyPost::Address.create(ADDRESS[:canada]),
37
- parcel: EasyPost::Parcel.create(PARCEL[:dimensions]),
38
- carrier: "usps",
39
- service: "prioritymailinternational"
47
+ :from_address => ADDRESS[:california],
48
+ :to_address => ADDRESS[:canada],
49
+ :parcel => PARCEL[:dimensions],
50
+ :carrier => "usps",
51
+ :service => "prioritymailinternational"
40
52
  }],
41
- reference: "batch123456789"
53
+ :reference => "batch123456789"
42
54
  })
43
55
  expect(batch).to be_an_instance_of(EasyPost::Batch)
44
56
  expect(batch.state).to eq("creating")
45
57
  expect(batch.num_shipments).to eq(2)
46
58
  end
47
59
  end
60
+
48
61
  end
@@ -1,6 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe EasyPost::Container do
4
+
4
5
  describe '#create' do
5
6
  it 'creates a container object' do
6
7
  container = EasyPost::Container.create(
@@ -72,5 +73,15 @@ describe EasyPost::Container do
72
73
  expect(container_2.height).to eq(container_1.height)
73
74
  expect(container_1.type).to eq("BOX")
74
75
  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
75
85
  end
86
+
76
87
  end
@@ -0,0 +1,180 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'fedex domestic' do
4
+ before(:all) do
5
+ @rates = {}
6
+ end
7
+
8
+ it 'buys a commercial ground label' do
9
+ shipment = EasyPost::Shipment.create(
10
+ :to_address => ADDRESS[:california],
11
+ :from_address => ADDRESS[:missouri],
12
+ :parcel => PARCEL[:dimensions]
13
+ )
14
+ shipment.buy(:rate => shipment.lowest_rate("fedex", "FEDEX_GROUND"))
15
+ label = open(shipment.postage_label.label_url)
16
+
17
+ expect(shipment).to be_an_instance_of(EasyPost::Shipment)
18
+ expect(shipment.selected_rate).to be_an_instance_of(EasyPost::Rate)
19
+ expect(shipment.selected_rate.service).to eq("FEDEX_GROUND")
20
+ expect(shipment.postage_label.label_url).to end_with(".png")
21
+ expect(shipment.tracking_code).to start_with("8000")
22
+ expect(label.size).to be > 5000
23
+
24
+ @rates[:commercial] = shipment.selected_rate
25
+ end
26
+
27
+ it 'buys a residential ground label' do
28
+ shipment = EasyPost::Shipment.create(
29
+ :to_address => ADDRESS[:california],
30
+ :from_address => ADDRESS[:missouri],
31
+ :parcel => PARCEL[:dimensions],
32
+ :options => {:residential_to_address => true}
33
+ )
34
+ shipment.buy(:rate => shipment.lowest_rate("fedex", "GROUND_HOME_DELIVERY"))
35
+ label = open(shipment.postage_label.label_url)
36
+
37
+ expect(shipment.selected_rate.service).to eq("GROUND_HOME_DELIVERY")
38
+ expect(shipment.tracking_code).to start_with("8000")
39
+ expect(label.size).to be > 5000
40
+
41
+ @rates[:residential] = shipment.selected_rate
42
+ end
43
+
44
+ it 'buys a ground evening delivery label' do
45
+ shipment = EasyPost::Shipment.create(
46
+ :to_address => ADDRESS[:california],
47
+ :from_address => ADDRESS[:missouri],
48
+ :parcel => PARCEL[:dimensions],
49
+ :options => {:residential_to_address => true,
50
+ :delivery_time_preference => "evening"}
51
+ )
52
+ shipment.buy(:rate => shipment.lowest_rate("fedex", "GROUND_HOME_DELIVERY"))
53
+
54
+ expect(shipment.postage_label.label_url).to end_with(".png")
55
+
56
+ @rates[:residential_evening] = shipment.selected_rate
57
+ end
58
+
59
+ it 'raises error without recipient phone number' do
60
+ shipment = EasyPost::Shipment.create(
61
+ :to_address => ADDRESS[:california_no_phone],
62
+ :from_address => ADDRESS[:missouri],
63
+ :parcel => PARCEL[:dimensions]
64
+ )
65
+
66
+ expect { shipment.buy(rate: shipment.lowest_rate("fedex")) }.to raise_error(EasyPost::Error, /Unable to buy FedEx shipment without recipient phone number./)
67
+ end
68
+
69
+ it 'buys a label for an alcoholic shipment with epl2 label' do
70
+ shipment = EasyPost::Shipment.create(
71
+ :to_address => ADDRESS[:california],
72
+ :from_address => ADDRESS[:missouri],
73
+ :parcel => PARCEL[:dimensions],
74
+ :options => {
75
+ :alcohol => 1,
76
+ :label_format => "epl2"
77
+ }
78
+ )
79
+ shipment.buy(:rate => shipment.lowest_rate("fedex", "PRIORITY_OVERNIGHT"))
80
+
81
+ expect(shipment.postage_label.label_url).to end_with(".epl2")
82
+ end
83
+
84
+ it 'buys a label for a ground cod shipment' do
85
+ shipment = EasyPost::Shipment.create(
86
+ :to_address => ADDRESS[:california],
87
+ :from_address => ADDRESS[:missouri],
88
+ :parcel => PARCEL[:dimensions]
89
+ )
90
+ shipment_cod = EasyPost::Shipment.create(
91
+ :to_address => ADDRESS[:california],
92
+ :from_address => ADDRESS[:missouri],
93
+ :parcel => PARCEL[:dimensions],
94
+ :options => {cod_amount: 19.99}
95
+ )
96
+ shipment_cod.buy(rate: shipment_cod.lowest_rate("fedex", "FEDEX_GROUND"))
97
+
98
+ expect(shipment.lowest_rate("fedex", "FEDEX_GROUND").rate.to_f).to be < (shipment_cod.lowest_rate("fedex", "FEDEX_GROUND").rate.to_f)
99
+ expect(shipment.lowest_rate("fedex", "PRIORITY_OVERNIGHT").rate.to_f).to be < (shipment_cod.lowest_rate("fedex", "PRIORITY_OVERNIGHT").rate.to_f)
100
+ expect(shipment_cod.postage_label.label_url).to be
101
+ end
102
+
103
+ it 'buys a label for a ground multi-parcel cod shipment' do
104
+ order = EasyPost::Order.create(
105
+ to_address: ADDRESS[:california],
106
+ from_address: ADDRESS[:missouri],
107
+ shipments: [{
108
+ parcel: {length: 8, width: 6, height: 4, weight: 12},
109
+ options: {cod_amount: 14.99}
110
+ },{
111
+ parcel: {length: 8, width: 6, height: 4, weight: 12},
112
+ options: {cod_amount: 18.75}
113
+ }]
114
+ )
115
+ order.buy(carrier: "fedex", service: "FEDEX_GROUND")
116
+
117
+ expect(order).to be_an_instance_of(EasyPost::Order)
118
+ expect(order.shipments.first).to be_an_instance_of(EasyPost::Shipment)
119
+ expect(order.shipments[0].postage_label.label_url).to be
120
+ expect(order.shipments[1].postage_label.label_url).to be
121
+ end
122
+
123
+ it 'buys a label for an express cod shipment' do
124
+ shipment = EasyPost::Shipment.create(
125
+ :to_address => ADDRESS[:california],
126
+ :from_address => ADDRESS[:missouri],
127
+ :parcel => PARCEL[:dimensions]
128
+ )
129
+ shipment_cod = EasyPost::Shipment.create(
130
+ :to_address => ADDRESS[:california],
131
+ :from_address => ADDRESS[:missouri],
132
+ :parcel => PARCEL[:dimensions],
133
+ :options => {cod_amount: 19.99}
134
+ )
135
+ shipment_cod.buy(rate: shipment_cod.lowest_rate("fedex", "PRIORITY_OVERNIGHT"))
136
+
137
+ expect(shipment.lowest_rate("fedex", "FEDEX_GROUND").rate.to_f).to be < (shipment_cod.lowest_rate("fedex", "FEDEX_GROUND").rate.to_f)
138
+ expect(shipment.lowest_rate("fedex", "PRIORITY_OVERNIGHT").rate.to_f).to be < (shipment_cod.lowest_rate("fedex", "PRIORITY_OVERNIGHT").rate.to_f)
139
+ expect(shipment_cod.postage_label.label_url).to be
140
+ end
141
+
142
+ it 'buys a label for an express multi-parcel cod shipment' do
143
+ order = EasyPost::Order.create(
144
+ to_address: ADDRESS[:california],
145
+ from_address: ADDRESS[:missouri],
146
+ shipments: [{
147
+ parcel: {length: 8, width: 6, height: 4, weight: 12},
148
+ options: {cod_amount: 14.99}
149
+ },{
150
+ parcel: {length: 8, width: 6, height: 4, weight: 12},
151
+ options: {cod_amount: 18.75}
152
+ }]
153
+ )
154
+ order.buy(carrier: "fedex", service: "PRIORITY_OVERNIGHT")
155
+
156
+ expect(order).to be_an_instance_of(EasyPost::Order)
157
+ expect(order.shipments.first).to be_an_instance_of(EasyPost::Shipment)
158
+ expect(order.shipments[0].postage_label.label_url).to be
159
+ expect(order.shipments[1].postage_label.label_url).to be
160
+ end
161
+
162
+ it 'buys a label using a thid party account number' do
163
+ shipment = EasyPost::Shipment.create(
164
+ :to_address => ADDRESS[:california],
165
+ :from_address => ADDRESS[:missouri],
166
+ :parcel => PARCEL[:dimensions],
167
+ :options => {:bill_third_party_account => "12345678"}
168
+ )
169
+ expect { shipment.buy(rate: shipment.lowest_rate("fedex")) }.to raise_error(EasyPost::Error, /ShippingChargesPayment Payor - The payor's account number is invalid/)
170
+ end
171
+
172
+ after(:all) do
173
+ begin
174
+ expect(@rates[:residential_evening].rate.to_i).to be > @rates[:residential].rate.to_i
175
+ expect(@rates[:residential].rate.to_i).to be > @rates[:commercial].rate.to_i
176
+ rescue
177
+ end
178
+ end
179
+
180
+ end