easypost 4.2.0 → 4.4.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: 18f330382213345312caf4cb5981ad506f3d882aaf2f78f556598d5201e28d94
4
- data.tar.gz: 4a750f473664d70f8d72f252a875e4eab75d256ffe0925fc5027915ecfc4cd3e
3
+ metadata.gz: c07c842f7ff2eb209a6f447259afce469b6e1f0f481ea2bf68585869167ea8f9
4
+ data.tar.gz: 0ffb89bcb615cd1835f12e70d3c23ffa9ca9033daddddaad9db20a363f483212
5
5
  SHA512:
6
- metadata.gz: 96e3c87b8ff96f797ca25e42e2dc61ce8c814826fca95b7f80506aa96624a5df58fe0f762fb87eab71f0e89422996d31d88f153b434c11268b220893731438a1
7
- data.tar.gz: 2ea7ea89d3cedea7222de7cbe41af96ef0b912b23e0409cfa2ffc5576915553ed578f7dfb315d0870bf5e6391ed5a7eff396eed7972db4e814223faa3152bc56
6
+ metadata.gz: f03686d79b7d2023c26dc3c69362955465f3f99efc9b666d101a3499697ed155061afa2e8a47767bd83ae78bdd265d5363339ad4fb7686f47e5cff472483fa6a
7
+ data.tar.gz: 25f79bcc1b8c745ae9556c675d3aad56a06518853b4389081325170d2c1c1e425906bb8ded8925d40805ef961c5ccea3394da7bfe1f845117a8701f80526d526
data/.gitattributes ADDED
@@ -0,0 +1,4 @@
1
+ * text=auto
2
+
3
+ spec/cassettes/**/* -diff
4
+ spec/cassettes/**/* linguist-generated
@@ -20,7 +20,7 @@ jobs:
20
20
  ruby-version: ${{ matrix.rubyversion }}
21
21
  bundler-cache: true
22
22
  - name: run tests
23
- run: 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/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## v4.4.0 (2022-07-11)
4
+
5
+ - Adds `Billing.retrieve_payment_methods()`, `Billing.fund_wallet()`, and `Billing.delete_payment_method()` functions
6
+ - Captures OS information in the user-agent header for easier debugging
7
+ - 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
8
+
9
+ ## v4.3.0 (2022-05-19)
10
+
11
+ - Adds the `EndShipper` Beta class with `create`, `retrieve`, `all`, and `save` functions
12
+ - Requests will now fail fast with an error if an API key is not provided instead of making a live API call with no key
13
+ - Fixes a bug where the library could not properly parse the response of deleting a child user
14
+ - Fixes a bug where you could not update a webhook due to a `wrong number of arguments` error
15
+
16
+ ## v4.2.1 (2022-05-11)
17
+
18
+ - Corrects the `Beta` namespace for the new Referral class
19
+
3
20
  ## v4.2.0 (2022-05-09)
4
21
 
5
22
  - Adds a `lowest_rate()` function to Orders and Pickups
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
@@ -3,7 +3,7 @@
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
4
  [![Gem Version](https://badge.fury.io/rb/easypost.svg)](https://badge.fury.io/rb/easypost)
5
5
 
6
- EasyPost, the simple shipping solution. You can sign up for an account at https://easypost.com.
6
+ EasyPost, the simple shipping solution. You can sign up for an account at <https://easypost.com>.
7
7
 
8
8
  ## Install
9
9
 
@@ -110,24 +110,41 @@ end
110
110
 
111
111
  ## Documentation
112
112
 
113
- API Documentation can be found at: https://easypost.com/docs/api.
113
+ API Documentation can be found at: <https://easypost.com/docs/api>.
114
114
 
115
115
  ## Development
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
126
129
 
127
130
  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.
128
131
 
129
- 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.
132
+ **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.
133
+
134
+ **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.
135
+
136
+ **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).
137
+
138
+ #### Unit Test API Keys
139
+
140
+ The following are required on every test run:
141
+
142
+ - `EASYPOST_TEST_API_KEY`
143
+ - `EASYPOST_PROD_API_KEY`
144
+
145
+ The following are required when you need to re-record cassettes for applicable tests (fallback values are used otherwise):
130
146
 
131
- 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** which has a fallback value to our internal testing user's ID. If you are a non-EasyPost employee and are re-recording cassettes, you may need to provide the `USPS_CARRIER_ACCOUNT_ID` environment variable with the ID associated with your USPS account (which will be associated with your API keys in use) for tests that use this fixture.
147
+ - `USPS_CARRIER_ACCOUNT_ID` (eg: one-call buying a shipment for non-EasyPost employees)
148
+ - `REFERRAL_USER_PROD_API_KEY` (eg: adding a credit card to a referral user)
132
149
 
133
- **Note on dates:** Some fixtures use hard-coded dates that may need to be incremented if cassettes get re-recorded (such as reports or pickups).
150
+ Some tests may require a 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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 4.2.0
1
+ 4.4.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,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ # EndShipper objects are fully-qualified Address objects that require all parameters and get verified upon creation.
4
+ class EasyPost::Beta::EndShipper < EasyPost::Resource
5
+ # Create an EndShipper object.
6
+ def self.create(params = {}, api_key = nil)
7
+ response = EasyPost.make_request(:post, '/beta/end_shippers', api_key, { address: params })
8
+ EasyPost::Util.convert_to_easypost_object(response, api_key)
9
+ end
10
+
11
+ # Retrieves an EndShipper object.
12
+ def self.retrieve(id, params = {}, api_key = nil)
13
+ response = EasyPost.make_request(:get, "/beta/end_shippers/#{id}", api_key, params)
14
+ EasyPost::Util.convert_to_easypost_object(response, api_key)
15
+ end
16
+
17
+ # Retrieves a list of EndShipper objects.
18
+ def self.all(params = {}, api_key = nil)
19
+ response = EasyPost.make_request(:get, '/beta/end_shippers', api_key, params)
20
+ EasyPost::Util.convert_to_easypost_object(response, api_key)
21
+ end
22
+
23
+ # Updates (saves) an EndShipper object. This requires all parameters to be set.
24
+ def save
25
+ if @unsaved_values.length.positive?
26
+ values = {}
27
+ @unsaved_values.each { |k| values[k] = @values[k] }
28
+
29
+ wrapped_params = { address: values }
30
+
31
+ response = EasyPost.make_request(:put, "/beta/end_shippers/#{id}", @api_key, wrapped_params)
32
+ refresh_from(response, api_key)
33
+ end
34
+ self
35
+ end
36
+ end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class EasyPost::BetaReferral < EasyPost::Resource
3
+ # Referral objects are User objects created from a Partner user.
4
+ class EasyPost::Beta::Referral < EasyPost::Resource
4
5
  # Create a referral user. This function requires the Partner User's API key.
5
6
  def self.create(params = {}, api_key = nil)
6
7
  response = EasyPost.make_request(:post, '/beta/referral_customers', api_key, { user: params })
@@ -14,7 +15,7 @@ class EasyPost::BetaReferral < EasyPost::Resource
14
15
  email: email,
15
16
  },
16
17
  }
17
- _ = EasyPost.make_request(:put, "/beta/referral_customers/#{user_id}", api_key, wrapped_params)
18
+ EasyPost.make_request(:put, "/beta/referral_customers/#{user_id}", api_key, wrapped_params)
18
19
 
19
20
  # return true if API succeeds, else an error is throw if it fails.
20
21
  true
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EasyPost::Beta
4
+ end
5
+
6
+ require_relative 'beta/end_shipper'
7
+ require_relative 'beta/referral'
@@ -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
@@ -10,6 +10,10 @@ EasyPost::Connection = Struct.new(:uri, :config, keyword_init: true) do
10
10
  # @raise [EasyPost::Error] if the response has a non-2xx status code
11
11
  # @return [Hash] JSON object parsed from the response body
12
12
  def call(method, path, api_key = nil, body = nil)
13
+ if api_key.nil?
14
+ raise EasyPost::Error, 'No API key provided.'
15
+ end
16
+
13
17
  connection =
14
18
  if config[:proxy]
15
19
  proxy_uri = URI(config[:proxy])
@@ -51,11 +55,12 @@ EasyPost::Connection = Struct.new(:uri, :config, keyword_init: true) do
51
55
  request['Authorization'] = EasyPost.authorization(api_key) if api_key
52
56
 
53
57
  response = connection.request(request)
58
+ response_is_json = response['Content-Type'] ? response['Content-Type'].start_with?('application/json') : false
54
59
 
55
60
  EasyPost.parse_response(
56
61
  status: response.code.to_i,
57
62
  body: response.body,
58
- json: response['Content-Type'].start_with?('application/json'),
63
+ json: response_is_json,
59
64
  )
60
65
  end
61
66
  end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ # PaymentMethod objects represent a payment method of a user.
4
+ class EasyPost::PaymentMethod < EasyPost::Resource
5
+ # Retrieve all payment methods.
6
+ def self.all(api_key = nil)
7
+ response = EasyPost.make_request(:get, url, api_key)
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)
14
+ end
15
+ 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
data/lib/easypost/user.rb CHANGED
@@ -16,12 +16,18 @@ 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
23
23
  end
24
24
 
25
+ # Delete a User.
26
+ def delete
27
+ EasyPost.make_request(:delete, url, @api_key)
28
+ self
29
+ end
30
+
25
31
  # Retrieve the authenticated User.
26
32
  def self.retrieve_me
27
33
  all
data/lib/easypost/util.rb CHANGED
@@ -2,6 +2,90 @@
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
+ 'CarrierAccount' => EasyPost::CarrierAccount,
41
+ 'CustomsInfo' => EasyPost::CustomsInfo,
42
+ 'CustomsItem' => EasyPost::CustomsItem,
43
+ 'EndShipper' => EasyPost::Beta::EndShipper,
44
+ 'Event' => EasyPost::Event,
45
+ 'Insurance' => EasyPost::Insurance,
46
+ 'Order' => EasyPost::Order,
47
+ 'Parcel' => EasyPost::Parcel,
48
+ 'PaymentLogReport' => EasyPost::Report,
49
+ 'Pickup' => EasyPost::Pickup,
50
+ 'PickupRate' => EasyPost::PickupRate,
51
+ 'PostageLabel' => EasyPost::PostageLabel,
52
+ 'Rate' => EasyPost::Rate,
53
+ 'Referral' => EasyPost::Beta::Referral,
54
+ 'Refund' => EasyPost::Refund,
55
+ 'RefundReport' => EasyPost::Report,
56
+ 'Report' => EasyPost::Report,
57
+ 'ScanForm' => EasyPost::ScanForm,
58
+ 'Shipment' => EasyPost::Shipment,
59
+ 'ShipmentInvoiceReport' => EasyPost::Report,
60
+ 'ShipmentReport' => EasyPost::Report,
61
+ 'TaxIdentifier' => EasyPost::TaxIdentifier,
62
+ 'Tracker' => EasyPost::Tracker,
63
+ 'TrackerReport' => EasyPost::Report,
64
+ 'User' => EasyPost::User,
65
+ 'Webhook' => EasyPost::Webhook,
66
+ }.freeze
67
+
68
+ def self.os_name
69
+ case RUBY_PLATFORM
70
+ when /linux/i
71
+ 'Linux'
72
+ when /darwin/i
73
+ 'Darwin'
74
+ when /cygwin|mswin|mingw|bccwin|wince|emx/i
75
+ 'Windows'
76
+ else
77
+ 'Unknown'
78
+ end
79
+ end
80
+
81
+ def self.os_version
82
+ Gem::Platform.local.version
83
+ end
84
+
85
+ def self.os_arch
86
+ Gem::Platform.local.cpu
87
+ end
88
+
5
89
  # Form-encode a multi-layer dictionary to a one-layer dictionary.
6
90
  def self.form_encode_params(hash, parent_keys = [], parent_dict = {})
7
91
  result = parent_dict or {}
@@ -55,81 +139,23 @@ module EasyPost::Util
55
139
 
56
140
  # Convert data to an EasyPost Object.
57
141
  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
- 'Event' => EasyPost::Event,
66
- 'Insurance' => EasyPost::Insurance,
67
- 'Order' => EasyPost::Order,
68
- 'Parcel' => EasyPost::Parcel,
69
- 'PaymentLogReport' => EasyPost::Report,
70
- 'Pickup' => EasyPost::Pickup,
71
- 'PickupRate' => EasyPost::PickupRate,
72
- 'PostageLabel' => EasyPost::PostageLabel,
73
- 'Rate' => EasyPost::Rate,
74
- 'Refund' => EasyPost::Refund,
75
- 'RefundReport' => EasyPost::Report,
76
- 'Report' => EasyPost::Report,
77
- 'ScanForm' => EasyPost::ScanForm,
78
- 'Shipment' => EasyPost::Shipment,
79
- 'TaxIdentifier' => EasyPost::TaxIdentifier,
80
- 'ShipmentInvoiceReport' => EasyPost::Report,
81
- 'ShipmentReport' => EasyPost::Report,
82
- 'Tracker' => EasyPost::Tracker,
83
- 'TrackerReport' => EasyPost::Report,
84
- 'User' => EasyPost::User,
85
- 'Webhook' => EasyPost::Webhook,
86
- }
87
-
88
- prefixes = {
89
- 'adr' => EasyPost::Address,
90
- 'batch' => EasyPost::Batch,
91
- 'brd' => EasyPost::Brand,
92
- 'ca' => EasyPost::CarrierAccount,
93
- 'cstinfo' => EasyPost::CustomsInfo,
94
- 'cstitem' => EasyPost::CustomsItem,
95
- 'evt' => EasyPost::Event,
96
- 'hook' => EasyPost::Webhook,
97
- 'ins' => EasyPost::Insurance,
98
- 'order' => EasyPost::Order,
99
- 'pickup' => EasyPost::Pickup,
100
- 'pickuprate' => EasyPost::PickupRate,
101
- 'pl' => EasyPost::PostageLabel,
102
- 'plrep' => EasyPost::Report,
103
- 'prcl' => EasyPost::Parcel,
104
- 'rate' => EasyPost::Rate,
105
- 'refrep' => EasyPost::Report,
106
- 'rfnd' => EasyPost::Refund,
107
- 'sf' => EasyPost::ScanForm,
108
- 'shp' => EasyPost::Shipment,
109
- 'shpinvrep' => EasyPost::Report,
110
- 'shprep' => EasyPost::Report,
111
- 'trk' => EasyPost::Tracker,
112
- 'trkrep' => EasyPost::Report,
113
- 'user' => EasyPost::User,
114
- }
115
-
116
142
  case response
117
143
  when Array
118
144
  response.map { |i| convert_to_easypost_object(i, api_key, parent) }
119
145
  when Hash
120
146
  if (cls_name = response[:object])
121
- cls = types[cls_name]
147
+ cls = BY_TYPE[cls_name]
122
148
  elsif response[:id]
123
149
  if response[:id].index('_').nil?
124
150
  cls = EasyPost::EasyPostObject
125
151
  elsif (cls_prefix = response[:id][0..response[:id].index('_')])
126
- cls = prefixes[cls_prefix[0..-2]]
152
+ cls = BY_PREFIX[cls_prefix[0..-2]]
127
153
  end
128
154
  elsif response['id']
129
155
  if response['id'].index('_').nil?
130
156
  cls = EasyPost::EasyPostObject
131
157
  elsif (cls_prefix = response['id'][0..response['id'].index('_')])
132
- cls = prefixes[cls_prefix[0..-2]]
158
+ cls = BY_PREFIX[cls_prefix[0..-2]]
133
159
  end
134
160
  end
135
161
 
@@ -12,8 +12,8 @@ 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)
16
- refresh_from(response, api_key, true)
15
+ response = EasyPost.make_request(:patch, instance_url, @api_key, params)
16
+ refresh_from(response, api_key)
17
17
 
18
18
  self
19
19
  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,6 +14,7 @@ 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
19
  require 'easypost/carrier_account'
20
20
  require 'easypost/carrier_type'
@@ -36,11 +36,12 @@ require 'easypost/tax_identifier'
36
36
  require 'easypost/tracker'
37
37
  require 'easypost/user'
38
38
  require 'easypost/webhook'
39
- require 'easypost/beta/beta'
39
+ require 'easypost/beta'
40
+
41
+ require 'easypost/util'
40
42
 
41
43
  module EasyPost
42
44
  DEFAULT_API_BASE = 'https://api.easypost.com'
43
- DEFAULT_USER_AGENT = "EasyPost/v2 RubyClient/#{EasyPost::VERSION} Ruby/#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"
44
45
 
45
46
  class << self
46
47
  attr_accessor :api_key, :api_base
@@ -49,10 +50,17 @@ module EasyPost
49
50
 
50
51
  self.api_base = DEFAULT_API_BASE
51
52
 
53
+ def self.user_agent
54
+ @user_agent ||=
55
+ "EasyPost/v2 RubyClient/#{EasyPost::VERSION} Ruby/#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL} " \
56
+ "OS/#{EasyPost::Util.os_name} OSVersion/#{EasyPost::Util.os_version} " \
57
+ "OSArch/#{EasyPost::Util.os_arch}"
58
+ end
59
+
52
60
  def self.default_headers
53
61
  @default_headers ||= {
54
62
  'Content-Type' => 'application/json',
55
- 'User-Agent' => EasyPost::DEFAULT_USER_AGENT,
63
+ 'User-Agent' => user_agent,
56
64
  }
57
65
  end
58
66
 
@@ -134,7 +142,7 @@ module EasyPost
134
142
  )
135
143
  end
136
144
 
137
- json ? JSON.parse(body) : body
145
+ json || !body.nil? && !body.match(/\A\s+\z/) ? JSON.parse(body) : body
138
146
  rescue JSON::ParserError
139
147
  raise "Invalid response object from API, unable to decode.\n#{body}"
140
148
  end
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.2.0
4
+ version: 4.4.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-09 00:00:00.000000000 Z
11
+ date: 2022-07-11 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,7 @@ executables:
143
157
  extensions: []
144
158
  extra_rdoc_files: []
145
159
  files:
160
+ - ".gitattributes"
146
161
  - ".github/ISSUE_TEMPLATE/bug_report.yml"
147
162
  - ".github/ISSUE_TEMPLATE/feature_request.yml"
148
163
  - ".github/PULL_REQUEST_TEMPLATE.md"
@@ -154,6 +169,7 @@ files:
154
169
  - CONTRIBUTING.md
155
170
  - Gemfile
156
171
  - LICENSE
172
+ - Makefile
157
173
  - README.md
158
174
  - Rakefile
159
175
  - SECURITY.md
@@ -167,8 +183,10 @@ files:
167
183
  - lib/easypost/address.rb
168
184
  - lib/easypost/api_key.rb
169
185
  - lib/easypost/batch.rb
170
- - lib/easypost/beta/beta.rb
171
- - lib/easypost/beta/beta_referral.rb
186
+ - lib/easypost/beta.rb
187
+ - lib/easypost/beta/end_shipper.rb
188
+ - lib/easypost/beta/referral.rb
189
+ - lib/easypost/billing.rb
172
190
  - lib/easypost/brand.rb
173
191
  - lib/easypost/carrier_account.rb
174
192
  - lib/easypost/carrier_type.rb
@@ -181,6 +199,7 @@ files:
181
199
  - lib/easypost/object.rb
182
200
  - lib/easypost/order.rb
183
201
  - lib/easypost/parcel.rb
202
+ - lib/easypost/payment_method.rb
184
203
  - lib/easypost/pickup.rb
185
204
  - lib/easypost/pickup_rate.rb
186
205
  - lib/easypost/postage_label.rb
@@ -215,7 +234,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
215
234
  - !ruby/object:Gem::Version
216
235
  version: '0'
217
236
  requirements: []
218
- rubygems_version: 3.3.7
237
+ rubygems_version: 3.3.11
219
238
  signing_key:
220
239
  specification_version: 4
221
240
  summary: EasyPost Ruby Client Library
@@ -1,6 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'easypost/beta/beta_referral'
4
-
5
- module EasyPost::Beta
6
- end