From cad66a0d4ff61eea070ad36d1929f7347197a921 Mon Sep 17 00:00:00 2001 From: Justintime50 <39606064+Justintime50@users.noreply.github.com> Date: Thu, 12 Feb 2026 10:31:22 -0700 Subject: [PATCH] feat: add a generic API request interface Co-Authored-By: Claude Sonnet 4.5 --- lib/easypost/client.rb | 16 +++++ ...using_the_generic_make_api_call_method.yml | 68 +++++++++++++++++++ spec/client_spec.rb | 9 +++ 3 files changed, 93 insertions(+) create mode 100644 spec/cassettes/client/EasyPost_Client_client_object_make_an_API_call_using_the_generic_make_api_call_method.yml diff --git a/lib/easypost/client.rb b/lib/easypost/client.rb index da829db1..63056d25 100644 --- a/lib/easypost/client.rb +++ b/lib/easypost/client.rb @@ -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 diff --git a/spec/cassettes/client/EasyPost_Client_client_object_make_an_API_call_using_the_generic_make_api_call_method.yml b/spec/cassettes/client/EasyPost_Client_client_object_make_an_API_call_using_the_generic_make_api_call_method.yml new file mode 100644 index 00000000..84bf9d55 --- /dev/null +++ b/spec/cassettes/client/EasyPost_Client_client_object_make_an_API_call_using_the_generic_make_api_call_method.yml @@ -0,0 +1,68 @@ +--- +http_interactions: +- request: + method: get + uri: https://api.easypost.com/v2/addresses?page_size=1 + body: + encoding: US-ASCII + string: '' + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: "" + Host: + - api.easypost.com + Content-Type: + - application/json + Authorization: "" + response: + status: + code: 200 + message: OK + headers: + X-Frame-Options: + - SAMEORIGIN + X-Xss-Protection: + - 1; mode=block + X-Content-Type-Options: + - nosniff + X-Download-Options: + - noopen + X-Permitted-Cross-Domain-Policies: + - none + Referrer-Policy: + - strict-origin-when-cross-origin + X-Ep-Request-Uuid: + - 16819983698e0e4fe787c8bc011c9815 + Cache-Control: + - private, no-cache, no-store + Pragma: + - no-cache + Expires: + - '0' + Content-Type: + - application/json; charset=utf-8 + X-Runtime: + - '0.033115' + Transfer-Encoding: + - chunked + X-Node: + - bigweb59nuq + X-Version-Label: + - easypost-202602121702-bfe72e7ac7-master + X-Backend: + - easypost + X-Proxied: + - extlb1nuq c01291cd8f + - intlb3nuq 0dcc3a6efb + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + body: + encoding: UTF-8 + string: '{"addresses":[{"id":"adr_965375f9083811f1ad4d3cecef1b359e","object":"Address","created_at":"2026-02-12T17:30:55Z","updated_at":"2026-02-12T17:30:55Z","name":"Jack + Sparrow","company":null,"street1":"388 Townsend St","street2":"Apt 20","city":"San + Francisco","state":"CA","zip":"94107","country":"US","phone":"","email":"","mode":"test","carrier_facility":null,"residential":null,"federal_tax_id":null,"state_tax_id":null,"verifications":{}}],"has_more":true}' + recorded_at: Thu, 12 Feb 2026 17:30:56 GMT +recorded_with: VCR 6.4.0 diff --git a/spec/client_spec.rb b/spec/client_spec.rb index 7640febc..3bc06760 100644 --- a/spec/client_spec.rb +++ b/spec/client_spec.rb @@ -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