easypost 4.2.1 → 4.3.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: 9106fd21b72e0361b541741ba63630f8a2edb3d51cc2c911af06a2bd55c413df
4
- data.tar.gz: 9333539ff70f45618cb81b83dc427469048f7f2585deeb2ea044983dfa7b2955
3
+ metadata.gz: '02404008f0fc1078e49e1e418c5a208fbca5d646f31886c3c7fab55d932def70'
4
+ data.tar.gz: b8a2f7d514f9f22fa5b7ec3daf010adbfcc793c689954102b6ccbaafd7742e6a
5
5
  SHA512:
6
- metadata.gz: d59cd4adcf74d2018d6a76bedfc583d9b0cc79c88a28742c0cffb12fa5756552c99cc30e1c720e29f9b26ca4063b93873a5faf82d8adbdca1c9731005e75ff88
7
- data.tar.gz: ebce5da4126834f9b76c67b6912717047b8396eed2a51be10e0057860b4268487f3ff91eb7857b88976e0402bc352220af984cebd280774470de22cdca418f4c
6
+ metadata.gz: f6c9af835a6ff8ccb7574fd5a14ef96f850784e6600249a8441d23a521763ad3fb40d826cdce0f758cd4b87213a65c6ee733476d34824dabbb7fb09db2af0de0
7
+ data.tar.gz: c492ad0635133598e8535a2a0c72949b0acd6f0095b511bb91011c50cec67e6d8999b5358da8aa7ae4543e38a30bc029367d8c0cfd791e4944f46fac3cdf75d9
@@ -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 bundle exec rspec
24
24
  lint:
25
25
  runs-on: ubuntu-latest
26
26
  steps:
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## v4.3.0 (2022-05-19)
4
+
5
+ - Adds the `EndShipper` Beta class with `create`, `retrieve`, `all`, and `save` functions
6
+ - 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
7
+ - Fixes a bug where the library could not properly parse the response of deleting a child user
8
+ - Fixes a bug where you could not update a webhook due to a `wrong number of arguments` error
9
+
3
10
  ## v4.2.1 (2022-05-11)
4
11
 
5
12
  - Corrects the `Beta` namespace for the new Referral class
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,7 +110,7 @@ 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
 
@@ -126,8 +126,22 @@ EASYPOST_TEST_API_KEY=123... EASYPOST_PROD_API_KEY=123... bundle exec rspec
126
126
 
127
127
  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
128
 
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.
129
+ **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.
130
130
 
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.
131
+ **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.
132
132
 
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).
133
+ **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).
134
+
135
+ #### Unit Test API Keys
136
+
137
+ The following are required on every test run:
138
+
139
+ - `EASYPOST_TEST_API_KEY`
140
+ - `EASYPOST_PROD_API_KEY`
141
+
142
+ The following are required when you need to re-record cassettes for applicable tests (fallback values are used otherwise):
143
+
144
+ - `USPS_CARRIER_ACCOUNT_ID` (eg: one-call buying a shipment for non-EasyPost employees)
145
+ - `REFERRAL_USER_PROD_API_KEY` (eg: adding a credit card to a referral user)
146
+
147
+ 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.1
1
+ 4.3.0
@@ -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,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # Referral objects are User objects created from a Partner user.
3
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)
@@ -14,7 +15,7 @@ class EasyPost::Beta::Referral < 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
data/lib/easypost/beta.rb CHANGED
@@ -3,4 +3,5 @@
3
3
  module EasyPost::Beta
4
4
  end
5
5
 
6
+ require_relative 'beta/end_shipper'
6
7
  require_relative 'beta/referral'
@@ -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
data/lib/easypost/user.rb CHANGED
@@ -22,6 +22,12 @@ class EasyPost::User < EasyPost::Resource
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
@@ -62,6 +62,7 @@ module EasyPost::Util
62
62
  'CarrierAccount' => EasyPost::CarrierAccount,
63
63
  'CustomsInfo' => EasyPost::CustomsInfo,
64
64
  'CustomsItem' => EasyPost::CustomsItem,
65
+ 'EndShipper' => EasyPost::Beta::EndShipper,
65
66
  'Event' => EasyPost::Event,
66
67
  'Insurance' => EasyPost::Insurance,
67
68
  'Order' => EasyPost::Order,
@@ -71,14 +72,15 @@ module EasyPost::Util
71
72
  'PickupRate' => EasyPost::PickupRate,
72
73
  'PostageLabel' => EasyPost::PostageLabel,
73
74
  'Rate' => EasyPost::Rate,
75
+ 'Referral' => EasyPost::Beta::Referral,
74
76
  'Refund' => EasyPost::Refund,
75
77
  'RefundReport' => EasyPost::Report,
76
78
  'Report' => EasyPost::Report,
77
79
  'ScanForm' => EasyPost::ScanForm,
78
80
  'Shipment' => EasyPost::Shipment,
79
- 'TaxIdentifier' => EasyPost::TaxIdentifier,
80
81
  'ShipmentInvoiceReport' => EasyPost::Report,
81
82
  'ShipmentReport' => EasyPost::Report,
83
+ 'TaxIdentifier' => EasyPost::TaxIdentifier,
82
84
  'Tracker' => EasyPost::Tracker,
83
85
  'TrackerReport' => EasyPost::Report,
84
86
  'User' => EasyPost::User,
@@ -92,6 +94,7 @@ module EasyPost::Util
92
94
  'ca' => EasyPost::CarrierAccount,
93
95
  'cstinfo' => EasyPost::CustomsInfo,
94
96
  'cstitem' => EasyPost::CustomsItem,
97
+ 'es' => EasyPost::Beta::EndShipper,
95
98
  'evt' => EasyPost::Event,
96
99
  'hook' => EasyPost::Webhook,
97
100
  'ins' => EasyPost::Insurance,
@@ -13,7 +13,7 @@ class EasyPost::Webhook < EasyPost::Resource
13
13
  instance_url = "#{self.class.url}/#{CGI.escape(id)}"
14
14
 
15
15
  response = EasyPost.make_request(:put, instance_url, @api_key, params)
16
- refresh_from(response, api_key, true)
16
+ refresh_from(response, api_key)
17
17
 
18
18
  self
19
19
  end
data/lib/easypost.rb CHANGED
@@ -134,7 +134,7 @@ module EasyPost
134
134
  )
135
135
  end
136
136
 
137
- json ? JSON.parse(body) : body
137
+ json || !body.nil? && !body.match(/\A\s+\z/) ? JSON.parse(body) : body
138
138
  rescue JSON::ParserError
139
139
  raise "Invalid response object from API, unable to decode.\n#{body}"
140
140
  end
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.2.1
4
+ version: 4.3.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-11 00:00:00.000000000 Z
11
+ date: 2022-05-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry
@@ -168,6 +168,7 @@ files:
168
168
  - lib/easypost/api_key.rb
169
169
  - lib/easypost/batch.rb
170
170
  - lib/easypost/beta.rb
171
+ - lib/easypost/beta/end_shipper.rb
171
172
  - lib/easypost/beta/referral.rb
172
173
  - lib/easypost/brand.rb
173
174
  - lib/easypost/carrier_account.rb