easypost 4.5.0 → 4.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/CODEOWNERS +2 -0
- data/.rubocop.yml +4 -0
- data/CHANGELOG.md +10 -0
- data/VERSION +1 -1
- data/lib/easypost/carbon_offset.rb +5 -0
- data/lib/easypost/payment_method.rb +4 -8
- data/lib/easypost/shipment.rb +18 -2
- data/lib/easypost/util.rb +1 -0
- data/lib/easypost/webhook.rb +22 -0
- data/lib/easypost.rb +1 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 16942dad76e2a3abbfa17dacaaa75f391f65a04a4daaea979bbba2c0e308ac30
|
4
|
+
data.tar.gz: 90d5b71e9c45c952296ed1dcb3769d1d69902c2917dc4a8fa1ca6842e5918129
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a91982b9ed19df4cf8ddea05d6da1a43d6caf86e6b49d67cf54d32ba71632e06d89822f695016d30e14a4f3577e600ebba29adedf38ed0c18797413c7589c80
|
7
|
+
data.tar.gz: 83201c6700dfdff58ca200780efdc83272fe3943a071879529ddb3a9ee8d526e505219c0584a8b91571400e3330be53f4aeefc568efdb5717f35df522a6b62fb
|
data/.github/CODEOWNERS
ADDED
data/.rubocop.yml
CHANGED
@@ -3,3 +3,7 @@ inherit_from: easycop.yml
|
|
3
3
|
# We are ignoring RSpec/FilePath because Simplecov doesn't play nice with nested spec files
|
4
4
|
RSpec/FilePath:
|
5
5
|
Enabled: false
|
6
|
+
# TODO: Remove this once we start using keyword arguments
|
7
|
+
Style/OptionalBooleanParameter:
|
8
|
+
Exclude:
|
9
|
+
- 'lib/easypost/shipment.rb'
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
+
## v4.6.0 (2022-08-02)
|
4
|
+
|
5
|
+
- Adds Carbon Offset support
|
6
|
+
- Adds ability to create a shipment with carbon_offset
|
7
|
+
- Adds ability to buy a shipment with carbon_offset
|
8
|
+
- Adds ability to one-call-buy a shipment with carbon_offset
|
9
|
+
- Adds ability to rerate a shipment with carbon_offset
|
10
|
+
- Adds `validate_webhook` function that returns your webhook or raises an error if there is a `webhook_secret` mismatch
|
11
|
+
- Deprecated `PaymentMethod` class, please use `Billing` class for retrieve all payment method function
|
12
|
+
|
3
13
|
## v4.5.0 (2022-07-18)
|
4
14
|
|
5
15
|
- Adds ability to generate shipment forms via `generate_form` function
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
4.
|
1
|
+
4.6.0
|
@@ -2,14 +2,10 @@
|
|
2
2
|
|
3
3
|
# PaymentMethod objects represent a payment method of a user.
|
4
4
|
class EasyPost::PaymentMethod < EasyPost::Resource
|
5
|
-
#
|
5
|
+
# <b>DEPRECATED:</b> Please use <tt>Billing class</tt> instead.
|
6
|
+
# Deprecated: v4.5.0 - v6.0.0
|
6
7
|
def self.all(api_key = nil)
|
7
|
-
|
8
|
-
|
9
|
-
if response['id'].nil?
|
10
|
-
raise EasyPost::Error.new('Billing has not been setup for this user. Please add a payment method.')
|
11
|
-
end
|
12
|
-
|
13
|
-
EasyPost::Util.convert_to_easypost_object(response, api_key)
|
8
|
+
warn '[DEPRECATION] `all` is deprecated. Please use `Billing.retrieve_payment_methods` instead.'
|
9
|
+
EasyPost::Billing.retrieve_payment_methods(api_key)
|
14
10
|
end
|
15
11
|
end
|
data/lib/easypost/shipment.rb
CHANGED
@@ -5,8 +5,22 @@ require 'set'
|
|
5
5
|
# The workhorse of the EasyPost API, a Shipment is made up of a "to" and "from" Address, the Parcel
|
6
6
|
# being shipped, and any customs forms required for international deliveries.
|
7
7
|
class EasyPost::Shipment < EasyPost::Resource
|
8
|
+
# Create a Shipment.
|
9
|
+
def self.create(params = {}, api_key = nil, with_carbon_offset = false)
|
10
|
+
wrapped_params = {
|
11
|
+
shipment: params,
|
12
|
+
carbon_offset: with_carbon_offset,
|
13
|
+
}
|
14
|
+
|
15
|
+
response = EasyPost.make_request(:post, url, api_key, wrapped_params)
|
16
|
+
EasyPost::Util.convert_to_easypost_object(response, api_key)
|
17
|
+
end
|
18
|
+
|
8
19
|
# Regenerate the rates of a Shipment.
|
9
|
-
def regenerate_rates(
|
20
|
+
def regenerate_rates(with_carbon_offset = false)
|
21
|
+
params = {}
|
22
|
+
params[:carbon_offset] = with_carbon_offset
|
23
|
+
|
10
24
|
response = EasyPost.make_request(:post, "#{url}/rerate", @api_key, params)
|
11
25
|
refresh_from(response, @api_key)
|
12
26
|
|
@@ -21,13 +35,15 @@ class EasyPost::Shipment < EasyPost::Resource
|
|
21
35
|
end
|
22
36
|
|
23
37
|
# Buy a Shipment.
|
24
|
-
def buy(params = {})
|
38
|
+
def buy(params = {}, with_carbon_offset = false)
|
25
39
|
if params.instance_of?(EasyPost::Rate)
|
26
40
|
temp = params.clone
|
27
41
|
params = {}
|
28
42
|
params[:rate] = temp
|
29
43
|
end
|
30
44
|
|
45
|
+
params[:carbon_offset] = with_carbon_offset
|
46
|
+
|
31
47
|
response = EasyPost.make_request(:post, "#{url}/buy", @api_key, params)
|
32
48
|
refresh_from(response, @api_key)
|
33
49
|
|
data/lib/easypost/util.rb
CHANGED
@@ -37,6 +37,7 @@ module EasyPost::Util
|
|
37
37
|
'Address' => EasyPost::Address,
|
38
38
|
'Batch' => EasyPost::Batch,
|
39
39
|
'Brand' => EasyPost::Brand,
|
40
|
+
'CarbonOffset' => EasyPost::CarbonOffset,
|
40
41
|
'CarrierAccount' => EasyPost::CarrierAccount,
|
41
42
|
'CustomsInfo' => EasyPost::CustomsInfo,
|
42
43
|
'CustomsItem' => EasyPost::CustomsItem,
|
data/lib/easypost/webhook.rb
CHANGED
@@ -32,4 +32,26 @@ class EasyPost::Webhook < EasyPost::Resource
|
|
32
32
|
|
33
33
|
self
|
34
34
|
end
|
35
|
+
|
36
|
+
# Validate a webhook by comparing the HMAC signature header sent from EasyPost to your shared secret.
|
37
|
+
# If the signatures do not match, an error will be raised signifying the webhook either did not originate
|
38
|
+
# from EasyPost or the secrets do not match. If the signatures do match, the `event_body` will be returned
|
39
|
+
# as JSON.
|
40
|
+
def self.validate_webhook(event_body, headers, webhook_secret)
|
41
|
+
easypost_hmac_signature = headers['X-Hmac-Signature']
|
42
|
+
|
43
|
+
if easypost_hmac_signature.nil?
|
44
|
+
raise EasyPost::Error.new('Webhook received does not contain an HMAC signature.')
|
45
|
+
end
|
46
|
+
|
47
|
+
encoded_webhook_secret = webhook_secret.unicode_normalize(:nfkd).encode('utf-8')
|
48
|
+
|
49
|
+
expected_signature = OpenSSL::HMAC.hexdigest('sha256', encoded_webhook_secret, event_body)
|
50
|
+
digest = "hmac-sha256-hex=#{expected_signature}"
|
51
|
+
unless digest == easypost_hmac_signature
|
52
|
+
raise EasyPost::Error.new('Webhook received did not originate from EasyPost or had a webhook secret mismatch.')
|
53
|
+
end
|
54
|
+
|
55
|
+
JSON.parse(event_body)
|
56
|
+
end
|
35
57
|
end
|
data/lib/easypost.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: easypost
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- EasyPost Developers
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-08-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: brakeman
|
@@ -158,6 +158,7 @@ extensions: []
|
|
158
158
|
extra_rdoc_files: []
|
159
159
|
files:
|
160
160
|
- ".gitattributes"
|
161
|
+
- ".github/CODEOWNERS"
|
161
162
|
- ".github/ISSUE_TEMPLATE/bug_report.yml"
|
162
163
|
- ".github/ISSUE_TEMPLATE/feature_request.yml"
|
163
164
|
- ".github/PULL_REQUEST_TEMPLATE.md"
|
@@ -188,6 +189,7 @@ files:
|
|
188
189
|
- lib/easypost/beta/referral.rb
|
189
190
|
- lib/easypost/billing.rb
|
190
191
|
- lib/easypost/brand.rb
|
192
|
+
- lib/easypost/carbon_offset.rb
|
191
193
|
- lib/easypost/carrier_account.rb
|
192
194
|
- lib/easypost/carrier_type.rb
|
193
195
|
- lib/easypost/connection.rb
|