Skip to content

Commit cad66a0

Browse files
Justintime50claude
andcommitted
feat: add a generic API request interface
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 95ba105 commit cad66a0

File tree

3 files changed

+93
-0
lines changed

3 files changed

+93
-0
lines changed

lib/easypost/client.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,22 @@ def unsubscribe_all_response_hooks
144144
EasyPost::Hooks.unsubscribe_all(:response)
145145
end
146146

147+
# Make an API call to the EasyPost API
148+
#
149+
# This public, generic interface is useful for making arbitrary API calls to the EasyPost API that
150+
# are not yet supported by the client library's services. When possible, the service for your use case
151+
# should be used instead as it provides a more convenient and higher-level interface depending on the endpoint.
152+
#
153+
# @param method [Symbol] the HTTP Verb (get, post, put, patch, delete, etc.)
154+
# @param endpoint [String] URI path of the resource
155+
# @param params [Object] (nil) object to be used as the request parameters
156+
# @return [EasyPost::Models::EasyPostObject] EasyPost object parsed from the response body
157+
def make_api_call(method, endpoint, params = nil)
158+
response = make_request(method, endpoint, params)
159+
160+
EasyPost::InternalUtilities::Json.convert_json_to_object(response)
161+
end
162+
147163
private
148164

149165
def http_config

spec/cassettes/client/EasyPost_Client_client_object_make_an_API_call_using_the_generic_make_api_call_method.yml

Lines changed: 68 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/client_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,5 +233,14 @@
233233
expect(EasyPost::Hooks.any_subscribers?(:response)).to eq(false)
234234
end
235235
end
236+
237+
it 'make an API call using the generic make_api_call method', :vcr do
238+
client = described_class.new(api_key: ENV['EASYPOST_TEST_API_KEY'])
239+
240+
response = client.make_api_call(:get, '/addresses', { page_size: 1 })
241+
242+
expect(response['addresses'].length).to eq(1)
243+
expect(response['addresses'][0]['object']).to eq('Address')
244+
end
236245
end
237246
end

0 commit comments

Comments
 (0)