Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
## Next Release (minor)

- Adds Ruby 3.4 support
- Fixes error parsing
- Allows for alternative format of `errors` field
- Corrects available properties of an `EasyPostError` and `ApiError` (`code` and `field` removed from `EasyPostError`, `message` unfurled and explicitly added to `ApiError`)
- Removes unused `Error` model
- Corrects the HTTP verb for updating a brand from `GET` to `PATCH`
- Removes the deprecated `create_list` tracker endpoint function as it is no longer available via API

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ docs:
bundle exec rdoc lib -o docs --title "EasyPost Ruby Docs"

## install-styleguide - Import the style guides (Unix only)
install-styleguide: | update-examples-submodule
install-styleguide: | init-examples-submodule
sh examples/symlink_directory_files.sh examples/style_guides/ruby .

## init-examples-submodule - Initialize the examples submodule
Expand Down
2 changes: 1 addition & 1 deletion lib/easypost/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def initialize(api_key:, read_timeout: 60, open_timeout: 30, api_base: 'https://
# @param endpoint [String] URI path of the resource
# @param params [Object] (nil) object to be used as the request parameters
# @param api_version [String] the version of API to hit
# @raise [EasyPost::Error] if the response has a non-2xx status code
# @raise [EasyPost::Errors::EasyPostError] if the response has a non-2xx status code
# @return [Hash] JSON object parsed from the response body
def make_request(
method,
Expand Down
2 changes: 1 addition & 1 deletion lib/easypost/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# @param path [String] URI path of the resource
# @param requested_api_key [String] ({EasyPost.api_key}) key set Authorization header.
# @param body [String] (nil) body of the request
# @raise [EasyPost::Error] if the response has a non-2xx status code
# @raise [EasyPost::Errors::EasyPostError] if the response has a non-2xx status code
# @return [Hash] JSON object parsed from the response body
def call(method, path, api_key = nil, body = nil)
raise EasyPost::Errors::MissingParameterError.new('api_key') if api_key.nil?
Expand Down
10 changes: 5 additions & 5 deletions lib/easypost/errors/api/api_error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
require 'easypost/constants'

class EasyPost::Errors::ApiError < EasyPost::Errors::EasyPostError
attr_reader :status_code, :code, :errors
attr_reader :message, :status_code, :code, :errors

def initialize(message, status_code = nil, error_code = nil, sub_errors = nil)
super message
message_list = []
EasyPost::Errors::ApiError.collect_error_messages(message, message_list)
@message = message_list.join(', ')
@status_code = status_code
@code = error_code
@errors = sub_errors
Expand Down Expand Up @@ -46,12 +49,9 @@ def self.handle_api_error(response)
# Try to parse the response body as JSON
begin
error_data = JSON.parse(response.body)['error']

error_message = error_data['message']
error_type = error_data['code']
errors = error_data['errors']&.map do |error|
EasyPost::Models::Error.from_api_error_response(error)
end
errors = error_data['errors']
rescue StandardError
error_message = response.code.to_s
error_type = EasyPost::Constants::API_ERROR_DETAILS_PARSING_ERROR
Expand Down
1 change: 0 additions & 1 deletion lib/easypost/models.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ module EasyPost::Models
require_relative 'models/customs_info'
require_relative 'models/customs_item'
require_relative 'models/end_shipper'
require_relative 'models/error'
require_relative 'models/event'
require_relative 'models/insurance'
require_relative 'models/order'
Expand Down
21 changes: 0 additions & 21 deletions lib/easypost/models/error.rb

This file was deleted.

16 changes: 16 additions & 0 deletions spec/address_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,23 @@
address = client.address.create(address_data)

expect(address).to be_an_instance_of(EasyPost::Models::Address)

# Delivery verification assertions
expect(address.verifications.delivery.success).to be false
# TODO: details is not deserializing correctly, related to the larger "double EasyPostObject" wrapping issue
# expect(address.verifications.delivery.details).to be_empty
expect(address.verifications.delivery.errors[0].code).to eq('E.ADDRESS.NOT_FOUND')
expect(address.verifications.delivery.errors[0].field).to eq('address')
expect(address.verifications.delivery.errors[0].suggestion).to be nil
expect(address.verifications.delivery.errors[0].message).to eq('Address not found')

# Zip4 verification assertions
expect(address.verifications.zip4.success).to be false
expect(address.verifications.zip4.details).to be nil
expect(address.verifications.zip4.errors[0].code).to eq('E.ADDRESS.NOT_FOUND')
expect(address.verifications.zip4.errors[0].field).to eq('address')
expect(address.verifications.zip4.errors[0].suggestion).to be nil
expect(address.verifications.zip4.errors[0].message).to eq('Address not found')
end

it 'creates an address with verify_strict param' do
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

Loading