easypost 2.0.12 → 2.0.13
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/.gitignore +1 -0
- data/CHANGELOG +6 -0
- data/VERSION +1 -1
- data/lib/easypost.rb +24 -10
- data/lib/easypost/address.rb +5 -4
- data/lib/easypost/batch.rb +2 -2
- data/lib/easypost/item.rb +2 -2
- data/lib/easypost/pickup.rb +19 -0
- data/lib/easypost/pickup_rate.rb +5 -0
- data/lib/easypost/shipment.rb +2 -6
- data/lib/easypost/util.rb +4 -0
- data/spec/address_spec.rb +17 -1
- data/spec/fedex/domestic_spec.rb +10 -0
- data/spec/pickup_spec.rb +69 -0
- data/spec/spec_helper.rb +1 -1
- data/spec/ups/domestic_spec.rb +15 -0
- metadata +5 -3
- data/Gemfile.lock +0 -30
data/.gitignore
CHANGED
data/CHANGELOG
CHANGED
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.0.
|
|
1
|
+
2.0.13
|
data/lib/easypost.rb
CHANGED
|
@@ -24,6 +24,8 @@ require 'easypost/tracker'
|
|
|
24
24
|
require 'easypost/item'
|
|
25
25
|
require 'easypost/container'
|
|
26
26
|
require 'easypost/order'
|
|
27
|
+
require 'easypost/pickup'
|
|
28
|
+
require 'easypost/pickup_rate'
|
|
27
29
|
|
|
28
30
|
require 'easypost/error'
|
|
29
31
|
|
|
@@ -31,6 +33,8 @@ module EasyPost
|
|
|
31
33
|
@@api_key = nil
|
|
32
34
|
@@api_base = 'https://api.easypost.com/v2'
|
|
33
35
|
@@api_version = nil
|
|
36
|
+
@@open_timeout = 30
|
|
37
|
+
@@timeout = 60
|
|
34
38
|
|
|
35
39
|
def self.api_url(url='')
|
|
36
40
|
@@api_base + url
|
|
@@ -60,12 +64,22 @@ module EasyPost
|
|
|
60
64
|
@@api_version
|
|
61
65
|
end
|
|
62
66
|
|
|
67
|
+
def self.http_config
|
|
68
|
+
@@http_config ||= {
|
|
69
|
+
timeout: 60,
|
|
70
|
+
open_timeout: 30,
|
|
71
|
+
verify_ssl: false
|
|
72
|
+
}
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def self.http_config=(http_config_params)
|
|
76
|
+
self.http_config.merge!(http_config_params)
|
|
77
|
+
end
|
|
78
|
+
|
|
63
79
|
def self.request(method, url, api_key, params={}, headers={})
|
|
64
80
|
api_key ||= @@api_key
|
|
65
81
|
raise Error.new('No API key provided.') unless api_key
|
|
66
82
|
|
|
67
|
-
ssl_opts = { :verify_ssl => false }
|
|
68
|
-
|
|
69
83
|
params = Util.objects_to_ids(params)
|
|
70
84
|
url = self.api_url(url)
|
|
71
85
|
case method.to_s.downcase.to_sym
|
|
@@ -86,14 +100,14 @@ module EasyPost
|
|
|
86
100
|
:content_type => 'application/x-www-form-urlencoded'
|
|
87
101
|
}.merge(headers)
|
|
88
102
|
|
|
89
|
-
opts =
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
103
|
+
opts = http_config.merge(
|
|
104
|
+
{
|
|
105
|
+
:method => method,
|
|
106
|
+
:url => url,
|
|
107
|
+
:headers => headers,
|
|
108
|
+
:payload => payload
|
|
109
|
+
}
|
|
110
|
+
)
|
|
97
111
|
|
|
98
112
|
begin
|
|
99
113
|
response = execute_request(opts)
|
data/lib/easypost/address.rb
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
module EasyPost
|
|
2
2
|
class Address < Resource
|
|
3
3
|
|
|
4
|
-
def self.create_and_verify(params={})
|
|
4
|
+
def self.create_and_verify(params={}, carrier=nil, api_key=nil)
|
|
5
5
|
wrapped_params = {}
|
|
6
6
|
wrapped_params[self.class_name().to_sym] = params
|
|
7
|
-
|
|
7
|
+
wrapped_params[:carrier] = carrier
|
|
8
|
+
response, api_key = EasyPost.request(:post, url + '/create_and_verify', api_key, wrapped_params)
|
|
8
9
|
|
|
9
10
|
if response.has_key?(:address)
|
|
10
11
|
if response.has_key?(:message)
|
|
@@ -17,8 +18,8 @@ module EasyPost
|
|
|
17
18
|
end
|
|
18
19
|
end
|
|
19
20
|
|
|
20
|
-
def verify(params={})
|
|
21
|
-
response, api_key = EasyPost.request(:get, url + '/verify', @api_key, params)
|
|
21
|
+
def verify(params={}, carrier=nil)
|
|
22
|
+
response, api_key = EasyPost.request(:get, url + '/verify?carrier=' + String(carrier), @api_key, params)
|
|
22
23
|
|
|
23
24
|
if response.has_key?(:address)
|
|
24
25
|
if response.has_key?(:message)
|
data/lib/easypost/batch.rb
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
module EasyPost
|
|
2
2
|
class Batch < Resource
|
|
3
3
|
|
|
4
|
-
def self.create_and_buy(params={})
|
|
4
|
+
def self.create_and_buy(params={}, api_key=nil)
|
|
5
5
|
wrapped_params = {}
|
|
6
6
|
wrapped_params[self.class_name().to_sym] = params
|
|
7
|
-
response, api_key = EasyPost.request(:post, url + '/create_and_buy',
|
|
7
|
+
response, api_key = EasyPost.request(:post, url + '/create_and_buy', api_key, wrapped_params)
|
|
8
8
|
|
|
9
9
|
return Util.convert_to_easypost_object(response, api_key)
|
|
10
10
|
end
|
data/lib/easypost/item.rb
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
module EasyPost
|
|
2
2
|
class Item < Resource
|
|
3
3
|
|
|
4
|
-
def self.retrieve_reference(params={})
|
|
5
|
-
response, api_key = EasyPost.request(:get, url + '/retrieve_reference',
|
|
4
|
+
def self.retrieve_reference(params={}, api_key=nil)
|
|
5
|
+
response, api_key = EasyPost.request(:get, url + '/retrieve_reference', api_key, params)
|
|
6
6
|
return EasyPost::Util::convert_to_easypost_object(response, api_key) if response
|
|
7
7
|
end
|
|
8
8
|
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module EasyPost
|
|
2
|
+
class Pickup < Resource
|
|
3
|
+
|
|
4
|
+
def buy(params={})
|
|
5
|
+
if params.instance_of?(EasyPost::PickupRate)
|
|
6
|
+
temp = params.clone
|
|
7
|
+
params = {}
|
|
8
|
+
params[:carrier] = temp.carrier
|
|
9
|
+
params[:service] = temp.service
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
response, api_key = EasyPost.request(:post, url + '/buy', @api_key, params)
|
|
13
|
+
self.refresh_from(response, @api_key, true)
|
|
14
|
+
|
|
15
|
+
return self
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
end
|
|
19
|
+
end
|
data/lib/easypost/shipment.rb
CHANGED
|
@@ -71,9 +71,7 @@ module EasyPost
|
|
|
71
71
|
|
|
72
72
|
self.get_rates unless self.rates
|
|
73
73
|
|
|
74
|
-
|
|
75
|
-
carriers = carriers.split(',')
|
|
76
|
-
end
|
|
74
|
+
carriers = carriers.is_a?(String) ? carriers.split(',') : Array(carriers)
|
|
77
75
|
carriers.map!(&:downcase)
|
|
78
76
|
carriers.map!(&:strip)
|
|
79
77
|
|
|
@@ -86,9 +84,7 @@ module EasyPost
|
|
|
86
84
|
end
|
|
87
85
|
end
|
|
88
86
|
|
|
89
|
-
|
|
90
|
-
services = services.split(',')
|
|
91
|
-
end
|
|
87
|
+
services = services.is_a?(String) ? services.split(',') : Array(services)
|
|
92
88
|
services.map!(&:downcase)
|
|
93
89
|
services.map!(&:strip)
|
|
94
90
|
|
data/lib/easypost/util.rb
CHANGED
|
@@ -30,6 +30,8 @@ module EasyPost
|
|
|
30
30
|
'Item' => Item,
|
|
31
31
|
'Container' => Container,
|
|
32
32
|
'Order' => Order,
|
|
33
|
+
'Pickup' => Pickup,
|
|
34
|
+
'PickupRate' => PickupRate,
|
|
33
35
|
'PostageLabel' => PostageLabel }
|
|
34
36
|
|
|
35
37
|
prefixes = { 'adr' => Address,
|
|
@@ -46,6 +48,8 @@ module EasyPost
|
|
|
46
48
|
'item' => Item,
|
|
47
49
|
'container' => Container,
|
|
48
50
|
'order' => Order,
|
|
51
|
+
'pickup' => Pickup,
|
|
52
|
+
'pickuprate' => PickupRate,
|
|
49
53
|
'pl' => PostageLabel }
|
|
50
54
|
|
|
51
55
|
case response
|
data/spec/address_spec.rb
CHANGED
|
@@ -37,6 +37,22 @@ describe EasyPost::Address do
|
|
|
37
37
|
expect(verified_address[:message]).to be_nil
|
|
38
38
|
end
|
|
39
39
|
|
|
40
|
+
it 'verifies an address using fedex' do
|
|
41
|
+
address = EasyPost::Address.create(ADDRESS[:california].reject {|k,v| k == :street2})
|
|
42
|
+
|
|
43
|
+
expect(address.company).to eq('EasyPost')
|
|
44
|
+
expect(address.street1).to eq('164 Townsend Street')
|
|
45
|
+
expect(address.city).to eq('San Francisco')
|
|
46
|
+
expect(address.state).to eq('CA')
|
|
47
|
+
expect(address.zip).to eq('94107')
|
|
48
|
+
expect(address.country).to eq('US')
|
|
49
|
+
expect(address.street2).to be_nil
|
|
50
|
+
|
|
51
|
+
verified_address = address.verify(carrier: :fedex)
|
|
52
|
+
expect(verified_address).to be_an_instance_of(EasyPost::Address)
|
|
53
|
+
expect(verified_address[:message].length).to be > 0
|
|
54
|
+
end
|
|
55
|
+
|
|
40
56
|
it 'is not able to verify address' do
|
|
41
57
|
address = EasyPost::Address.create(
|
|
42
58
|
:company => 'Simpler Postage Inc',
|
|
@@ -47,7 +63,7 @@ describe EasyPost::Address do
|
|
|
47
63
|
:zip => '941abc07'
|
|
48
64
|
)
|
|
49
65
|
|
|
50
|
-
expect { verified_address = address.verify() }.to raise_error(EasyPost::Error, /
|
|
66
|
+
expect { verified_address = address.verify() }.to raise_error(EasyPost::Error, /Unable to verify address./)
|
|
51
67
|
end
|
|
52
68
|
end
|
|
53
69
|
end
|
data/spec/fedex/domestic_spec.rb
CHANGED
|
@@ -159,6 +159,16 @@ describe 'fedex domestic' do
|
|
|
159
159
|
expect(order.shipments[1].postage_label.label_url).to be
|
|
160
160
|
end
|
|
161
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
|
+
|
|
162
172
|
after(:all) do
|
|
163
173
|
begin
|
|
164
174
|
expect(@rates[:residential_evening].rate.to_i).to be > @rates[:residential].rate.to_i
|
data/spec/pickup_spec.rb
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe EasyPost::Pickup do
|
|
4
|
+
|
|
5
|
+
describe '#create' do
|
|
6
|
+
it 'creates a pickup and returns rates' do
|
|
7
|
+
shipment = EasyPost::Shipment.create(
|
|
8
|
+
:to_address => ADDRESS[:california],
|
|
9
|
+
:from_address => ADDRESS[:missouri],
|
|
10
|
+
:parcel => PARCEL[:dimensions]
|
|
11
|
+
)
|
|
12
|
+
shipment.buy(:rate => shipment.lowest_rate("ups", "ground"))
|
|
13
|
+
pickup = EasyPost::Pickup.create(
|
|
14
|
+
address: ADDRESS[:missouri],
|
|
15
|
+
reference: "12345678",
|
|
16
|
+
min_datetime: DateTime.now(),
|
|
17
|
+
max_datetime: DateTime.now() + 14400,
|
|
18
|
+
is_account_address: false,
|
|
19
|
+
instructions: "",
|
|
20
|
+
shipment: shipment
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
expect(pickup).to be_an_instance_of(EasyPost::Pickup)
|
|
24
|
+
expect(pickup.pickup_rates.first).to be_an_instance_of(EasyPost::PickupRate)
|
|
25
|
+
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
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
|
+
shipment.buy(:rate => shipment.lowest_rate("ups", "ground"))
|
|
35
|
+
expect { pickup = EasyPost::Pickup.create(
|
|
36
|
+
address: ADDRESS[:california],
|
|
37
|
+
reference: "12345678",
|
|
38
|
+
max_datetime: DateTime.now() + 14400,
|
|
39
|
+
is_account_address: false,
|
|
40
|
+
instructions: "",
|
|
41
|
+
shipment: shipment
|
|
42
|
+
) }.to raise_exception(EasyPost::Error, /Invalid request, 'min_datetime' is required./)
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
describe '#buy' do
|
|
47
|
+
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
|
+
shipment.buy(:rate => shipment.lowest_rate("ups", "ground"))
|
|
54
|
+
pickup = EasyPost::Pickup.create(
|
|
55
|
+
address: ADDRESS[:california],
|
|
56
|
+
reference: "buy12345678",
|
|
57
|
+
min_datetime: DateTime.now(),
|
|
58
|
+
max_datetime: DateTime.now() + 14400,
|
|
59
|
+
is_account_address: false,
|
|
60
|
+
instructions: "",
|
|
61
|
+
shipment: shipment
|
|
62
|
+
)
|
|
63
|
+
pickup.buy(pickup.pickup_rates.first)
|
|
64
|
+
|
|
65
|
+
expect(pickup.confirmation).not_to be_empty
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
end
|
data/spec/spec_helper.rb
CHANGED
data/spec/ups/domestic_spec.rb
CHANGED
|
@@ -54,6 +54,21 @@ describe 'ups domestic' do
|
|
|
54
54
|
expect(shipment.postage_label.label_url).to end_with(".epl2")
|
|
55
55
|
end
|
|
56
56
|
|
|
57
|
+
# it 'buys an order with shipment level cod', focus: true do
|
|
58
|
+
# order = EasyPost::Order.create(
|
|
59
|
+
# to_address: ADDRESS[:california],
|
|
60
|
+
# from_address: ADDRESS[:missouri],
|
|
61
|
+
# options: {cod_amount: 19.99},
|
|
62
|
+
# shipments: [{
|
|
63
|
+
# parcel: {length: 8, width: 6, height: 4, weight: 12}
|
|
64
|
+
# },{
|
|
65
|
+
# parcel: {length: 8, width: 6, height: 4, weight: 12}
|
|
66
|
+
# }]
|
|
67
|
+
# )
|
|
68
|
+
# p order
|
|
69
|
+
# # order.buy(carrier: "ups", service: "Ground")
|
|
70
|
+
# end
|
|
71
|
+
|
|
57
72
|
after(:all) do
|
|
58
73
|
begin
|
|
59
74
|
expect(@rates[:next_day_air].rate.to_i).to be > @rates[:ground].rate.to_i
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: easypost
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.0.
|
|
4
|
+
version: 2.0.13
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2014-
|
|
12
|
+
date: 2014-10-30 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: rest-client
|
|
@@ -75,7 +75,6 @@ files:
|
|
|
75
75
|
- .gitignore
|
|
76
76
|
- CHANGELOG
|
|
77
77
|
- Gemfile
|
|
78
|
-
- Gemfile.lock
|
|
79
78
|
- LICENSE
|
|
80
79
|
- README.md
|
|
81
80
|
- Rakefile
|
|
@@ -94,6 +93,8 @@ files:
|
|
|
94
93
|
- lib/easypost/object.rb
|
|
95
94
|
- lib/easypost/order.rb
|
|
96
95
|
- lib/easypost/parcel.rb
|
|
96
|
+
- lib/easypost/pickup.rb
|
|
97
|
+
- lib/easypost/pickup_rate.rb
|
|
97
98
|
- lib/easypost/postage_label.rb
|
|
98
99
|
- lib/easypost/rate.rb
|
|
99
100
|
- lib/easypost/refund.rb
|
|
@@ -110,6 +111,7 @@ files:
|
|
|
110
111
|
- spec/fedex/international_spec.rb
|
|
111
112
|
- spec/item_spec.rb
|
|
112
113
|
- spec/order_spec.rb
|
|
114
|
+
- spec/pickup_spec.rb
|
|
113
115
|
- spec/shipment_spec.rb
|
|
114
116
|
- spec/spec_helper.rb
|
|
115
117
|
- spec/ups/domestic_spec.rb
|
data/Gemfile.lock
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
PATH
|
|
2
|
-
remote: .
|
|
3
|
-
specs:
|
|
4
|
-
easypost (2.0.11)
|
|
5
|
-
multi_json (>= 1.0.4, < 2)
|
|
6
|
-
rest-client (~> 1.4)
|
|
7
|
-
|
|
8
|
-
GEM
|
|
9
|
-
remote: https://rubygems.org/
|
|
10
|
-
specs:
|
|
11
|
-
diff-lcs (1.2.4)
|
|
12
|
-
mime-types (1.25.1)
|
|
13
|
-
multi_json (1.8.4)
|
|
14
|
-
rest-client (1.6.7)
|
|
15
|
-
mime-types (>= 1.16)
|
|
16
|
-
rspec (2.13.0)
|
|
17
|
-
rspec-core (~> 2.13.0)
|
|
18
|
-
rspec-expectations (~> 2.13.0)
|
|
19
|
-
rspec-mocks (~> 2.13.0)
|
|
20
|
-
rspec-core (2.13.1)
|
|
21
|
-
rspec-expectations (2.13.0)
|
|
22
|
-
diff-lcs (>= 1.1.3, < 2.0)
|
|
23
|
-
rspec-mocks (2.13.1)
|
|
24
|
-
|
|
25
|
-
PLATFORMS
|
|
26
|
-
ruby
|
|
27
|
-
|
|
28
|
-
DEPENDENCIES
|
|
29
|
-
easypost!
|
|
30
|
-
rspec (~> 2.13.0)
|