easypost 3.5.1 → 5.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitattributes +9 -0
- data/.github/CODEOWNERS +2 -0
- data/.github/ISSUE_TEMPLATE/bug_report.yml +81 -0
- data/.github/ISSUE_TEMPLATE/feature_request.yml +37 -0
- data/.github/PULL_REQUEST_TEMPLATE.md +22 -0
- data/.github/workflows/ci.yml +54 -5
- data/.gitignore +27 -17
- data/.gitmodules +3 -0
- data/CHANGELOG.md +295 -119
- data/Gemfile +2 -0
- data/Makefile +70 -0
- data/README.md +184 -72
- data/Rakefile +2 -1
- data/UPGRADE_GUIDE.md +181 -0
- data/VERSION +1 -1
- data/bin/easypost-irb +5 -3
- data/easypost.gemspec +27 -20
- data/lib/easypost/client.rb +179 -0
- data/lib/easypost/connection.rb +64 -0
- data/lib/easypost/constants.rb +15 -0
- data/lib/easypost/errors/api/api_error.rb +108 -0
- data/lib/easypost/errors/api/bad_request_error.rb +6 -0
- data/lib/easypost/errors/api/connection_error.rb +6 -0
- data/lib/easypost/errors/api/external_api_error.rb +18 -0
- data/lib/easypost/errors/api/forbidden_error.rb +6 -0
- data/lib/easypost/errors/api/gateway_timeout_error.rb +6 -0
- data/lib/easypost/errors/api/internal_server_error.rb +6 -0
- data/lib/easypost/errors/api/invalid_request_error.rb +6 -0
- data/lib/easypost/errors/api/method_not_allowed_error.rb +6 -0
- data/lib/easypost/errors/api/not_found_error.rb +6 -0
- data/lib/easypost/errors/api/payment_error.rb +6 -0
- data/lib/easypost/errors/api/proxy_error.rb +6 -0
- data/lib/easypost/errors/api/rate_limit_error.rb +6 -0
- data/lib/easypost/errors/api/redirect_error.rb +6 -0
- data/lib/easypost/errors/api/retry_error.rb +6 -0
- data/lib/easypost/errors/api/service_unavailable_error.rb +6 -0
- data/lib/easypost/errors/api/ssl_error.rb +6 -0
- data/lib/easypost/errors/api/timeout_error.rb +6 -0
- data/lib/easypost/errors/api/unauthorized_error.rb +6 -0
- data/lib/easypost/errors/api/unknown_api_error.rb +6 -0
- data/lib/easypost/errors/easy_post_error.rb +7 -0
- data/lib/easypost/errors/end_of_pagination_error.rb +7 -0
- data/lib/easypost/errors/filtering_error.rb +4 -0
- data/lib/easypost/errors/invalid_object_error.rb +4 -0
- data/lib/easypost/errors/invalid_parameter_error.rb +11 -0
- data/lib/easypost/errors/missing_parameter_error.rb +9 -0
- data/lib/easypost/errors/signature_verification_error.rb +4 -0
- data/lib/easypost/errors.rb +32 -0
- data/lib/easypost/hooks/request_context.rb +16 -0
- data/lib/easypost/hooks/response_context.rb +23 -0
- data/lib/easypost/hooks.rb +34 -0
- data/lib/easypost/http_client.rb +117 -0
- data/lib/easypost/internal_utilities.rb +66 -0
- data/lib/easypost/models/address.rb +5 -0
- data/lib/easypost/models/api_key.rb +5 -0
- data/lib/easypost/models/base.rb +58 -0
- data/lib/easypost/models/batch.rb +5 -0
- data/lib/easypost/models/brand.rb +5 -0
- data/lib/easypost/models/carbon_offset.rb +5 -0
- data/lib/easypost/models/carrier_account.rb +5 -0
- data/lib/easypost/models/carrier_type.rb +5 -0
- data/lib/easypost/models/customs_info.rb +5 -0
- data/lib/easypost/models/customs_item.rb +5 -0
- data/lib/easypost/models/end_shipper.rb +5 -0
- data/lib/easypost/models/error.rb +21 -0
- data/lib/easypost/models/event.rb +5 -0
- data/lib/easypost/models/insurance.rb +6 -0
- data/lib/easypost/models/order.rb +9 -0
- data/lib/easypost/models/parcel.rb +5 -0
- data/lib/easypost/models/payload.rb +5 -0
- data/lib/easypost/models/payment_method.rb +5 -0
- data/lib/easypost/models/pickup.rb +9 -0
- data/lib/easypost/models/pickup_rate.rb +5 -0
- data/lib/easypost/models/postage_label.rb +5 -0
- data/lib/easypost/models/rate.rb +5 -0
- data/lib/easypost/models/referral.rb +5 -0
- data/lib/easypost/models/refund.rb +5 -0
- data/lib/easypost/models/report.rb +5 -0
- data/lib/easypost/models/scan_form.rb +6 -0
- data/lib/easypost/models/shipment.rb +10 -0
- data/lib/easypost/models/tax_identifier.rb +6 -0
- data/lib/easypost/models/tracker.rb +5 -0
- data/lib/easypost/models/user.rb +5 -0
- data/lib/easypost/models/webhook.rb +6 -0
- data/lib/easypost/models.rb +36 -0
- data/lib/easypost/services/address.rb +50 -0
- data/lib/easypost/services/api_key.rb +8 -0
- data/lib/easypost/services/base.rb +27 -0
- data/lib/easypost/services/batch.rb +53 -0
- data/lib/easypost/services/beta_rate.rb +12 -0
- data/lib/easypost/services/beta_referral_customer.rb +40 -0
- data/lib/easypost/services/billing.rb +75 -0
- data/lib/easypost/services/carrier_account.rb +44 -0
- data/lib/easypost/services/carrier_metadata.rb +22 -0
- data/lib/easypost/services/carrier_type.rb +10 -0
- data/lib/easypost/services/customs_info.rb +17 -0
- data/lib/easypost/services/customs_item.rb +15 -0
- data/lib/easypost/services/end_shipper.rb +31 -0
- data/lib/easypost/services/event.rb +32 -0
- data/lib/easypost/services/insurance.rb +26 -0
- data/lib/easypost/services/order.rb +30 -0
- data/lib/easypost/services/parcel.rb +16 -0
- data/lib/easypost/services/pickup.rb +40 -0
- data/lib/easypost/services/rate.rb +8 -0
- data/lib/easypost/services/referral_customer.rb +103 -0
- data/lib/easypost/services/refund.rb +26 -0
- data/lib/easypost/services/report.rb +42 -0
- data/lib/easypost/services/scan_form.rb +25 -0
- data/lib/easypost/services/shipment.rb +106 -0
- data/lib/easypost/services/tracker.rb +38 -0
- data/lib/easypost/services/user.rb +66 -0
- data/lib/easypost/services/webhook.rb +34 -0
- data/lib/easypost/services.rb +33 -0
- data/lib/easypost/util.rb +160 -116
- data/lib/easypost/utilities/constants.rb +5 -0
- data/lib/easypost/utilities/json.rb +23 -0
- data/lib/easypost/utilities/static_mapper.rb +73 -0
- data/lib/easypost/utilities/system.rb +36 -0
- data/lib/easypost/version.rb +3 -1
- data/lib/easypost.rb +20 -143
- metadata +249 -46
- data/lib/easypost/address.rb +0 -58
- data/lib/easypost/api_key.rb +0 -2
- data/lib/easypost/batch.rb +0 -49
- data/lib/easypost/brand.rb +0 -9
- data/lib/easypost/carrier_account.rb +0 -5
- data/lib/easypost/carrier_type.rb +0 -2
- data/lib/easypost/customs_info.rb +0 -5
- data/lib/easypost/customs_item.rb +0 -5
- data/lib/easypost/error.rb +0 -31
- data/lib/easypost/event.rb +0 -7
- data/lib/easypost/insurance.rb +0 -2
- data/lib/easypost/object.rb +0 -151
- data/lib/easypost/order.rb +0 -28
- data/lib/easypost/parcel.rb +0 -2
- data/lib/easypost/pickup.rb +0 -26
- data/lib/easypost/pickup_rate.rb +0 -3
- data/lib/easypost/postage_label.rb +0 -2
- data/lib/easypost/print_job.rb +0 -2
- data/lib/easypost/printer.rb +0 -24
- data/lib/easypost/rate.rb +0 -2
- data/lib/easypost/refund.rb +0 -2
- data/lib/easypost/report.rb +0 -29
- data/lib/easypost/resource.rb +0 -75
- data/lib/easypost/scan_form.rb +0 -6
- data/lib/easypost/shipment.rb +0 -129
- data/lib/easypost/tax_identifier.rb +0 -2
- data/lib/easypost/tracker.rb +0 -7
- data/lib/easypost/user.rb +0 -56
- data/lib/easypost/webhook.rb +0 -29
data/README.md
CHANGED
@@ -1,113 +1,225 @@
|
|
1
1
|
# EasyPost Ruby Client Library
|
2
2
|
|
3
3
|
[![Build Status](https://github.com/EasyPost/easypost-ruby/workflows/CI/badge.svg)](https://github.com/EasyPost/easypost-ruby/actions?query=workflow%3ACI)
|
4
|
+
[![Coverage Status](https://coveralls.io/repos/github/EasyPost/easypost-ruby/badge.svg?branch=master)](https://coveralls.io/github/EasyPost/easypost-ruby?branch=master)
|
4
5
|
[![Gem Version](https://badge.fury.io/rb/easypost.svg)](https://badge.fury.io/rb/easypost)
|
5
6
|
|
7
|
+
EasyPost, the simple shipping solution. You can sign up for an account at <https://easypost.com>.
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
-
## Installation
|
10
|
-
|
11
|
-
Install the gem:
|
9
|
+
## Install
|
12
10
|
|
13
11
|
```bash
|
14
12
|
gem install easypost
|
15
13
|
```
|
16
14
|
|
17
|
-
Import the EasyPost client in your application:
|
18
|
-
|
19
15
|
```ruby
|
16
|
+
# Require the library in your project:
|
20
17
|
require 'easypost'
|
21
18
|
```
|
22
19
|
|
23
|
-
##
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
A simple create & buy shipment example:
|
24
23
|
|
25
24
|
```ruby
|
26
25
|
require 'easypost'
|
27
|
-
EasyPost.api_key = 'API_KEY'
|
28
|
-
|
29
|
-
to_address = EasyPost::Address.create(
|
30
|
-
:name => 'Dr. Steve Brule',
|
31
|
-
:street1 => '179 N Harbor Dr',
|
32
|
-
:city => 'Redondo Beach',
|
33
|
-
:state => 'CA',
|
34
|
-
:zip => '90277',
|
35
|
-
:country => 'US',
|
36
|
-
:phone => '310-808-5243'
|
37
|
-
)
|
38
26
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
:
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
27
|
+
client = EasyPost::Client.new(api_key: ENV['EASYPOST_TEST_API_KEY'])
|
28
|
+
|
29
|
+
shipment = client.shipment.create(
|
30
|
+
from_address: {
|
31
|
+
company: 'EasyPost',
|
32
|
+
street1: '118 2nd Street',
|
33
|
+
street2: '4th Floor',
|
34
|
+
city: 'San Francisco',
|
35
|
+
state: 'CA',
|
36
|
+
zip: '94105',
|
37
|
+
phone: '415-456-7890',
|
38
|
+
},
|
39
|
+
to_address: {
|
40
|
+
name: 'Dr. Steve Brule',
|
41
|
+
street1: '179 N Harbor Dr',
|
42
|
+
city: 'Redondo Beach',
|
43
|
+
state: 'CA',
|
44
|
+
zip: '90277',
|
45
|
+
country: 'US',
|
46
|
+
phone: '310-808-5243',
|
47
|
+
},
|
48
|
+
parcel: {
|
49
|
+
width: 15.2,
|
50
|
+
length: 18,
|
51
|
+
height: 9.5,
|
52
|
+
weight: 35.1,
|
53
|
+
},
|
47
54
|
)
|
48
55
|
|
49
|
-
|
50
|
-
:width => 15.2,
|
51
|
-
:length => 18,
|
52
|
-
:height => 9.5,
|
53
|
-
:weight => 35.1
|
54
|
-
)
|
56
|
+
bought_shipment = client.shipment.buy(shipment.id, rate: shipment.lowest_rate)
|
55
57
|
|
56
|
-
|
57
|
-
|
58
|
-
:quantity => 2,
|
59
|
-
:value => 23.56,
|
60
|
-
:weight => 33,
|
61
|
-
:origin_country => 'us',
|
62
|
-
:hs_tariff_number => 123456
|
63
|
-
)
|
58
|
+
puts bought_shipment
|
59
|
+
```
|
64
60
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
61
|
+
### Custom Connections
|
62
|
+
|
63
|
+
Pass in a lambda function as `custom_client_exec` when initializing a client that responds to `call(method, uri, headers, open_timeout, read_timeout, body = nil)` where:
|
64
|
+
|
65
|
+
- `uri` is the fully-qualified URL of the EasyPost endpoint, including query parameters (`Uri` object)
|
66
|
+
- `method` is the lowercase name of the HTTP method being used for the request (e.g. `:get`, `:post`, `:put`, `:delete`)
|
67
|
+
- `headers` is a hash with all headers needed for the request pre-populated, including authorization (`Hash` object)
|
68
|
+
- `open_timeout` is the number of seconds to wait for the connection to open (integer)
|
69
|
+
- `read_timeout` is the number of seconds to wait for one block to be read (integer)
|
70
|
+
- `body` is a string of the body data to be included in the request, or nil (e.g. GET or DELETE request) (string or `nil`)
|
71
|
+
|
72
|
+
The lambda function should return an object with `code` and `body` attributes, where:
|
73
|
+
|
74
|
+
- `code` is the HTTP response status code (integer)
|
75
|
+
- `body` is the response body (string)
|
76
|
+
|
77
|
+
#### Faraday
|
77
78
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
:
|
79
|
+
```ruby
|
80
|
+
require 'faraday'
|
81
|
+
|
82
|
+
custom_connection = lambda { |method, uri, headers, _open_timeout, _read_timeout, body = nil|
|
83
|
+
conn = Faraday.new(url: uri.to_s, headers: headers) do |faraday|
|
84
|
+
faraday.adapter Faraday.default_adapter
|
85
|
+
end
|
86
|
+
conn.public_send(method, uri.path) { |request|
|
87
|
+
request.body = body if body
|
88
|
+
}.yield_self do |response|
|
89
|
+
OpenStruct.new(code: response.status, body: response.body)
|
90
|
+
end
|
91
|
+
}
|
92
|
+
|
93
|
+
my_client = described_class.new(
|
94
|
+
api_key: ENV['EASYPOST_API_KEY'],
|
95
|
+
custom_client_exec: custom_connection,
|
83
96
|
)
|
97
|
+
```
|
84
98
|
|
85
|
-
|
86
|
-
|
99
|
+
#### Typhoeus
|
100
|
+
|
101
|
+
```ruby
|
102
|
+
require 'typhoeus'
|
103
|
+
|
104
|
+
custom_connection = lambda { |method, uri, headers, _open_timeout, _read_timeout, body = nil|
|
105
|
+
Typhoeus.public_send(
|
106
|
+
method,
|
107
|
+
uri.to_s,
|
108
|
+
headers: headers,
|
109
|
+
body: body,
|
110
|
+
).yield_self do |response|
|
111
|
+
OpenStruct.new(code: response.code, body: response.body)
|
112
|
+
end
|
113
|
+
}
|
114
|
+
|
115
|
+
my_client = described_class.new(
|
116
|
+
api_key: ENV['EASYPOST_API_KEY'],
|
117
|
+
custom_client_exec: custom_connection,
|
87
118
|
)
|
119
|
+
```
|
88
120
|
|
89
|
-
|
121
|
+
### HTTP Hooks
|
90
122
|
|
91
|
-
|
123
|
+
Users can audit HTTP requests and responses being made by the library by subscribing to request and response events. To do so, pass a block to the `subscribe_request_hook` and `subscribe_response_hook` methods of an instance of `EasyPost::Client`:
|
92
124
|
|
93
|
-
|
125
|
+
```ruby
|
126
|
+
require 'easypost'
|
127
|
+
|
128
|
+
client = EasyPost::Client.new(api_key: ENV['EASYPOST_API_KEY'])
|
129
|
+
|
130
|
+
# Returns a randomly-generated symbol which you can use to later unsubscribe the request hook
|
131
|
+
client.subscribe_request_hook do |request_data|
|
132
|
+
# Your code goes here
|
133
|
+
end
|
134
|
+
# Returns a randomly-generated symbol which you can use to later unsubscribe the response hook
|
135
|
+
client.subscribe_response_hook do |response_data|
|
136
|
+
# Your code goes here
|
137
|
+
end
|
94
138
|
```
|
95
139
|
|
140
|
+
You can also name your hook subscriptions by providing an optional parameter to the methods above:
|
141
|
+
|
142
|
+
```ruby
|
143
|
+
require 'easypost'
|
144
|
+
|
145
|
+
client = EasyPost::Client.new(api_key: ENV['EASYPOST_API_KEY'])
|
146
|
+
|
147
|
+
request_hook = client.subscribe_request_hook(:my_request_hook) do |request_data|
|
148
|
+
# Your code goes here
|
149
|
+
end
|
150
|
+
response_hook = client.subscribe_response_hook(:my_response_hook) do |response_data|
|
151
|
+
# Your code goes here
|
152
|
+
end
|
153
|
+
|
154
|
+
puts request_hook # :my_request_hook
|
155
|
+
puts response_hook # :my_response_hook
|
156
|
+
```
|
157
|
+
|
158
|
+
Keep in mind that subscribing a hook with the same name of an existing hook will replace the existing hook with the new one. A request hook and a response hook can share the same name.
|
159
|
+
|
160
|
+
#### Custom HTTP Connections with HTTP Hooks
|
161
|
+
|
162
|
+
If you're using a custom HTTP connection, keep in mind that the `response_data` parameter that a response hook receives *will not be hydrated* with all the response data. You will have to inspect the `client_response_object` property in `response_data` to inspect the response code, response headers and response body.
|
163
|
+
|
96
164
|
## Documentation
|
97
165
|
|
98
|
-
|
166
|
+
API documentation can be found at: <https://easypost.com/docs/api>.
|
167
|
+
|
168
|
+
Library documentation can be found on the web at: <https://easypost.github.io/easypost-ruby/> or by building them locally via the `make docs` command.
|
169
|
+
|
170
|
+
Upgrading major versions of this project? Refer to the [Upgrade Guide](UPGRADE_GUIDE.md).
|
171
|
+
|
172
|
+
## Support
|
173
|
+
|
174
|
+
New features and bug fixes are released on the latest major release of this library. If you are on an older major release of this library, we recommend upgrading to the most recent release to take advantage of new features, bug fixes, and security patches. Older versions of this library will continue to work and be available as long as the API version they are tied to remains active; however, they will not receive updates and are considered EOL.
|
175
|
+
|
176
|
+
For additional support, see our [org-wide support policy](https://github.com/EasyPost/.github/blob/main/SUPPORT.md).
|
99
177
|
|
100
178
|
## Development
|
101
179
|
|
102
180
|
```bash
|
103
|
-
#
|
104
|
-
|
181
|
+
# Install dependencies
|
182
|
+
make install
|
183
|
+
|
184
|
+
# Install style guide (Unix only)
|
185
|
+
make install-style
|
186
|
+
|
187
|
+
# Lint project
|
188
|
+
make lint
|
189
|
+
make lint-fix
|
190
|
+
|
191
|
+
# Run tests (coverage is generated on a successful test suite run)
|
192
|
+
EASYPOST_TEST_API_KEY=123... EASYPOST_PROD_API_KEY=123... make test
|
193
|
+
|
194
|
+
# Run security analysis
|
195
|
+
make scan
|
196
|
+
|
197
|
+
# Generate library documentation
|
198
|
+
make docs
|
199
|
+
|
200
|
+
# Update submodules
|
201
|
+
make update-examples-submodule
|
105
202
|
```
|
106
203
|
|
107
|
-
|
204
|
+
### Testing
|
205
|
+
|
206
|
+
The test suite in this project was specifically built to produce consistent results on every run, regardless of when they run or who is running them. This project uses [VCR](https://github.com/vcr/vcr) to record and replay HTTP requests and responses via "cassettes". When the suite is run, the HTTP requests and responses for each test function will be saved to a cassette if they do not exist already and replayed from this saved file if they do, which saves the need to make live API calls on every test run. If you receive errors about a cassette expiring, delete and re-record the cassette to ensure the data is up-to-date.
|
207
|
+
|
208
|
+
**Sensitive Data:** We've made every attempt to include scrubbers for sensitive data when recording cassettes so that PII or sensitive info does not persist in version control; however, please ensure when recording or re-recording cassettes that prior to committing your changes, no PII or sensitive information gets persisted by inspecting the cassette.
|
209
|
+
|
210
|
+
**Making Changes:** If you make an addition to this project, the request/response will get recorded automatically for you. When making changes to this project, you'll need to re-record the associated cassette to force a new live API call for that test which will then record the request/response used on the next run.
|
211
|
+
|
212
|
+
**Test Data:** The test suite has been populated with various helpful fixtures that are available for use, each completely independent from a particular user **with the exception of the USPS carrier account ID** (see [Unit Test API Keys](#unit-test-api-keys) for more information) which has a fallback value of our internal testing user's ID. Some fixtures use hard-coded dates that may need to be incremented if cassettes get re-recorded (such as reports or pickups).
|
213
|
+
|
214
|
+
#### Unit Test API Keys
|
215
|
+
|
216
|
+
The following are required on every test run:
|
217
|
+
|
218
|
+
- `EASYPOST_TEST_API_KEY`
|
219
|
+
- `EASYPOST_PROD_API_KEY`
|
220
|
+
|
221
|
+
Some tests may require an EasyPost user with a particular set of enabled features such as a `Partner` user when creating referrals. We have attempted to call out these functions in their respective docstrings. The following are required when you need to re-record cassettes for applicable tests:
|
108
222
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
1. Build the Gem `gem build easypost.gemspec`
|
113
|
-
1. Publish the Gem `gem push easypost-X.X.X.gem` (replace `X.X.X` with the version being released)
|
223
|
+
- `USPS_CARRIER_ACCOUNT_ID` (eg: one-call buying a shipment for non-EasyPost employees)
|
224
|
+
- `PARTNER_USER_PROD_API_KEY` (eg: creating a referral customer)
|
225
|
+
- `REFERRAL_CUSTOMER_PROD_API_KEY` (eg: adding a credit card to a referral customer)
|
data/Rakefile
CHANGED
data/UPGRADE_GUIDE.md
ADDED
@@ -0,0 +1,181 @@
|
|
1
|
+
# Upgrade Guide
|
2
|
+
|
3
|
+
Use the following guide to assist in the upgrade process of the `easypost-ruby` library between major versions.
|
4
|
+
|
5
|
+
- [Upgrading from 4.x to 5.0](#upgrading-from-4x-to-50)
|
6
|
+
- [Upgrading from 3.x to 4.0](#upgrading-from-3x-to-40)
|
7
|
+
|
8
|
+
## Upgrading from 4.x to 5.0
|
9
|
+
|
10
|
+
### 5.0 High Impact Changes
|
11
|
+
|
12
|
+
- [New Client object](#50-thread-safe-with-client-object)
|
13
|
+
- [Updated Dependencies](#50-updated-dependencies)
|
14
|
+
- [Improved Error Handling](#50-improved-error-handling)
|
15
|
+
|
16
|
+
### 5.0 Medium Impact Changes
|
17
|
+
|
18
|
+
- [Corrected Naming Conventions](#50-corrected-naming-conventions)
|
19
|
+
|
20
|
+
### 5.0 Low Impact Changes
|
21
|
+
|
22
|
+
- [Beta Namespace Changed](#50-beta-namespace-changed)
|
23
|
+
|
24
|
+
## 5.0 Thread-Safe with Client Object
|
25
|
+
|
26
|
+
Likelihood of Impact: High
|
27
|
+
|
28
|
+
This library is now thread-safe with the introduction of a new `Client` object. Instead of defining a global API key that all requests use, you now create an `Client` object and pass your API key to it with optional open and read timeout params. You then call your desired functions against a `service` which are called against a `Client` object:
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
# Old way
|
32
|
+
EasyPost.api_key = ENV['EASYPOST_API_KEY']
|
33
|
+
shipment = EasyPost::Shipment.retrieve('shp_...')
|
34
|
+
|
35
|
+
# New way
|
36
|
+
client = EasyPost::Client.new(api_key: ENV['EASYPOST_TEST_API_KEY'])
|
37
|
+
shipment = client.shipment.retrieve('shp_...')
|
38
|
+
```
|
39
|
+
|
40
|
+
All instance methods are now static with the exception of `lowest_rate` as these make API calls and require the Client object(EasyPost objects do not contain an API key to make API calls with).
|
41
|
+
|
42
|
+
Previously used `.save()` instance methods are now static `.update()` functions where you specify first the ID of the object you are updating and second, the parameters that need updating.
|
43
|
+
|
44
|
+
## 5.0 Updated Dependencies
|
45
|
+
|
46
|
+
Likelihood of Impact: High
|
47
|
+
|
48
|
+
**Ruby 2.6 Required**
|
49
|
+
|
50
|
+
easypost-ruby now requires Ruby 2.6 or greater.
|
51
|
+
|
52
|
+
**Dependencies**
|
53
|
+
|
54
|
+
All dependencies had minor version bumps.
|
55
|
+
|
56
|
+
## 5.0 Improved Error Handling
|
57
|
+
|
58
|
+
Likelihood of Impact: High
|
59
|
+
|
60
|
+
There are ~2 dozen new error types that extend either `ApiError` or `EasyPostError`.
|
61
|
+
|
62
|
+
New ApiErrors (extends EasyPostError):
|
63
|
+
|
64
|
+
- `ApiError`
|
65
|
+
- `ConnectionError`
|
66
|
+
- `ExternalApiError`
|
67
|
+
- `ForbiddenError`
|
68
|
+
- `GatewayTimeoutError`
|
69
|
+
- `InternalServerError`
|
70
|
+
- `InvalidRequestError`
|
71
|
+
- `MethodNotAllowedError`
|
72
|
+
- `NotFoundError`
|
73
|
+
- `PaymentError`
|
74
|
+
- `ProxyError`
|
75
|
+
- `RateLimitError`
|
76
|
+
- `RedirectError`
|
77
|
+
- `RetryError`
|
78
|
+
- `ServiceUnavailableError`
|
79
|
+
- `SSLError`
|
80
|
+
- `TimeoutError`
|
81
|
+
- `UnauthorizedError`
|
82
|
+
- `UnknownApiError`
|
83
|
+
|
84
|
+
New EasyPostErrors (extends builtin Exception):
|
85
|
+
|
86
|
+
- `EasyPostError`
|
87
|
+
- `EndOfPaginationError`
|
88
|
+
- `FilteringError`
|
89
|
+
- `InvalidObjectError`
|
90
|
+
- `InvalidParameterError`
|
91
|
+
- `MissingParameterError`
|
92
|
+
- `SignatureVerificationError`
|
93
|
+
|
94
|
+
ApiErrors will behave like the previous Error class did. They will include a `message`, `http_status`, and `http_body`. Additionally, a new `code` and `errors` keys are present and populate when available. This class extends the more generic `EasyPostError` which only contains a message, used for errors thrown directly from this library.
|
95
|
+
|
96
|
+
## 5.0 Corrected Naming Conventions
|
97
|
+
|
98
|
+
Likelihood of Impact: Medium
|
99
|
+
|
100
|
+
Occurances of `referral` are now `referral_customer` and `Referral` are now `ReferralCustomer` to match the documentation and API.
|
101
|
+
|
102
|
+
Occurances of `smartrate` are now `smart_rate` and `Smartrate` are now `SmartRate` to match the documentation and API.
|
103
|
+
|
104
|
+
Occurances of `scanform` are now `scan_form` and `Scanform` are now `ScanForm` to match the documentation and API.
|
105
|
+
|
106
|
+
Rename function `get_smartrates` to `get_smart_rates`
|
107
|
+
|
108
|
+
Rename function `get_lowest_smartrate` to `get_lowest_smart_rate`
|
109
|
+
|
110
|
+
## 5.0 Beta Namespace Changed
|
111
|
+
|
112
|
+
Likelihood of Impact: Low
|
113
|
+
|
114
|
+
Previously, the beta namespace was found at `easypost.beta.x` where `x` is the name of your model. Now, the beta namespace is simply prepended to the name of your service: `client.beta_x`. for instance, you can call `client.beta_referral_customer.add_payment_method()`.
|
115
|
+
|
116
|
+
## 5.0 Return True For Empty API Response
|
117
|
+
|
118
|
+
Likelihood of Impact: Low
|
119
|
+
|
120
|
+
Empty API response functions for `delete` return `true` instead of empty object
|
121
|
+
|
122
|
+
## Upgrading from 3.x to 4.0
|
123
|
+
|
124
|
+
**NOTICE:** v4 is deprecated.
|
125
|
+
|
126
|
+
### 4.0 High Impact Changes
|
127
|
+
|
128
|
+
* [Updating Dependencies](#40-updating-dependencies)
|
129
|
+
|
130
|
+
### 4.0 Medium Impact Changes
|
131
|
+
|
132
|
+
* [Removal of `get_rates` Shipment Method](#40-removal-of-getrates-shipment-method)
|
133
|
+
|
134
|
+
### 4.0 Low Impact Changes
|
135
|
+
|
136
|
+
* [Removal of `Print` and `PrintJob` Objects](#40-removal-of-print-and-printjob-objects)
|
137
|
+
* [Removal of `stamp_and_barcode_by_reference` Batch Method](#40-removal-of-stampandbarcodebyreference-batch-method)
|
138
|
+
* [Removal of `Address.verify` Parameters](#40-removal-of-addressverify-parameters)
|
139
|
+
* [Removal of the `http_status` Property on EasyPost::Error](#40-removal-of-httpstatus-property-on-easyposterror)
|
140
|
+
|
141
|
+
## 4.0 Updating Dependencies
|
142
|
+
|
143
|
+
Likelihood of Impact: High
|
144
|
+
|
145
|
+
**Ruby 2.5 Required**
|
146
|
+
|
147
|
+
easypost-ruby now requires Ruby 2.5 or greater.
|
148
|
+
|
149
|
+
**Dependencies**
|
150
|
+
|
151
|
+
No production dependencies were altered. Development dependencies were all bumped and `simplecov` and `rubocop` were introduced.
|
152
|
+
|
153
|
+
## 4.0 Removal of get_rates Shipment Method
|
154
|
+
|
155
|
+
Likelihood of Impact: Medium
|
156
|
+
|
157
|
+
The HTTP method used for the `get_rates` endpoint at the API level has changed from `POST` to `GET` and will only retrieve rates for a shipment instead of regenerating them. A new `/rerate` endpoint has been introduced to replace this functionality; In this library, you can now call the `Shipment.regenerate_rates` method to regenerate rates. Due to the logic change, the `get_rates` method has been removed since a Shipment inherently already has rates associated.
|
158
|
+
|
159
|
+
## 4.0 Removal of Print and PrintJob Objects
|
160
|
+
|
161
|
+
Likelihood of Impact: Low
|
162
|
+
|
163
|
+
The `Print` and `PrintJob` objects have been removed as they are no longer usable with the current version of the API.
|
164
|
+
|
165
|
+
## 4.0 Removal of stamp_and_barcode_by_reference Batch Method
|
166
|
+
|
167
|
+
Likelihood of Impact: Low
|
168
|
+
|
169
|
+
The `stamp_and_barcode_by_reference` Batch method has been removed as it is no longer usable with the current version of the API.
|
170
|
+
|
171
|
+
## 4.0 Removal of Address.verify Parameters
|
172
|
+
|
173
|
+
Likelihood of Impact: Low
|
174
|
+
|
175
|
+
The parameters for the `Address.verify` method were removed as they were unusable, the current version of the API does not allow you to verify an address by specifying a carrier.
|
176
|
+
|
177
|
+
## 4.0 Removal of http_status Property on EasyPost::Error
|
178
|
+
|
179
|
+
Likelihood of Impact: Low
|
180
|
+
|
181
|
+
The deprecated `http_status` property has been removed in favor of the `status` property on the EasyPost::Error object.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
5.2.0
|
data/bin/easypost-irb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
2
4
|
irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
|
3
5
|
|
4
|
-
libs =
|
5
|
-
libs <<
|
6
|
-
puts
|
6
|
+
libs = ' -r irb/completion'
|
7
|
+
libs << " -r #{"#{File.dirname(__FILE__)}/../lib/easypost"}"
|
8
|
+
puts 'Initializing EasyPost...'
|
7
9
|
exec "#{irb} #{libs} --simple-prompt"
|
data/easypost.gemspec
CHANGED
@@ -1,31 +1,38 @@
|
|
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.
|
11
|
-
spec.
|
12
|
-
spec.
|
13
|
-
spec.
|
14
|
-
spec.
|
15
|
-
spec.
|
16
|
-
spec.homepage = "https://www.easypost.com/docs"
|
10
|
+
spec.license = '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
|
-
f.match(%r{^(
|
18
|
+
f.match(%r{^(docs|examples|spec)/})
|
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.6'
|
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 'brakeman', '~> 5.4'
|
25
|
+
spec.add_development_dependency 'faraday', '~> 2.7.5' # used for integration tests
|
26
|
+
spec.add_development_dependency 'pry', '~> 0.14'
|
27
|
+
spec.add_development_dependency 'psych', '~> 5.1'
|
28
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
29
|
+
spec.add_development_dependency 'rdoc', '~> 6.5'
|
30
|
+
spec.add_development_dependency 'rspec', '~> 3.12'
|
31
|
+
spec.add_development_dependency 'rubocop', '~> 1.49'
|
32
|
+
spec.add_development_dependency 'rubocop-rspec', '2.19' # pin to 2.19 because latest version doesn't support Ruby 2.6
|
33
|
+
spec.add_development_dependency 'simplecov', '~> 0.22'
|
34
|
+
spec.add_development_dependency 'simplecov-lcov', '~> 0.8'
|
35
|
+
spec.add_development_dependency 'typhoeus', '~> 1.4.0' # used for integration tests
|
36
|
+
spec.add_development_dependency 'vcr', '~> 6.1'
|
37
|
+
spec.add_development_dependency 'webmock', '~> 3.18'
|
31
38
|
end
|