easypost 3.4.0 → 4.1.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 +2 -0
- data/.rubocop.yml +5 -0
- data/CHANGELOG.md +149 -138
- data/Gemfile +2 -0
- data/README.md +51 -8
- 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 +13 -0
- data/lib/easypost/carrier_account.rb +4 -0
- data/lib/easypost/carrier_type.rb +3 -0
- data/lib/easypost/connection.rb +67 -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 +55 -25
- data/lib/easypost/scan_form.rb +8 -3
- data/lib/easypost/shipment.rb +47 -51
- data/lib/easypost/tax_identifier.rb +6 -0
- data/lib/easypost/tracker.rb +9 -4
- data/lib/easypost/user.rb +31 -10
- data/lib/easypost/util.rb +22 -17
- data/lib/easypost/version.rb +3 -1
- data/lib/easypost/webhook.rb +18 -12
- data/lib/easypost.rb +99 -107
- metadata +80 -22
- data/lib/easypost/print_job.rb +0 -2
- data/lib/easypost/printer.rb +0 -24
data/easycop.yml
ADDED
@@ -0,0 +1,180 @@
|
|
1
|
+
# This file was generated by
|
2
|
+
# `rake easycop:init`
|
3
|
+
# on 2019-12-16 19:20:52 +0000 using EasyCop version 0.1.
|
4
|
+
---
|
5
|
+
require:
|
6
|
+
- rubocop-rspec
|
7
|
+
AllCops:
|
8
|
+
TargetRubyVersion: 2.5
|
9
|
+
NewCops: disable
|
10
|
+
Layout/BlockAlignment:
|
11
|
+
Enabled: true
|
12
|
+
EnforcedStyleAlignWith: start_of_block
|
13
|
+
Layout/DotPosition:
|
14
|
+
Enabled: true
|
15
|
+
AutoCorrect: true
|
16
|
+
EnforcedStyle: leading
|
17
|
+
Layout/EmptyLineAfterGuardClause:
|
18
|
+
Enabled: true
|
19
|
+
AutoCorrect: true
|
20
|
+
Layout/EmptyLinesAroundArguments:
|
21
|
+
Enabled: true
|
22
|
+
AutoCorrect: true
|
23
|
+
Layout/EmptyLinesAroundExceptionHandlingKeywords:
|
24
|
+
Enabled: true
|
25
|
+
AutoCorrect: true
|
26
|
+
Layout/EndAlignment:
|
27
|
+
Enabled: true
|
28
|
+
EnforcedStyleAlignWith: keyword
|
29
|
+
AutoCorrect: true
|
30
|
+
Layout/MultilineMethodCallBraceLayout:
|
31
|
+
EnforcedStyle: new_line
|
32
|
+
Layout/MultilineHashBraceLayout:
|
33
|
+
EnforcedStyle: new_line
|
34
|
+
Layout/MultilineArrayBraceLayout:
|
35
|
+
EnforcedStyle: new_line
|
36
|
+
Layout/FirstArrayElementLineBreak:
|
37
|
+
Enabled: true
|
38
|
+
Layout/FirstHashElementLineBreak:
|
39
|
+
Enabled: true
|
40
|
+
Layout/FirstMethodArgumentLineBreak:
|
41
|
+
Enabled: true
|
42
|
+
Layout/LineLength:
|
43
|
+
Max: 120
|
44
|
+
IgnoredPatterns:
|
45
|
+
- "(\\A|\\s)#"
|
46
|
+
Layout/LineEndStringConcatenationIndentation: # new in 1.18
|
47
|
+
Enabled: true
|
48
|
+
Layout/SpaceBeforeBrackets: # new in 1.7
|
49
|
+
Enabled: true
|
50
|
+
RSpec/SharedExamples:
|
51
|
+
Enabled: false
|
52
|
+
RSpec/NestedGroups:
|
53
|
+
Enabled: false
|
54
|
+
RSpec/ExampleLength:
|
55
|
+
Enabled: false
|
56
|
+
RSpec/ImplicitSubject:
|
57
|
+
Enabled: false
|
58
|
+
RSpec/MultipleExpectations:
|
59
|
+
Enabled: false
|
60
|
+
RSpec/MultipleMemoizedHelpers:
|
61
|
+
Enabled: false
|
62
|
+
RSpec/IdenticalEqualityAssertion: # new in 2.4
|
63
|
+
Enabled: true
|
64
|
+
Style/BlockDelimiters:
|
65
|
+
Enabled: true
|
66
|
+
EnforcedStyle: braces_for_chaining
|
67
|
+
Style/ClassAndModuleChildren:
|
68
|
+
Enabled: true
|
69
|
+
EnforcedStyle: compact
|
70
|
+
Style/Documentation:
|
71
|
+
Enabled: false
|
72
|
+
Style/MethodCalledOnDoEndBlock:
|
73
|
+
Severity: warning
|
74
|
+
Enabled: true
|
75
|
+
Style/RaiseArgs:
|
76
|
+
Enabled: false
|
77
|
+
Style/RescueStandardError:
|
78
|
+
Enabled: true
|
79
|
+
Style/MultilineBlockChain:
|
80
|
+
Enabled: false
|
81
|
+
Style/TrailingCommaInHashLiteral:
|
82
|
+
EnforcedStyleForMultiline: consistent_comma
|
83
|
+
Style/TrailingCommaInArguments:
|
84
|
+
EnforcedStyleForMultiline: consistent_comma
|
85
|
+
Style/TrailingCommaInArrayLiteral:
|
86
|
+
EnforcedStyleForMultiline: consistent_comma
|
87
|
+
Style/SymbolArray:
|
88
|
+
Enabled: false
|
89
|
+
Style/IfUnlessModifier:
|
90
|
+
Enabled: false
|
91
|
+
Metrics/BlockLength:
|
92
|
+
Enabled: false
|
93
|
+
Metrics/ClassLength:
|
94
|
+
Enabled: false
|
95
|
+
Metrics/CyclomaticComplexity:
|
96
|
+
Enabled: false
|
97
|
+
Metrics/PerceivedComplexity:
|
98
|
+
Enabled: false
|
99
|
+
Metrics/ModuleLength:
|
100
|
+
Enabled: false
|
101
|
+
Metrics/MethodLength:
|
102
|
+
Enabled: false
|
103
|
+
Metrics/ParameterLists:
|
104
|
+
Enabled: false
|
105
|
+
Metrics/AbcSize:
|
106
|
+
Enabled: false
|
107
|
+
Gemspec/DateAssignment: # new in 1.10
|
108
|
+
Enabled: true
|
109
|
+
Lint/AmbiguousAssignment: # new in 1.7
|
110
|
+
Enabled: true
|
111
|
+
Lint/AmbiguousRange: # new in 1.19
|
112
|
+
Enabled: true
|
113
|
+
Lint/DeprecatedConstants: # new in 1.8
|
114
|
+
Enabled: true
|
115
|
+
Lint/DuplicateBranch: # new in 1.3
|
116
|
+
Enabled: true
|
117
|
+
Lint/DuplicateRegexpCharacterClassElement: # new in 1.1
|
118
|
+
Enabled: true
|
119
|
+
Lint/EmptyBlock: # new in 1.1
|
120
|
+
Enabled: true
|
121
|
+
Lint/EmptyClass: # new in 1.3
|
122
|
+
Enabled: true
|
123
|
+
Lint/EmptyInPattern: # new in 1.16
|
124
|
+
Enabled: true
|
125
|
+
Lint/LambdaWithoutLiteralBlock: # new in 1.8
|
126
|
+
Enabled: true
|
127
|
+
Lint/NoReturnInBeginEndBlocks: # new in 1.2
|
128
|
+
Enabled: true
|
129
|
+
Lint/NumberedParameterAssignment: # new in 1.9
|
130
|
+
Enabled: true
|
131
|
+
Lint/OrAssignmentToConstant: # new in 1.9
|
132
|
+
Enabled: true
|
133
|
+
Lint/RedundantDirGlobSort: # new in 1.8
|
134
|
+
Enabled: true
|
135
|
+
Lint/SymbolConversion: # new in 1.9
|
136
|
+
Enabled: true
|
137
|
+
Lint/ToEnumArguments: # new in 1.1
|
138
|
+
Enabled: true
|
139
|
+
Lint/TripleQuotes: # new in 1.9
|
140
|
+
Enabled: true
|
141
|
+
Lint/UnexpectedBlockArity: # new in 1.5
|
142
|
+
Enabled: true
|
143
|
+
Lint/UnmodifiedReduceAccumulator: # new in 1.1
|
144
|
+
Enabled: true
|
145
|
+
Naming/InclusiveLanguage: # new in 1.18
|
146
|
+
Enabled: true
|
147
|
+
Style/ArgumentsForwarding: # new in 1.1
|
148
|
+
Enabled: true
|
149
|
+
Style/CollectionCompact: # new in 1.2
|
150
|
+
Enabled: true
|
151
|
+
Style/DocumentDynamicEvalDefinition: # new in 1.1
|
152
|
+
Enabled: true
|
153
|
+
Style/EndlessMethod: # new in 1.8
|
154
|
+
Enabled: true
|
155
|
+
Style/HashConversion: # new in 1.10
|
156
|
+
Enabled: true
|
157
|
+
Style/HashExcept: # new in 1.7
|
158
|
+
Enabled: true
|
159
|
+
Style/IfWithBooleanLiteralBranches: # new in 1.9
|
160
|
+
Enabled: true
|
161
|
+
Style/InPatternThen: # new in 1.16
|
162
|
+
Enabled: true
|
163
|
+
Style/MultilineInPatternThen: # new in 1.16
|
164
|
+
Enabled: true
|
165
|
+
Style/NegatedIfElseCondition: # new in 1.2
|
166
|
+
Enabled: true
|
167
|
+
Style/NilLambda: # new in 1.3
|
168
|
+
Enabled: true
|
169
|
+
Style/QuotedSymbols: # new in 1.16
|
170
|
+
Enabled: true
|
171
|
+
Style/RedundantArgument: # new in 1.4
|
172
|
+
Enabled: true
|
173
|
+
Style/RedundantSelfAssignmentBranch: # new in 1.19
|
174
|
+
Enabled: true
|
175
|
+
Style/StringChars: # new in 1.12
|
176
|
+
Enabled: true
|
177
|
+
Style/SwapValues: # new in 1.1
|
178
|
+
Enabled: true
|
179
|
+
RSpec/Rails/AvoidSetupHook: # new in 2.4
|
180
|
+
Enabled: true
|
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
|
@@ -0,0 +1,13 @@
|
|
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.
|
4
|
+
class EasyPost::Brand < EasyPost::Resource
|
5
|
+
# The url of the Brand object.
|
6
|
+
def url
|
7
|
+
if user_id.nil? || user_id.empty?
|
8
|
+
raise EasyPost::Error, "Missing user_id: #{self.class} instance is missing user_id"
|
9
|
+
end
|
10
|
+
|
11
|
+
"#{::EasyPost::User.url}/#{CGI.escape(user_id)}/brand"
|
12
|
+
end
|
13
|
+
end
|
@@ -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
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
EasyPost::Connection = Struct.new(:uri, :config, keyword_init: true) do
|
4
|
+
attr_reader :connection
|
5
|
+
|
6
|
+
def initialize(uri:, config:)
|
7
|
+
super
|
8
|
+
|
9
|
+
@connection =
|
10
|
+
if config[:proxy]
|
11
|
+
proxy_uri = URI(config[:proxy])
|
12
|
+
Net::HTTP.new(
|
13
|
+
uri.host,
|
14
|
+
uri.port,
|
15
|
+
proxy_uri.host,
|
16
|
+
proxy_uri.port,
|
17
|
+
proxy_uri.user,
|
18
|
+
proxy_uri.password,
|
19
|
+
)
|
20
|
+
else
|
21
|
+
Net::HTTP.new(uri.host, uri.port)
|
22
|
+
end
|
23
|
+
|
24
|
+
connection.use_ssl = true
|
25
|
+
|
26
|
+
config.each do |name, value|
|
27
|
+
# Discrepancies between RestClient and Net::HTTP.
|
28
|
+
case name
|
29
|
+
when :verify_ssl
|
30
|
+
name = :verify_mode
|
31
|
+
when :timeout
|
32
|
+
name = :read_timeout
|
33
|
+
end
|
34
|
+
|
35
|
+
# Handled in the creation of the client.
|
36
|
+
if name == :proxy
|
37
|
+
next
|
38
|
+
end
|
39
|
+
|
40
|
+
connection.public_send("#{name}=", value)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# Make an HTTP request with Ruby's {Net::HTTP}
|
45
|
+
#
|
46
|
+
# @param method [Symbol] the HTTP Verb (get, method, put, post, etc.)
|
47
|
+
# @param path [String] URI path of the resource
|
48
|
+
# @param requested_api_key [String] ({EasyPost.api_key}) key set Authorization header.
|
49
|
+
# @param body [String] (nil) body of the request
|
50
|
+
# @raise [EasyPost::Error] if the response has a non-2xx status code
|
51
|
+
# @return [Hash] JSON object parsed from the response body
|
52
|
+
def call(method, path, api_key = nil, body = nil)
|
53
|
+
request = Net::HTTP.const_get(method.capitalize).new(path)
|
54
|
+
request.body = JSON.dump(EasyPost::Util.objects_to_ids(body)) if body
|
55
|
+
|
56
|
+
EasyPost.default_headers.each_pair { |h, v| request[h] = v }
|
57
|
+
request['Authorization'] = EasyPost.authorization(api_key) if api_key
|
58
|
+
|
59
|
+
response = connection.request(request)
|
60
|
+
|
61
|
+
EasyPost.parse_response(
|
62
|
+
status: response.code.to_i,
|
63
|
+
body: response.body,
|
64
|
+
json: response['Content-Type'].start_with?('application/json'),
|
65
|
+
)
|
66
|
+
end
|
67
|
+
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
|