easypost 3.5.0 → 4.0.0
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.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +19 -5
- data/.gitignore +1 -0
- data/.rubocop.yml +5 -0
- data/CHANGELOG.md +88 -88
- data/Gemfile +2 -0
- data/README.md +2 -10
- data/Rakefile +2 -1
- data/UPGRADE_GUIDE.md +62 -0
- data/VERSION +1 -1
- data/bin/easypost-irb +5 -3
- data/easycop.yml +180 -0
- data/easypost.gemspec +21 -19
- data/lib/easypost/address.rb +26 -26
- data/lib/easypost/api_key.rb +3 -0
- data/lib/easypost/batch.rb +31 -30
- data/lib/easypost/brand.rb +4 -0
- data/lib/easypost/carrier_account.rb +4 -0
- data/lib/easypost/carrier_type.rb +3 -0
- data/lib/easypost/customs_info.rb +5 -1
- data/lib/easypost/customs_item.rb +5 -1
- data/lib/easypost/error.rb +7 -7
- data/lib/easypost/event.rb +5 -1
- data/lib/easypost/insurance.rb +4 -0
- data/lib/easypost/object.rb +44 -28
- data/lib/easypost/order.rb +15 -11
- data/lib/easypost/parcel.rb +7 -0
- data/lib/easypost/pickup.rb +15 -9
- data/lib/easypost/pickup_rate.rb +3 -1
- data/lib/easypost/postage_label.rb +3 -0
- data/lib/easypost/rate.rb +7 -0
- data/lib/easypost/refund.rb +3 -0
- data/lib/easypost/report.rb +9 -16
- data/lib/easypost/resource.rb +41 -25
- data/lib/easypost/scan_form.rb +8 -3
- data/lib/easypost/shipment.rb +47 -51
- data/lib/easypost/tax_identifier.rb +4 -0
- data/lib/easypost/tracker.rb +9 -4
- data/lib/easypost/user.rb +14 -5
- data/lib/easypost/util.rb +21 -17
- data/lib/easypost/version.rb +3 -1
- data/lib/easypost/webhook.rb +18 -12
- data/lib/easypost.rb +59 -51
- metadata +74 -19
- data/lib/easypost/print_job.rb +0 -2
- data/lib/easypost/printer.rb +0 -24
data/easypost.gemspec
CHANGED
@@ -1,31 +1,33 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
lib = File.expand_path(
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
4
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
-
require
|
5
|
+
require 'easypost/version'
|
6
6
|
|
7
7
|
Gem::Specification.new do |spec|
|
8
|
-
spec.name =
|
8
|
+
spec.name = 'easypost'
|
9
9
|
spec.version = EasyPost::VERSION
|
10
|
-
spec.licenses = [
|
11
|
-
spec.
|
12
|
-
spec.
|
13
|
-
spec.
|
14
|
-
spec.
|
15
|
-
spec.
|
16
|
-
spec.homepage = "https://www.easypost.com/docs"
|
10
|
+
spec.licenses = ['MIT']
|
11
|
+
spec.summary = 'EasyPost Ruby Client Library'
|
12
|
+
spec.description = 'Client library for accessing the EasyPost shipping API via Ruby.'
|
13
|
+
spec.authors = 'EasyPost Developers'
|
14
|
+
spec.email = 'oss@easypost.com'
|
15
|
+
spec.homepage = 'https://www.easypost.com/docs'
|
17
16
|
|
18
17
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
19
18
|
f.match(%r{^(test|spec|features)/})
|
20
19
|
end
|
21
20
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
22
|
-
spec.
|
23
|
-
spec.
|
24
|
-
spec.required_ruby_version = ">= 2.2"
|
21
|
+
spec.require_paths = ['lib']
|
22
|
+
spec.required_ruby_version = '>= 2.5'
|
25
23
|
|
26
|
-
spec.add_development_dependency
|
27
|
-
spec.add_development_dependency
|
28
|
-
spec.add_development_dependency
|
29
|
-
spec.add_development_dependency
|
30
|
-
spec.add_development_dependency
|
24
|
+
spec.add_development_dependency 'pry', '~> 0.14'
|
25
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
26
|
+
spec.add_development_dependency 'rspec', '~> 3.10'
|
27
|
+
spec.add_development_dependency 'rubocop', '~> 1.24'
|
28
|
+
spec.add_development_dependency 'rubocop-rspec', '~> 2.7'
|
29
|
+
spec.add_development_dependency 'simplecov', '~> 0.21'
|
30
|
+
spec.add_development_dependency 'simplecov-lcov', '~> 0.8'
|
31
|
+
spec.add_development_dependency 'vcr', '~> 6.0'
|
32
|
+
spec.add_development_dependency 'webmock', '~> 3.14'
|
31
33
|
end
|
data/lib/easypost/address.rb
CHANGED
@@ -1,16 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Address objects are used to represent people, places, and organizations in a number of contexts.
|
1
4
|
class EasyPost::Address < EasyPost::Resource
|
2
5
|
attr_accessor :message # Backwards compatibility
|
3
6
|
|
4
|
-
|
7
|
+
# Create an Address.
|
8
|
+
def self.create(params = {}, api_key = nil)
|
5
9
|
url = self.url
|
6
10
|
|
7
|
-
address = params.reject { |k,_|
|
11
|
+
address = params.reject { |k, _| [:verify, :verify_strict].include?(k) }
|
8
12
|
|
9
13
|
if params[:verify] || params[:verify_strict]
|
10
14
|
verify = params[:verify] || []
|
11
15
|
verify_strict = params[:verify_strict] || []
|
12
16
|
|
13
|
-
url +=
|
17
|
+
url += '?'
|
14
18
|
verify.each do |verification|
|
15
19
|
url += "verify[]=#{verification}&"
|
16
20
|
end
|
@@ -19,40 +23,36 @@ class EasyPost::Address < EasyPost::Resource
|
|
19
23
|
end
|
20
24
|
end
|
21
25
|
|
22
|
-
response = EasyPost.make_request(:post, url, api_key, {address: address})
|
23
|
-
|
26
|
+
response = EasyPost.make_request(:post, url, api_key, { address: address })
|
27
|
+
EasyPost::Util.convert_to_easypost_object(response, api_key)
|
24
28
|
end
|
25
29
|
|
26
|
-
|
30
|
+
# Create and verify an Address in one call.
|
31
|
+
def self.create_and_verify(params = {}, carrier = nil, api_key = nil)
|
27
32
|
wrapped_params = {}
|
28
|
-
wrapped_params[
|
33
|
+
wrapped_params[class_name.to_sym] = params
|
29
34
|
wrapped_params[:carrier] = carrier
|
30
|
-
response = EasyPost.make_request(:post, url
|
35
|
+
response = EasyPost.make_request(:post, "#{url}/create_and_verify", api_key, wrapped_params)
|
31
36
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
verified_address = EasyPost::Util::convert_to_easypost_object(response["address"], api_key)
|
37
|
-
return verified_address
|
38
|
-
else
|
39
|
-
raise EasyPost::Error.new("Unable to verify address.")
|
37
|
+
raise EasyPost::Error.new('Unable to verify address.') unless response.key?('address')
|
38
|
+
|
39
|
+
if response.key?('message')
|
40
|
+
response['address']['message'] = response['message']
|
40
41
|
end
|
42
|
+
|
43
|
+
EasyPost::Util.convert_to_easypost_object(response['address'], api_key)
|
41
44
|
end
|
42
45
|
|
43
|
-
|
46
|
+
# Verify an Address.
|
47
|
+
def verify
|
44
48
|
begin
|
45
|
-
response = EasyPost.make_request(:get, url
|
46
|
-
rescue
|
47
|
-
raise EasyPost::Error.new(
|
49
|
+
response = EasyPost.make_request(:get, "#{url}/verify", @api_key)
|
50
|
+
rescue StandardError
|
51
|
+
raise EasyPost::Error.new('Unable to verify address.')
|
48
52
|
end
|
49
53
|
|
50
|
-
|
51
|
-
return EasyPost::Util::convert_to_easypost_object(response["address"], api_key)
|
52
|
-
else
|
53
|
-
raise EasyPost::Error.new("Unable to verify address.")
|
54
|
-
end
|
54
|
+
raise EasyPost::Error.new('Unable to verify address.') unless response.key?('address')
|
55
55
|
|
56
|
-
|
56
|
+
EasyPost::Util.convert_to_easypost_object(response['address'], api_key)
|
57
57
|
end
|
58
58
|
end
|
data/lib/easypost/api_key.rb
CHANGED
data/lib/easypost/batch.rb
CHANGED
@@ -1,49 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# The Batch object allows you to perform operations on multiple Shipments at once.
|
1
4
|
class EasyPost::Batch < EasyPost::Resource
|
2
|
-
|
5
|
+
# Create and buy a batch in one call.
|
6
|
+
def self.create_and_buy(params = {}, api_key = nil)
|
3
7
|
wrapped_params = {}
|
4
|
-
wrapped_params[
|
5
|
-
response = EasyPost.make_request(:post, url
|
8
|
+
wrapped_params[class_name.to_sym] = params
|
9
|
+
response = EasyPost.make_request(:post, "#{url}/create_and_buy", api_key, wrapped_params)
|
6
10
|
|
7
|
-
|
11
|
+
EasyPost::Util.convert_to_easypost_object(response, api_key)
|
8
12
|
end
|
9
13
|
|
10
|
-
|
11
|
-
|
12
|
-
|
14
|
+
# Buy a Batch.
|
15
|
+
def buy(params = {})
|
16
|
+
response = EasyPost.make_request(:post, "#{url}/buy", @api_key, params)
|
17
|
+
refresh_from(response, @api_key)
|
13
18
|
|
14
|
-
|
19
|
+
self
|
15
20
|
end
|
16
21
|
|
17
|
-
|
18
|
-
|
19
|
-
|
22
|
+
# Convert the label format of a Batch.
|
23
|
+
def label(params = {})
|
24
|
+
response = EasyPost.make_request(:post, "#{url}/label", @api_key, params)
|
25
|
+
refresh_from(response, @api_key)
|
20
26
|
|
21
|
-
|
27
|
+
self
|
22
28
|
end
|
23
29
|
|
24
|
-
|
25
|
-
|
26
|
-
|
30
|
+
# Remove Shipments from a Batch.
|
31
|
+
def remove_shipments(params = {})
|
32
|
+
response = EasyPost.make_request(:post, "#{url}/remove_shipments", @api_key, params)
|
33
|
+
refresh_from(response, @api_key)
|
27
34
|
|
28
|
-
|
35
|
+
self
|
29
36
|
end
|
30
37
|
|
31
|
-
|
32
|
-
|
33
|
-
|
38
|
+
# Add Shipments to a Batch.
|
39
|
+
def add_shipments(params = {})
|
40
|
+
response = EasyPost.make_request(:post, "#{url}/add_shipments", @api_key, params)
|
41
|
+
refresh_from(response, @api_key)
|
34
42
|
|
35
|
-
|
43
|
+
self
|
36
44
|
end
|
37
45
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
return response
|
42
|
-
end
|
43
|
-
|
44
|
-
def create_scan_form(params={})
|
45
|
-
response = EasyPost.make_request(:post, url + '/scan_form', @api_key, params)
|
46
|
-
|
47
|
-
return response
|
46
|
+
# Create a ScanForm for a Batch.
|
47
|
+
def create_scan_form(params = {})
|
48
|
+
EasyPost.make_request(:post, "#{url}/scan_form", @api_key, params)
|
48
49
|
end
|
49
50
|
end
|
data/lib/easypost/brand.rb
CHANGED
@@ -1,4 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# The Brand object allows you to customize the publicly-accessible html page that shows tracking details for every EasyPost tracker.
|
1
4
|
class EasyPost::Brand < EasyPost::Resource
|
5
|
+
# The url of the Brand object.
|
2
6
|
def url
|
3
7
|
if user_id.nil? || user_id.empty?
|
4
8
|
raise EasyPost::Error, "Missing user_id: #{self.class} instance is missing user_id"
|
@@ -1,4 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# A CarrierAccount encapsulates your credentials with the carrier.
|
1
4
|
class EasyPost::CarrierAccount < EasyPost::Resource
|
5
|
+
# Retrieve a list of available CarrierAccount types for the authenticated User.
|
2
6
|
def self.types
|
3
7
|
EasyPost::CarrierType.all
|
4
8
|
end
|
@@ -1,5 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# CustomsInfo objects contain CustomsItem objects and all necessary information for the generation of customs forms required for international shipping.
|
1
4
|
class EasyPost::CustomsInfo < EasyPost::Resource
|
2
|
-
|
5
|
+
# Retrieve a list of CustomsInfo objects
|
6
|
+
def self.all
|
3
7
|
raise NotImplementedError.new('CustomsInfo.all not implemented.')
|
4
8
|
end
|
5
9
|
end
|
@@ -1,5 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# A CustomsItem object describes goods for international shipment and should be created then included in a CustomsInfo object.
|
1
4
|
class EasyPost::CustomsItem < EasyPost::Resource
|
2
|
-
|
5
|
+
# Retrieve a list of CustomsItem objects
|
6
|
+
def self.all
|
3
7
|
raise NotImplementedError.new('CustomsItem.all not implemented.')
|
4
8
|
end
|
5
9
|
end
|
data/lib/easypost/error.rb
CHANGED
@@ -1,15 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# EasyPost Error object.
|
1
4
|
class EasyPost::Error < StandardError
|
2
|
-
attr_reader :message
|
3
|
-
attr_reader :status
|
4
|
-
attr_reader :http_status # deprecated
|
5
|
-
attr_reader :http_body
|
6
|
-
attr_reader :code
|
7
|
-
attr_reader :errors
|
5
|
+
attr_reader :message, :status, :http_body, :code, :errors
|
8
6
|
|
7
|
+
# Initialize a new EasyPost Error
|
9
8
|
def initialize(message = nil, status = nil, code = nil, errors = nil, http_body = nil)
|
10
9
|
@message = message
|
11
10
|
@status = status
|
12
|
-
@http_status = status # deprecated
|
13
11
|
@code = code
|
14
12
|
@errors = errors
|
15
13
|
@http_body = http_body
|
@@ -17,10 +15,12 @@ class EasyPost::Error < StandardError
|
|
17
15
|
super(message)
|
18
16
|
end
|
19
17
|
|
18
|
+
# Convert an error to a string.
|
20
19
|
def to_s
|
21
20
|
"#{code} (#{status}): #{message} #{errors}".strip
|
22
21
|
end
|
23
22
|
|
23
|
+
# Compare error properties.
|
24
24
|
def ==(other)
|
25
25
|
other.is_a?(EasyPost::Error) &&
|
26
26
|
message == other.message &&
|
data/lib/easypost/event.rb
CHANGED
@@ -1,7 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'json'
|
2
4
|
|
5
|
+
# Webhook Events are triggered by changes in objects you've created via the API.
|
3
6
|
class EasyPost::Event < EasyPost::Resource
|
7
|
+
# Converts a raw webhook event into an EasyPost object.
|
4
8
|
def self.receive(values)
|
5
|
-
|
9
|
+
EasyPost::Util.convert_to_easypost_object(JSON.parse(values), nil)
|
6
10
|
end
|
7
11
|
end
|
data/lib/easypost/insurance.rb
CHANGED
@@ -1,2 +1,6 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# An Insurance object represents insurance for packages purchased both via the EasyPost API as well
|
4
|
+
# as shipments purchased through third parties and later registered with EasyPost.
|
1
5
|
class EasyPost::Insurance < EasyPost::Resource
|
2
6
|
end
|
data/lib/easypost/object.rb
CHANGED
@@ -1,12 +1,17 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'set'
|
4
|
+
|
5
|
+
# The EasyPostObject is extended by the EasyPost Resource object.
|
3
6
|
class EasyPost::EasyPostObject
|
4
7
|
include Enumerable
|
5
8
|
|
6
9
|
attr_accessor :parent, :name, :api_key, :unsaved_values
|
7
|
-
@@immutable_values = Set.new([:api_key, :id])
|
8
10
|
|
9
|
-
|
11
|
+
@@immutable_values = Set.new([:api_key, :id]) # rubocop:disable Style/ClassVars
|
12
|
+
|
13
|
+
# Initialize an EasyPostObject.
|
14
|
+
def initialize(id = nil, api_key = nil, parent = nil, name = nil)
|
10
15
|
@api_key = api_key
|
11
16
|
@values = {}
|
12
17
|
@unsaved_values = Set.new
|
@@ -16,22 +21,26 @@ class EasyPost::EasyPostObject
|
|
16
21
|
self.id = id if id
|
17
22
|
end
|
18
23
|
|
19
|
-
|
20
|
-
|
24
|
+
# Construct an object from values.
|
25
|
+
def self.construct_from(values, api_key = nil, parent = nil, name = nil)
|
26
|
+
obj = new(values[:id], api_key, parent, name)
|
21
27
|
obj.refresh_from(values, api_key)
|
22
28
|
obj
|
23
29
|
end
|
24
30
|
|
25
|
-
|
31
|
+
# Convert to a string.
|
32
|
+
def to_s(*_args)
|
26
33
|
JSON.dump(@values)
|
27
34
|
end
|
28
35
|
|
36
|
+
# Inspect JSON.
|
29
37
|
def inspect
|
30
|
-
id_string =
|
38
|
+
id_string = respond_to?(:id) && !id.nil? ? " id=#{id}" : ''
|
31
39
|
"#<#{self.class}:#{id_string}> JSON: " + to_json
|
32
40
|
end
|
33
41
|
|
34
|
-
|
42
|
+
# Refresh an object from the API.
|
43
|
+
def refresh_from(values, api_key)
|
35
44
|
@api_key = api_key
|
36
45
|
|
37
46
|
added = Set.new(values.keys - @values.keys)
|
@@ -40,6 +49,9 @@ class EasyPost::EasyPostObject
|
|
40
49
|
add_accessors(added)
|
41
50
|
end
|
42
51
|
|
52
|
+
# IDs don't change, do not update it
|
53
|
+
@values.delete(:id)
|
54
|
+
|
43
55
|
values.each do |k, v|
|
44
56
|
@values[k.to_s] = EasyPost::Util.convert_to_easypost_object(v, api_key, self, k)
|
45
57
|
@transient_values.delete(k)
|
@@ -47,55 +59,67 @@ class EasyPost::EasyPostObject
|
|
47
59
|
end
|
48
60
|
end
|
49
61
|
|
50
|
-
|
51
|
-
|
62
|
+
# Get element of an array.
|
63
|
+
def [](key)
|
64
|
+
@values[key.to_s]
|
52
65
|
end
|
53
66
|
|
54
|
-
|
55
|
-
|
67
|
+
# Set the element of an array.
|
68
|
+
def []=(key, value)
|
69
|
+
send(:"#{key}=", value)
|
56
70
|
end
|
57
71
|
|
72
|
+
# Keys of an object.
|
58
73
|
def keys
|
59
74
|
@values.keys
|
60
75
|
end
|
61
76
|
|
77
|
+
# Values of an object.
|
62
78
|
def values
|
63
79
|
@values.values
|
64
80
|
end
|
65
81
|
|
66
|
-
|
82
|
+
# Make values JSON.
|
83
|
+
def to_json(_options = {})
|
67
84
|
JSON.dump(@values)
|
68
85
|
end
|
69
86
|
|
70
|
-
|
87
|
+
# Get values as JSON.
|
88
|
+
def as_json(_options = {})
|
71
89
|
@values.as_json
|
72
90
|
end
|
73
91
|
|
92
|
+
# Make values a hash.
|
74
93
|
def to_hash
|
75
94
|
@values
|
76
95
|
end
|
77
96
|
|
97
|
+
# Deconstruct the keys of an object.
|
78
98
|
def deconstruct_keys(_keys)
|
79
99
|
@values.transform_keys(&:to_sym)
|
80
100
|
end
|
81
101
|
|
102
|
+
# Get each element of values.
|
82
103
|
def each(&blk)
|
83
104
|
@values.each(&blk)
|
84
105
|
end
|
85
106
|
|
107
|
+
# Set the ID of an object.
|
86
108
|
def id=(id)
|
87
109
|
@values[:id] = id
|
88
110
|
end
|
89
111
|
|
112
|
+
# Get the ID of an object.
|
90
113
|
def id
|
91
114
|
@values[:id]
|
92
115
|
end
|
93
116
|
|
94
117
|
protected
|
95
118
|
|
119
|
+
# Flatten the unsaved values of an object.
|
96
120
|
def flatten_unsaved
|
97
121
|
values = {}
|
98
|
-
|
122
|
+
@unsaved_values.each do |key|
|
99
123
|
value = @values[key]
|
100
124
|
|
101
125
|
values[key] = value
|
@@ -105,28 +129,20 @@ class EasyPost::EasyPostObject
|
|
105
129
|
end
|
106
130
|
end
|
107
131
|
|
108
|
-
|
132
|
+
values
|
109
133
|
end
|
110
134
|
|
135
|
+
# The metaclass of an object.
|
111
136
|
def metaclass
|
112
137
|
class << self; self; end
|
113
138
|
end
|
114
139
|
|
115
|
-
|
116
|
-
metaclass.instance_eval do
|
117
|
-
keys.each do |k|
|
118
|
-
next if @@immutable_values.include?(k)
|
119
|
-
k_eq = :"#{k}="
|
120
|
-
remove_method(k) if method_defined?(k)
|
121
|
-
remove_method(k_eq) if method_defined?(k_eq)
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
140
|
+
# Add accessors of an object.
|
126
141
|
def add_accessors(keys)
|
127
142
|
metaclass.instance_eval do
|
128
143
|
keys.each do |k|
|
129
144
|
next if @@immutable_values.include?(k)
|
145
|
+
|
130
146
|
k = k.to_s
|
131
147
|
k_eq = :"#{k}="
|
132
148
|
define_method(k) { @values[k] }
|
@@ -135,7 +151,7 @@ class EasyPost::EasyPostObject
|
|
135
151
|
@unsaved_values.add(k)
|
136
152
|
|
137
153
|
cur = self
|
138
|
-
cur_parent =
|
154
|
+
cur_parent = parent
|
139
155
|
while cur_parent
|
140
156
|
if cur.name
|
141
157
|
cur_parent.unsaved_values.add(cur.name)
|
data/lib/easypost/order.rb
CHANGED
@@ -1,13 +1,17 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
# The Order object represents a collection of packages and can be used for Multi-Piece Shipments.
|
4
|
+
class EasyPost::Order < EasyPost::Resource
|
5
|
+
# Get the rates of an Order.
|
6
|
+
def get_rates(params = {})
|
7
|
+
response = EasyPost.make_request(:get, "#{url}/rates", @api_key, params)
|
8
|
+
refresh_from(response, @api_key)
|
6
9
|
|
7
|
-
|
10
|
+
self
|
8
11
|
end
|
9
12
|
|
10
|
-
|
13
|
+
# Buy an Order.
|
14
|
+
def buy(params = {})
|
11
15
|
if params.instance_of?(EasyPost::Rate)
|
12
16
|
temp = params.clone
|
13
17
|
params = {}
|
@@ -15,14 +19,14 @@ class EasyPost::Order < EasyPost::Resource
|
|
15
19
|
params[:service] = temp.service
|
16
20
|
end
|
17
21
|
|
18
|
-
response = EasyPost.make_request(:post, url
|
19
|
-
|
22
|
+
response = EasyPost.make_request(:post, "#{url}/buy", @api_key, params)
|
23
|
+
refresh_from(response, @api_key)
|
20
24
|
|
21
|
-
|
25
|
+
self
|
22
26
|
end
|
23
27
|
|
24
|
-
|
28
|
+
# Retrieve a list of Order objects.
|
29
|
+
def self.all
|
25
30
|
raise NotImplementedError.new('Order.all not implemented.')
|
26
31
|
end
|
27
|
-
|
28
32
|
end
|
data/lib/easypost/parcel.rb
CHANGED
@@ -1,2 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Parcel objects represent the physical container being shipped.
|
1
4
|
class EasyPost::Parcel < EasyPost::Resource
|
5
|
+
# Retrieving all Parcel objects is not supported.
|
6
|
+
def self.all
|
7
|
+
raise NotImplementedError.new('Parcel.all not implemented.')
|
8
|
+
end
|
2
9
|
end
|
data/lib/easypost/pickup.rb
CHANGED
@@ -1,5 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# The Pickup object allows you to schedule a pickup from your carrier from your customer's residence or place of business.
|
1
4
|
class EasyPost::Pickup < EasyPost::Resource
|
2
|
-
|
5
|
+
# Buy a Pickup.
|
6
|
+
def buy(params = {})
|
3
7
|
if params.instance_of?(EasyPost::PickupRate)
|
4
8
|
temp = params.clone
|
5
9
|
params = {}
|
@@ -7,20 +11,22 @@ class EasyPost::Pickup < EasyPost::Resource
|
|
7
11
|
params[:service] = temp.service
|
8
12
|
end
|
9
13
|
|
10
|
-
response = EasyPost.make_request(:post, url
|
11
|
-
|
14
|
+
response = EasyPost.make_request(:post, "#{url}/buy", @api_key, params)
|
15
|
+
refresh_from(response, @api_key)
|
12
16
|
|
13
|
-
|
17
|
+
self
|
14
18
|
end
|
15
19
|
|
16
|
-
|
17
|
-
|
18
|
-
|
20
|
+
# Cancel a Pickup.
|
21
|
+
def cancel(params = {})
|
22
|
+
response = EasyPost.make_request(:post, "#{url}/cancel", @api_key, params)
|
23
|
+
refresh_from(response, @api_key)
|
19
24
|
|
20
|
-
|
25
|
+
self
|
21
26
|
end
|
22
27
|
|
23
|
-
|
28
|
+
# Retrieve a list of all Pickup objects.
|
29
|
+
def self.all
|
24
30
|
raise NotImplementedError.new('Pickup.all not implemented.')
|
25
31
|
end
|
26
32
|
end
|
data/lib/easypost/pickup_rate.rb
CHANGED
data/lib/easypost/rate.rb
CHANGED
@@ -1,2 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# A Rate object contains all the details about the rate of a Shipment.
|
1
4
|
class EasyPost::Rate < EasyPost::Resource
|
5
|
+
# Retrieving all Rate objects is not supported.
|
6
|
+
def self.all
|
7
|
+
raise NotImplementedError.new('Rate.all not implemented.')
|
8
|
+
end
|
2
9
|
end
|