easypost 3.5.1 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +19 -5
- data/.gitignore +1 -0
- data/.rubocop.yml +5 -0
- data/CHANGELOG.md +88 -48
- 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 -40
- data/lib/easypost/version.rb +3 -1
- data/lib/easypost/webhook.rb +18 -12
- data/lib/easypost.rb +59 -55
- metadata +74 -19
- data/lib/easypost/print_job.rb +0 -2
- data/lib/easypost/printer.rb +0 -24
data/lib/easypost.rb
CHANGED
@@ -1,63 +1,66 @@
|
|
1
|
-
|
2
|
-
require "cgi"
|
3
|
-
require "net/http"
|
1
|
+
# frozen_string_literal: true
|
4
2
|
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require "easypost/resource"
|
9
|
-
require "easypost/error"
|
10
|
-
|
11
|
-
# Resources
|
12
|
-
require "easypost/address"
|
13
|
-
require "easypost/api_key"
|
14
|
-
require "easypost/batch"
|
15
|
-
require "easypost/brand"
|
16
|
-
require "easypost/carrier_account"
|
17
|
-
require "easypost/carrier_type"
|
18
|
-
require "easypost/customs_info"
|
19
|
-
require "easypost/customs_item"
|
20
|
-
require "easypost/event"
|
21
|
-
require "easypost/insurance"
|
22
|
-
require "easypost/order"
|
23
|
-
require "easypost/parcel"
|
24
|
-
require "easypost/pickup_rate"
|
25
|
-
require "easypost/pickup"
|
26
|
-
require "easypost/postage_label"
|
27
|
-
require "easypost/print_job"
|
28
|
-
require "easypost/printer"
|
29
|
-
require "easypost/rate"
|
30
|
-
require "easypost/refund"
|
31
|
-
require "easypost/report"
|
32
|
-
require "easypost/scan_form"
|
33
|
-
require "easypost/shipment"
|
34
|
-
require "easypost/tax_identifier"
|
35
|
-
require "easypost/tracker"
|
36
|
-
require "easypost/user"
|
37
|
-
require "easypost/webhook"
|
3
|
+
require 'base64'
|
4
|
+
require 'cgi'
|
5
|
+
require 'net/http'
|
38
6
|
|
7
|
+
require 'easypost/version'
|
39
8
|
require 'easypost/util'
|
9
|
+
require 'easypost/object'
|
10
|
+
require 'easypost/resource'
|
11
|
+
require 'easypost/error'
|
12
|
+
|
13
|
+
# Resources
|
14
|
+
require 'easypost/address'
|
15
|
+
require 'easypost/api_key'
|
16
|
+
require 'easypost/batch'
|
17
|
+
require 'easypost/brand'
|
18
|
+
require 'easypost/carrier_account'
|
19
|
+
require 'easypost/carrier_type'
|
20
|
+
require 'easypost/customs_info'
|
21
|
+
require 'easypost/customs_item'
|
22
|
+
require 'easypost/event'
|
23
|
+
require 'easypost/insurance'
|
24
|
+
require 'easypost/order'
|
25
|
+
require 'easypost/parcel'
|
26
|
+
require 'easypost/pickup_rate'
|
27
|
+
require 'easypost/pickup'
|
28
|
+
require 'easypost/postage_label'
|
29
|
+
require 'easypost/rate'
|
30
|
+
require 'easypost/refund'
|
31
|
+
require 'easypost/report'
|
32
|
+
require 'easypost/scan_form'
|
33
|
+
require 'easypost/shipment'
|
34
|
+
require 'easypost/tax_identifier'
|
35
|
+
require 'easypost/tracker'
|
36
|
+
require 'easypost/user'
|
37
|
+
require 'easypost/webhook'
|
40
38
|
|
41
39
|
module EasyPost
|
42
40
|
@api_key = nil
|
43
|
-
@api_base =
|
41
|
+
@api_base = 'https://api.easypost.com'
|
44
42
|
|
43
|
+
# Set the ApiKey.
|
45
44
|
def self.api_key=(api_key)
|
46
45
|
@api_key = api_key
|
47
46
|
end
|
48
47
|
|
48
|
+
# Get the ApiKey.
|
49
49
|
def self.api_key
|
50
50
|
@api_key
|
51
51
|
end
|
52
52
|
|
53
|
+
# Set the API base.
|
53
54
|
def self.api_base=(api_base)
|
54
55
|
@api_base = api_base
|
55
56
|
end
|
56
57
|
|
58
|
+
# Get the API base.
|
57
59
|
def self.api_base
|
58
60
|
@api_base
|
59
61
|
end
|
60
62
|
|
63
|
+
# Reset the HTTP config.
|
61
64
|
def self.reset_http_config
|
62
65
|
@http_config = {
|
63
66
|
timeout: 60,
|
@@ -66,23 +69,26 @@ module EasyPost
|
|
66
69
|
}
|
67
70
|
|
68
71
|
ruby_version = Gem::Version.new(RUBY_VERSION)
|
69
|
-
if ruby_version >= Gem::Version.new(
|
72
|
+
if ruby_version >= Gem::Version.new('2.5.0')
|
70
73
|
@http_config[:min_version] = OpenSSL::SSL::TLS1_2_VERSION
|
71
74
|
else
|
72
|
-
@http_config[:ssl_version] = :TLSv1_2
|
75
|
+
@http_config[:ssl_version] = :TLSv1_2 # rubocop:disable Naming/VariableNumber
|
73
76
|
end
|
74
77
|
|
75
78
|
@http_config
|
76
79
|
end
|
77
80
|
|
81
|
+
# Get the HTTP config.
|
78
82
|
def self.http_config
|
79
83
|
@http_config ||= reset_http_config
|
80
84
|
end
|
81
85
|
|
86
|
+
# Set the HTTP config.
|
82
87
|
def self.http_config=(http_config_params)
|
83
88
|
http_config.merge!(http_config_params)
|
84
89
|
end
|
85
90
|
|
91
|
+
# Create an EasyPost Client.
|
86
92
|
def self.make_client(uri)
|
87
93
|
client = if http_config[:proxy]
|
88
94
|
proxy_uri = URI(http_config[:proxy])
|
@@ -92,7 +98,7 @@ module EasyPost
|
|
92
98
|
proxy_uri.host,
|
93
99
|
proxy_uri.port,
|
94
100
|
proxy_uri.user,
|
95
|
-
proxy_uri.password
|
101
|
+
proxy_uri.password,
|
96
102
|
)
|
97
103
|
else
|
98
104
|
Net::HTTP.new(uri.host, uri.port)
|
@@ -101,9 +107,10 @@ module EasyPost
|
|
101
107
|
|
102
108
|
http_config.each do |name, value|
|
103
109
|
# Discrepancies between RestClient and Net::HTTP.
|
104
|
-
|
110
|
+
case name
|
111
|
+
when :verify_ssl
|
105
112
|
name = :verify_mode
|
106
|
-
|
113
|
+
when :timeout
|
107
114
|
name = :read_timeout
|
108
115
|
end
|
109
116
|
|
@@ -118,7 +125,8 @@ module EasyPost
|
|
118
125
|
client
|
119
126
|
end
|
120
127
|
|
121
|
-
|
128
|
+
# Make an HTTP request.
|
129
|
+
def self.make_request(method, path, api_key = nil, body = nil)
|
122
130
|
client = make_client(URI(@api_base))
|
123
131
|
|
124
132
|
request = Net::HTTP.const_get(method.capitalize).new(path)
|
@@ -126,29 +134,25 @@ module EasyPost
|
|
126
134
|
request.body = JSON.dump(EasyPost::Util.objects_to_ids(body))
|
127
135
|
end
|
128
136
|
|
129
|
-
request[
|
130
|
-
request[
|
131
|
-
|
132
|
-
"
|
133
|
-
if api_key = api_key || @api_key
|
134
|
-
request["Authorization"] = "Basic #{Base64.strict_encode64("#{api_key}:")}"
|
137
|
+
request['Content-Type'] = 'application/json'
|
138
|
+
request['User-Agent'] = "EasyPost/v2 RubyClient/#{VERSION} Ruby/#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"
|
139
|
+
if api_key ||= @api_key
|
140
|
+
request['Authorization'] = "Basic #{Base64.strict_encode64("#{api_key}:")}"
|
135
141
|
end
|
136
142
|
|
137
143
|
response = client.request(request)
|
138
144
|
|
139
145
|
if (400..599).include? response.code.to_i
|
140
|
-
error = JSON.parse(response.body)[
|
141
|
-
raise EasyPost::Error.new(error[
|
146
|
+
error = JSON.parse(response.body)['error']
|
147
|
+
raise EasyPost::Error.new(error['message'], response.code.to_i, error['code'], error['errors'], response.body)
|
142
148
|
end
|
143
149
|
|
144
|
-
if response[
|
150
|
+
if response['Content-Type'].include? 'application/json'
|
145
151
|
JSON.parse(response.body)
|
146
152
|
else
|
147
153
|
response.body
|
148
154
|
end
|
149
155
|
rescue JSON::ParserError
|
150
|
-
raise
|
151
|
-
"Invalid response object from API, unable to decode.\n#{response.body}"
|
152
|
-
)
|
156
|
+
raise "Invalid response object from API, unable to decode.\n#{response.body}"
|
153
157
|
end
|
154
158
|
end
|
metadata
CHANGED
@@ -1,16 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: easypost
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 4.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
8
|
-
- Andrew Tribone
|
9
|
-
- James Brown
|
7
|
+
- EasyPost Developers
|
10
8
|
autorequire:
|
11
9
|
bindir: bin
|
12
10
|
cert_chain: []
|
13
|
-
date: 2022-
|
11
|
+
date: 2022-02-25 00:00:00.000000000 Z
|
14
12
|
dependencies:
|
15
13
|
- !ruby/object:Gem::Dependency
|
16
14
|
name: pry
|
@@ -18,14 +16,14 @@ dependencies:
|
|
18
16
|
requirements:
|
19
17
|
- - "~>"
|
20
18
|
- !ruby/object:Gem::Version
|
21
|
-
version: '0.
|
19
|
+
version: '0.14'
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
23
|
requirements:
|
26
24
|
- - "~>"
|
27
25
|
- !ruby/object:Gem::Version
|
28
|
-
version: '0.
|
26
|
+
version: '0.14'
|
29
27
|
- !ruby/object:Gem::Dependency
|
30
28
|
name: rake
|
31
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -46,44 +44,100 @@ dependencies:
|
|
46
44
|
requirements:
|
47
45
|
- - "~>"
|
48
46
|
- !ruby/object:Gem::Version
|
49
|
-
version: '3.
|
47
|
+
version: '3.10'
|
50
48
|
type: :development
|
51
49
|
prerelease: false
|
52
50
|
version_requirements: !ruby/object:Gem::Requirement
|
53
51
|
requirements:
|
54
52
|
- - "~>"
|
55
53
|
- !ruby/object:Gem::Version
|
56
|
-
version: '3.
|
54
|
+
version: '3.10'
|
57
55
|
- !ruby/object:Gem::Dependency
|
58
|
-
name:
|
56
|
+
name: rubocop
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.24'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.24'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop-rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '2.7'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '2.7'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: simplecov
|
59
85
|
requirement: !ruby/object:Gem::Requirement
|
60
86
|
requirements:
|
61
87
|
- - "~>"
|
62
88
|
- !ruby/object:Gem::Version
|
63
|
-
version: '
|
89
|
+
version: '0.21'
|
64
90
|
type: :development
|
65
91
|
prerelease: false
|
66
92
|
version_requirements: !ruby/object:Gem::Requirement
|
67
93
|
requirements:
|
68
94
|
- - "~>"
|
69
95
|
- !ruby/object:Gem::Version
|
70
|
-
version: '
|
96
|
+
version: '0.21'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: simplecov-lcov
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0.8'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0.8'
|
71
111
|
- !ruby/object:Gem::Dependency
|
72
112
|
name: vcr
|
73
113
|
requirement: !ruby/object:Gem::Requirement
|
74
114
|
requirements:
|
75
115
|
- - "~>"
|
76
116
|
- !ruby/object:Gem::Version
|
77
|
-
version: '
|
117
|
+
version: '6.0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '6.0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: webmock
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '3.14'
|
78
132
|
type: :development
|
79
133
|
prerelease: false
|
80
134
|
version_requirements: !ruby/object:Gem::Requirement
|
81
135
|
requirements:
|
82
136
|
- - "~>"
|
83
137
|
- !ruby/object:Gem::Version
|
84
|
-
version: '
|
138
|
+
version: '3.14'
|
85
139
|
description: Client library for accessing the EasyPost shipping API via Ruby.
|
86
|
-
email:
|
140
|
+
email: oss@easypost.com
|
87
141
|
executables:
|
88
142
|
- easypost-irb
|
89
143
|
extensions: []
|
@@ -91,13 +145,16 @@ extra_rdoc_files: []
|
|
91
145
|
files:
|
92
146
|
- ".github/workflows/ci.yml"
|
93
147
|
- ".gitignore"
|
148
|
+
- ".rubocop.yml"
|
94
149
|
- CHANGELOG.md
|
95
150
|
- Gemfile
|
96
151
|
- LICENSE
|
97
152
|
- README.md
|
98
153
|
- Rakefile
|
154
|
+
- UPGRADE_GUIDE.md
|
99
155
|
- VERSION
|
100
156
|
- bin/easypost-irb
|
157
|
+
- easycop.yml
|
101
158
|
- easypost.gemspec
|
102
159
|
- lib/easypost.rb
|
103
160
|
- lib/easypost/address.rb
|
@@ -117,8 +174,6 @@ files:
|
|
117
174
|
- lib/easypost/pickup.rb
|
118
175
|
- lib/easypost/pickup_rate.rb
|
119
176
|
- lib/easypost/postage_label.rb
|
120
|
-
- lib/easypost/print_job.rb
|
121
|
-
- lib/easypost/printer.rb
|
122
177
|
- lib/easypost/rate.rb
|
123
178
|
- lib/easypost/refund.rb
|
124
179
|
- lib/easypost/report.rb
|
@@ -143,14 +198,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
143
198
|
requirements:
|
144
199
|
- - ">="
|
145
200
|
- !ruby/object:Gem::Version
|
146
|
-
version: '2.
|
201
|
+
version: '2.5'
|
147
202
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
148
203
|
requirements:
|
149
204
|
- - ">="
|
150
205
|
- !ruby/object:Gem::Version
|
151
206
|
version: '0'
|
152
207
|
requirements: []
|
153
|
-
rubygems_version: 3.3.
|
208
|
+
rubygems_version: 3.3.3
|
154
209
|
signing_key:
|
155
210
|
specification_version: 4
|
156
211
|
summary: EasyPost Ruby Client Library
|
data/lib/easypost/print_job.rb
DELETED
data/lib/easypost/printer.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
class EasyPost::Printer < EasyPost::Resource
|
2
|
-
|
3
|
-
def job
|
4
|
-
response = EasyPost.make_request(
|
5
|
-
:get, url + '/jobs', @api_key
|
6
|
-
)
|
7
|
-
return EasyPost::Util::convert_to_easypost_object(response, api_key)
|
8
|
-
end
|
9
|
-
|
10
|
-
def print(params={})
|
11
|
-
if params.instance_of?(EasyPost::PostageLabel)
|
12
|
-
temp = params.clone
|
13
|
-
params = {}
|
14
|
-
params[:postage_label] = temp
|
15
|
-
end
|
16
|
-
|
17
|
-
response = EasyPost.make_request(
|
18
|
-
:post, url + '/print_postage_label', @api_key, params
|
19
|
-
)
|
20
|
-
true
|
21
|
-
rescue
|
22
|
-
false
|
23
|
-
end
|
24
|
-
end
|