easypost 4.3.0 → 4.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '02404008f0fc1078e49e1e418c5a208fbca5d646f31886c3c7fab55d932def70'
4
- data.tar.gz: b8a2f7d514f9f22fa5b7ec3daf010adbfcc793c689954102b6ccbaafd7742e6a
3
+ metadata.gz: 16942dad76e2a3abbfa17dacaaa75f391f65a04a4daaea979bbba2c0e308ac30
4
+ data.tar.gz: 90d5b71e9c45c952296ed1dcb3769d1d69902c2917dc4a8fa1ca6842e5918129
5
5
  SHA512:
6
- metadata.gz: f6c9af835a6ff8ccb7574fd5a14ef96f850784e6600249a8441d23a521763ad3fb40d826cdce0f758cd4b87213a65c6ee733476d34824dabbb7fb09db2af0de0
7
- data.tar.gz: c492ad0635133598e8535a2a0c72949b0acd6f0095b511bb91011c50cec67e6d8999b5358da8aa7ae4543e38a30bc029367d8c0cfd791e4944f46fac3cdf75d9
6
+ metadata.gz: 9a91982b9ed19df4cf8ddea05d6da1a43d6caf86e6b49d67cf54d32ba71632e06d89822f695016d30e14a4f3577e600ebba29adedf38ed0c18797413c7589c80
7
+ data.tar.gz: 83201c6700dfdff58ca200780efdc83272fe3943a071879529ddb3a9ee8d526e505219c0584a8b91571400e3330be53f4aeefc568efdb5717f35df522a6b62fb
data/.gitattributes ADDED
@@ -0,0 +1,4 @@
1
+ * text=auto
2
+
3
+ spec/cassettes/**/* -diff
4
+ spec/cassettes/**/* linguist-generated
@@ -0,0 +1,2 @@
1
+ # Ping the DevEx team for reviews on every PR
2
+ * @EasyPost/devex
@@ -20,7 +20,7 @@ jobs:
20
20
  ruby-version: ${{ matrix.rubyversion }}
21
21
  bundler-cache: true
22
22
  - name: run tests
23
- run: EASYPOST_TEST_API_KEY=123 EASYPOST_PROD_API_KEY=123 bundle exec rspec
23
+ run: EASYPOST_TEST_API_KEY=123 EASYPOST_PROD_API_KEY=123 make test
24
24
  lint:
25
25
  runs-on: ubuntu-latest
26
26
  steps:
@@ -31,6 +31,8 @@ jobs:
31
31
  with:
32
32
  ruby-version: "3.1"
33
33
  - name: Install Dependencies
34
- run: bundle install
34
+ run: make install
35
35
  - name: Lint Project
36
- run: rubocop
36
+ run: make lint
37
+ - name: Run security analysis
38
+ run: make brakeman
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,25 @@
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
+
13
+ ## v4.5.0 (2022-07-18)
14
+
15
+ - Adds ability to generate shipment forms via `generate_form` function
16
+
17
+ ## v4.4.0 (2022-07-11)
18
+
19
+ - Adds `Billing.retrieve_payment_methods()`, `Billing.fund_wallet()`, and `Billing.delete_payment_method()` functions
20
+ - Captures OS information in the user-agent header for easier debugging
21
+ - Update functions now use `patch` instead of `put` under the hood to better match API behavior and documentation. The behavior of these functions should remain the same
22
+
3
23
  ## v4.3.0 (2022-05-19)
4
24
 
5
25
  - Adds the `EndShipper` Beta class with `create`, `retrieve`, `all`, and `save` functions
data/Makefile ADDED
@@ -0,0 +1,37 @@
1
+ ## help - Display help about make targets for this Makefile
2
+ help:
3
+ @cat Makefile | grep '^## ' --color=never | cut -c4- | sed -e "`printf 's/ - /\t- /;'`" | column -s "`printf '\t'`" -t
4
+
5
+ ## brakeman - Runs security analysis on the project with Brakeman
6
+ brakeman:
7
+ brakeman lib --force
8
+
9
+ ## build - Builds the project
10
+ build:
11
+ gem build easypost.gemspec
12
+
13
+ ## clean - Cleans the project
14
+ clean:
15
+ rm -rf coverage doc *.gem
16
+
17
+ ## fix - Fix Rubocop errors
18
+ fix:
19
+ rubocop -A
20
+
21
+ ## install - Install globally from source
22
+ install:
23
+ bundle install
24
+
25
+ ## lint - Lint the project
26
+ lint:
27
+ rubocop
28
+
29
+ ## push - Pushes the built gem to Rubygems
30
+ push:
31
+ gem push *.gem
32
+
33
+ ## test - Test the project
34
+ test:
35
+ bundle exec rspec
36
+
37
+ .PHONY: help build clean fix install lint push test
data/README.md CHANGED
@@ -116,10 +116,13 @@ API Documentation can be found at: <https://easypost.com/docs/api>.
116
116
 
117
117
  ```bash
118
118
  # Install dependencies
119
- bundle install
119
+ make install
120
+
121
+ # Lint project
122
+ make lint
120
123
 
121
124
  # Run tests (coverage is generated on a successful test suite run)
122
- EASYPOST_TEST_API_KEY=123... EASYPOST_PROD_API_KEY=123... bundle exec rspec
125
+ EASYPOST_TEST_API_KEY=123... EASYPOST_PROD_API_KEY=123... make test
123
126
  ```
124
127
 
125
128
  ### Testing
data/VERSION CHANGED
@@ -1 +1 @@
1
- 4.3.0
1
+ 4.6.0
data/easypost.gemspec CHANGED
@@ -21,6 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.require_paths = ['lib']
22
22
  spec.required_ruby_version = '>= 2.5'
23
23
 
24
+ spec.add_development_dependency 'brakeman', '~> 5.2'
24
25
  spec.add_development_dependency 'pry', '~> 0.14'
25
26
  spec.add_development_dependency 'rake', '~> 13.0'
26
27
  spec.add_development_dependency 'rspec', '~> 3.10'
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Billing class that users can manage their payment and fund
4
+ class EasyPost::Billing < EasyPost::Resource
5
+ # Fund your EasyPost wallet by charging your primary or secondary card on file.
6
+ def self.fund_wallet(amount, primary_or_secondary = 'primary', api_key = nil)
7
+ payment_info = EasyPost::Billing.get_payment_method_info(primary_or_secondary.downcase)
8
+ endpoint = payment_info[0]
9
+ payment_id = payment_info[1]
10
+
11
+ wrapped_params = { amount: amount }
12
+ EasyPost.make_request(:post, "#{endpoint}/#{payment_id}/charges", api_key, wrapped_params)
13
+
14
+ # Return true if succeeds, an error will be thrown if it fails
15
+ true
16
+ end
17
+
18
+ # Delete a payment method.
19
+ def self.delete_payment_method(primary_or_secondary, api_key = nil)
20
+ payment_info = EasyPost::Billing.get_payment_method_info(primary_or_secondary.downcase)
21
+ endpoint = payment_info[0]
22
+ payment_id = payment_info[1]
23
+
24
+ EasyPost.make_request(:delete, "#{endpoint}/#{payment_id}", api_key)
25
+
26
+ # Return true if succeeds, an error will be thrown if it fails
27
+ true
28
+ end
29
+
30
+ # Retrieve all payment methods.
31
+ def self.retrieve_payment_methods(api_key = nil)
32
+ response = EasyPost.make_request(:get, '/v2/payment_methods', api_key)
33
+
34
+ if response['id'].nil?
35
+ raise EasyPost::Error.new('Billing has not been setup for this user. Please add a payment method.')
36
+ end
37
+
38
+ EasyPost::Util.convert_to_easypost_object(response, api_key)
39
+ end
40
+
41
+ # Get payment method info (type of the payment method and ID of the payment method)
42
+ private_class_method def self.get_payment_method_info(primary_or_secondary)
43
+ payment_methods = EasyPost::Billing.retrieve_payment_methods
44
+ payment_method_map = {
45
+ 'primary' => 'primary_payment_method',
46
+ 'secondary' => 'secondary_payment_method',
47
+ }
48
+
49
+ payment_method_to_use = payment_method_map[primary_or_secondary]
50
+
51
+ error_string = 'The chosen payment method is not valid. Please try again.'
52
+ raise EasyPost::Error.new(error_string) if payment_methods[payment_method_to_use].nil?
53
+
54
+ payment_method_id = payment_methods[payment_method_to_use]['id']
55
+
56
+ unless payment_method_id.nil?
57
+ if payment_method_id.start_with?('card_')
58
+ endpoint = '/v2/credit_cards'
59
+ elsif payment_method_id.start_with?('bank_')
60
+ endpoint = '/v2/bank_accounts'
61
+ else
62
+ raise EasyPost::Error.new(error_string)
63
+ end
64
+ end
65
+
66
+ [endpoint, payment_method_id]
67
+ end
68
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ # The CarbonOffset object is a summary of carbon offset data for a given rate, including grams, price and currency
4
+ class EasyPost::CarbonOffset < EasyPost::Resource
5
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ # PaymentMethod objects represent a payment method of a user.
4
+ class EasyPost::PaymentMethod < EasyPost::Resource
5
+ # <b>DEPRECATED:</b> Please use <tt>Billing class</tt> instead.
6
+ # Deprecated: v4.5.0 - v6.0.0
7
+ def self.all(api_key = nil)
8
+ warn '[DEPRECATION] `all` is deprecated. Please use `Billing.retrieve_payment_methods` instead.'
9
+ EasyPost::Billing.retrieve_payment_methods(api_key)
10
+ end
11
+ end
@@ -97,7 +97,7 @@ class EasyPost::Resource < EasyPost::EasyPostObject
97
97
 
98
98
  wrapped_params = { self.class.class_name => values }
99
99
 
100
- response = EasyPost.make_request(:put, url, @api_key, wrapped_params)
100
+ response = EasyPost.make_request(:patch, url, @api_key, wrapped_params)
101
101
  refresh_from(response, api_key)
102
102
  end
103
103
  self
@@ -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(params = {})
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
 
@@ -112,4 +128,19 @@ class EasyPost::Shipment < EasyPost::Resource
112
128
 
113
129
  lowest_smartrate
114
130
  end
131
+
132
+ # Generate a form for a Shipment.
133
+ def generate_form(form_type, form_options = {})
134
+ params = {}
135
+ params[:type] = form_type
136
+ merged_params = params.merge(form_options)
137
+ wrapped_params = {
138
+ form: merged_params,
139
+ }
140
+
141
+ response = EasyPost.make_request(:post, "#{url}/forms", @api_key, wrapped_params)
142
+ refresh_from(response, @api_key)
143
+
144
+ self
145
+ end
115
146
  end
data/lib/easypost/user.rb CHANGED
@@ -16,7 +16,7 @@ class EasyPost::User < EasyPost::Resource
16
16
 
17
17
  wrapped_params = { user: values }
18
18
 
19
- response = EasyPost.make_request(:put, url, @api_key, wrapped_params)
19
+ response = EasyPost.make_request(:patch, url, @api_key, wrapped_params)
20
20
  refresh_from(response, api_key)
21
21
  end
22
22
  self
data/lib/easypost/util.rb CHANGED
@@ -2,6 +2,91 @@
2
2
 
3
3
  # Internal utilities helpful for this libraries operation.
4
4
  module EasyPost::Util
5
+ attr_accessor :os_name, :os_version, :os_arch
6
+
7
+ BY_PREFIX = {
8
+ 'adr' => EasyPost::Address,
9
+ 'batch' => EasyPost::Batch,
10
+ 'brd' => EasyPost::Brand,
11
+ 'ca' => EasyPost::CarrierAccount,
12
+ 'cstinfo' => EasyPost::CustomsInfo,
13
+ 'cstitem' => EasyPost::CustomsItem,
14
+ 'es' => EasyPost::Beta::EndShipper,
15
+ 'evt' => EasyPost::Event,
16
+ 'hook' => EasyPost::Webhook,
17
+ 'ins' => EasyPost::Insurance,
18
+ 'order' => EasyPost::Order,
19
+ 'pickup' => EasyPost::Pickup,
20
+ 'pickuprate' => EasyPost::PickupRate,
21
+ 'pl' => EasyPost::PostageLabel,
22
+ 'plrep' => EasyPost::Report,
23
+ 'prcl' => EasyPost::Parcel,
24
+ 'rate' => EasyPost::Rate,
25
+ 'refrep' => EasyPost::Report,
26
+ 'rfnd' => EasyPost::Refund,
27
+ 'sf' => EasyPost::ScanForm,
28
+ 'shp' => EasyPost::Shipment,
29
+ 'shpinvrep' => EasyPost::Report,
30
+ 'shprep' => EasyPost::Report,
31
+ 'trk' => EasyPost::Tracker,
32
+ 'trkrep' => EasyPost::Report,
33
+ 'user' => EasyPost::User,
34
+ }.freeze
35
+
36
+ BY_TYPE = {
37
+ 'Address' => EasyPost::Address,
38
+ 'Batch' => EasyPost::Batch,
39
+ 'Brand' => EasyPost::Brand,
40
+ 'CarbonOffset' => EasyPost::CarbonOffset,
41
+ 'CarrierAccount' => EasyPost::CarrierAccount,
42
+ 'CustomsInfo' => EasyPost::CustomsInfo,
43
+ 'CustomsItem' => EasyPost::CustomsItem,
44
+ 'EndShipper' => EasyPost::Beta::EndShipper,
45
+ 'Event' => EasyPost::Event,
46
+ 'Insurance' => EasyPost::Insurance,
47
+ 'Order' => EasyPost::Order,
48
+ 'Parcel' => EasyPost::Parcel,
49
+ 'PaymentLogReport' => EasyPost::Report,
50
+ 'Pickup' => EasyPost::Pickup,
51
+ 'PickupRate' => EasyPost::PickupRate,
52
+ 'PostageLabel' => EasyPost::PostageLabel,
53
+ 'Rate' => EasyPost::Rate,
54
+ 'Referral' => EasyPost::Beta::Referral,
55
+ 'Refund' => EasyPost::Refund,
56
+ 'RefundReport' => EasyPost::Report,
57
+ 'Report' => EasyPost::Report,
58
+ 'ScanForm' => EasyPost::ScanForm,
59
+ 'Shipment' => EasyPost::Shipment,
60
+ 'ShipmentInvoiceReport' => EasyPost::Report,
61
+ 'ShipmentReport' => EasyPost::Report,
62
+ 'TaxIdentifier' => EasyPost::TaxIdentifier,
63
+ 'Tracker' => EasyPost::Tracker,
64
+ 'TrackerReport' => EasyPost::Report,
65
+ 'User' => EasyPost::User,
66
+ 'Webhook' => EasyPost::Webhook,
67
+ }.freeze
68
+
69
+ def self.os_name
70
+ case RUBY_PLATFORM
71
+ when /linux/i
72
+ 'Linux'
73
+ when /darwin/i
74
+ 'Darwin'
75
+ when /cygwin|mswin|mingw|bccwin|wince|emx/i
76
+ 'Windows'
77
+ else
78
+ 'Unknown'
79
+ end
80
+ end
81
+
82
+ def self.os_version
83
+ Gem::Platform.local.version
84
+ end
85
+
86
+ def self.os_arch
87
+ Gem::Platform.local.cpu
88
+ end
89
+
5
90
  # Form-encode a multi-layer dictionary to a one-layer dictionary.
6
91
  def self.form_encode_params(hash, parent_keys = [], parent_dict = {})
7
92
  result = parent_dict or {}
@@ -55,84 +140,23 @@ module EasyPost::Util
55
140
 
56
141
  # Convert data to an EasyPost Object.
57
142
  def self.convert_to_easypost_object(response, api_key, parent = nil, name = nil)
58
- types = {
59
- 'Address' => EasyPost::Address,
60
- 'Batch' => EasyPost::Batch,
61
- 'Brand' => EasyPost::Brand,
62
- 'CarrierAccount' => EasyPost::CarrierAccount,
63
- 'CustomsInfo' => EasyPost::CustomsInfo,
64
- 'CustomsItem' => EasyPost::CustomsItem,
65
- 'EndShipper' => EasyPost::Beta::EndShipper,
66
- 'Event' => EasyPost::Event,
67
- 'Insurance' => EasyPost::Insurance,
68
- 'Order' => EasyPost::Order,
69
- 'Parcel' => EasyPost::Parcel,
70
- 'PaymentLogReport' => EasyPost::Report,
71
- 'Pickup' => EasyPost::Pickup,
72
- 'PickupRate' => EasyPost::PickupRate,
73
- 'PostageLabel' => EasyPost::PostageLabel,
74
- 'Rate' => EasyPost::Rate,
75
- 'Referral' => EasyPost::Beta::Referral,
76
- 'Refund' => EasyPost::Refund,
77
- 'RefundReport' => EasyPost::Report,
78
- 'Report' => EasyPost::Report,
79
- 'ScanForm' => EasyPost::ScanForm,
80
- 'Shipment' => EasyPost::Shipment,
81
- 'ShipmentInvoiceReport' => EasyPost::Report,
82
- 'ShipmentReport' => EasyPost::Report,
83
- 'TaxIdentifier' => EasyPost::TaxIdentifier,
84
- 'Tracker' => EasyPost::Tracker,
85
- 'TrackerReport' => EasyPost::Report,
86
- 'User' => EasyPost::User,
87
- 'Webhook' => EasyPost::Webhook,
88
- }
89
-
90
- prefixes = {
91
- 'adr' => EasyPost::Address,
92
- 'batch' => EasyPost::Batch,
93
- 'brd' => EasyPost::Brand,
94
- 'ca' => EasyPost::CarrierAccount,
95
- 'cstinfo' => EasyPost::CustomsInfo,
96
- 'cstitem' => EasyPost::CustomsItem,
97
- 'es' => EasyPost::Beta::EndShipper,
98
- 'evt' => EasyPost::Event,
99
- 'hook' => EasyPost::Webhook,
100
- 'ins' => EasyPost::Insurance,
101
- 'order' => EasyPost::Order,
102
- 'pickup' => EasyPost::Pickup,
103
- 'pickuprate' => EasyPost::PickupRate,
104
- 'pl' => EasyPost::PostageLabel,
105
- 'plrep' => EasyPost::Report,
106
- 'prcl' => EasyPost::Parcel,
107
- 'rate' => EasyPost::Rate,
108
- 'refrep' => EasyPost::Report,
109
- 'rfnd' => EasyPost::Refund,
110
- 'sf' => EasyPost::ScanForm,
111
- 'shp' => EasyPost::Shipment,
112
- 'shpinvrep' => EasyPost::Report,
113
- 'shprep' => EasyPost::Report,
114
- 'trk' => EasyPost::Tracker,
115
- 'trkrep' => EasyPost::Report,
116
- 'user' => EasyPost::User,
117
- }
118
-
119
143
  case response
120
144
  when Array
121
145
  response.map { |i| convert_to_easypost_object(i, api_key, parent) }
122
146
  when Hash
123
147
  if (cls_name = response[:object])
124
- cls = types[cls_name]
148
+ cls = BY_TYPE[cls_name]
125
149
  elsif response[:id]
126
150
  if response[:id].index('_').nil?
127
151
  cls = EasyPost::EasyPostObject
128
152
  elsif (cls_prefix = response[:id][0..response[:id].index('_')])
129
- cls = prefixes[cls_prefix[0..-2]]
153
+ cls = BY_PREFIX[cls_prefix[0..-2]]
130
154
  end
131
155
  elsif response['id']
132
156
  if response['id'].index('_').nil?
133
157
  cls = EasyPost::EasyPostObject
134
158
  elsif (cls_prefix = response['id'][0..response['id'].index('_')])
135
- cls = prefixes[cls_prefix[0..-2]]
159
+ cls = BY_PREFIX[cls_prefix[0..-2]]
136
160
  end
137
161
  end
138
162
 
@@ -12,7 +12,7 @@ class EasyPost::Webhook < EasyPost::Resource
12
12
 
13
13
  instance_url = "#{self.class.url}/#{CGI.escape(id)}"
14
14
 
15
- response = EasyPost.make_request(:put, instance_url, @api_key, params)
15
+ response = EasyPost.make_request(:patch, instance_url, @api_key, params)
16
16
  refresh_from(response, api_key)
17
17
 
18
18
  self
@@ -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
@@ -5,7 +5,6 @@ require 'cgi'
5
5
  require 'net/http'
6
6
 
7
7
  require 'easypost/version'
8
- require 'easypost/util'
9
8
  require 'easypost/object'
10
9
  require 'easypost/resource'
11
10
  require 'easypost/error'
@@ -15,7 +14,9 @@ require 'easypost/connection'
15
14
  require 'easypost/address'
16
15
  require 'easypost/api_key'
17
16
  require 'easypost/batch'
17
+ require 'easypost/billing'
18
18
  require 'easypost/brand'
19
+ require 'easypost/carbon_offset'
19
20
  require 'easypost/carrier_account'
20
21
  require 'easypost/carrier_type'
21
22
  require 'easypost/customs_info'
@@ -38,9 +39,10 @@ require 'easypost/user'
38
39
  require 'easypost/webhook'
39
40
  require 'easypost/beta'
40
41
 
42
+ require 'easypost/util'
43
+
41
44
  module EasyPost
42
45
  DEFAULT_API_BASE = 'https://api.easypost.com'
43
- DEFAULT_USER_AGENT = "EasyPost/v2 RubyClient/#{EasyPost::VERSION} Ruby/#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"
44
46
 
45
47
  class << self
46
48
  attr_accessor :api_key, :api_base
@@ -49,10 +51,17 @@ module EasyPost
49
51
 
50
52
  self.api_base = DEFAULT_API_BASE
51
53
 
54
+ def self.user_agent
55
+ @user_agent ||=
56
+ "EasyPost/v2 RubyClient/#{EasyPost::VERSION} Ruby/#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL} " \
57
+ "OS/#{EasyPost::Util.os_name} OSVersion/#{EasyPost::Util.os_version} " \
58
+ "OSArch/#{EasyPost::Util.os_arch}"
59
+ end
60
+
52
61
  def self.default_headers
53
62
  @default_headers ||= {
54
63
  'Content-Type' => 'application/json',
55
- 'User-Agent' => EasyPost::DEFAULT_USER_AGENT,
64
+ 'User-Agent' => user_agent,
56
65
  }
57
66
  end
58
67
 
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easypost
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.3.0
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-05-19 00:00:00.000000000 Z
11
+ date: 2022-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: brakeman
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '5.2'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '5.2'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: pry
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -143,6 +157,8 @@ executables:
143
157
  extensions: []
144
158
  extra_rdoc_files: []
145
159
  files:
160
+ - ".gitattributes"
161
+ - ".github/CODEOWNERS"
146
162
  - ".github/ISSUE_TEMPLATE/bug_report.yml"
147
163
  - ".github/ISSUE_TEMPLATE/feature_request.yml"
148
164
  - ".github/PULL_REQUEST_TEMPLATE.md"
@@ -154,6 +170,7 @@ files:
154
170
  - CONTRIBUTING.md
155
171
  - Gemfile
156
172
  - LICENSE
173
+ - Makefile
157
174
  - README.md
158
175
  - Rakefile
159
176
  - SECURITY.md
@@ -170,7 +187,9 @@ files:
170
187
  - lib/easypost/beta.rb
171
188
  - lib/easypost/beta/end_shipper.rb
172
189
  - lib/easypost/beta/referral.rb
190
+ - lib/easypost/billing.rb
173
191
  - lib/easypost/brand.rb
192
+ - lib/easypost/carbon_offset.rb
174
193
  - lib/easypost/carrier_account.rb
175
194
  - lib/easypost/carrier_type.rb
176
195
  - lib/easypost/connection.rb
@@ -182,6 +201,7 @@ files:
182
201
  - lib/easypost/object.rb
183
202
  - lib/easypost/order.rb
184
203
  - lib/easypost/parcel.rb
204
+ - lib/easypost/payment_method.rb
185
205
  - lib/easypost/pickup.rb
186
206
  - lib/easypost/pickup_rate.rb
187
207
  - lib/easypost/postage_label.rb
@@ -216,7 +236,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
216
236
  - !ruby/object:Gem::Version
217
237
  version: '0'
218
238
  requirements: []
219
- rubygems_version: 3.3.7
239
+ rubygems_version: 3.3.11
220
240
  signing_key:
221
241
  specification_version: 4
222
242
  summary: EasyPost Ruby Client Library