Skip to content
Open
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
16 changes: 16 additions & 0 deletions lib/easypost/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,22 @@ def unsubscribe_all_response_hooks
EasyPost::Hooks.unsubscribe_all(:response)
end

# Make an API call to the EasyPost API
#
# This public, generic interface is useful for making arbitrary API calls to the EasyPost API that
# are not yet supported by the client library's services. When possible, the service for your use case
# should be used instead as it provides a more convenient and higher-level interface depending on the endpoint.
#
# @param method [Symbol] the HTTP Verb (get, post, put, patch, delete, etc.)
# @param endpoint [String] URI path of the resource
# @param params [Object] (nil) object to be used as the request parameters
# @return [EasyPost::Models::EasyPostObject] EasyPost object parsed from the response body
def make_api_call(method, endpoint, params = nil)
response = make_request(method, endpoint, params)

EasyPost::InternalUtilities::Json.convert_json_to_object(response)
end

private

def http_config
Expand Down

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

9 changes: 9 additions & 0 deletions spec/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -233,5 +233,14 @@
expect(EasyPost::Hooks.any_subscribers?(:response)).to eq(false)
end
end

it 'make an API call using the generic make_api_call method', :vcr do
client = described_class.new(api_key: ENV['EASYPOST_TEST_API_KEY'])

response = client.make_api_call(:get, '/addresses', { page_size: 1 })

expect(response['addresses'].length).to eq(1)
expect(response['addresses'][0]['object']).to eq('Address')
end
end
end