Skip to content

Commit 195fa40

Browse files
nwithan8jchen293
andauthored
[fix] Use body for POST/PUT/PATCH and query for GET/DELETE requests (#310)
- Use body for POST/PUT/PATCH and query for GET/DELETE requests - Re-record all cassettes Co-authored-by: jchen293 <jchen@easypost.com>
1 parent 98beadf commit 195fa40

File tree

164 files changed

+5293
-4413
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

164 files changed

+5293
-4413
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# CHANGELOG
22

3+
## Next release
4+
5+
- Send GET requests as query parameters instead of JSON body parameters
6+
- Fix get_next_page_of_children function for User service with correct filter key
7+
38
## v6.4.0 (2024-07-24)
49

510
- Adds new `Claim` service for filing claims on EasyPost shipments and insurances

examples

Submodule examples updated 40 files

lib/easypost/client.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,17 @@ def initialize(api_key:, read_timeout: 60, open_timeout: 30, api_base: 'https://
7474
#
7575
# @param method [Symbol] the HTTP Verb (get, method, put, post, etc.)
7676
# @param endpoint [String] URI path of the resource
77-
# @param body [Object] (nil) object to be dumped to JSON
77+
# @param params [Object] (nil) object to be used as the request parameters
7878
# @param api_version [String] the version of API to hit
7979
# @raise [EasyPost::Error] if the response has a non-2xx status code
8080
# @return [Hash] JSON object parsed from the response body
8181
def make_request(
8282
method,
8383
endpoint,
84-
body = nil,
84+
params = nil,
8585
api_version = EasyPost::InternalUtilities::Constants::API_VERSION
8686
)
87-
response = @http_client.request(method, endpoint, nil, body, api_version)
87+
response = @http_client.request(method, endpoint, nil, params, api_version)
8888

8989
potential_error = EasyPost::Errors::ApiError.handle_api_error(response)
9090
raise potential_error unless potential_error.nil?

lib/easypost/http_client.rb

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,35 @@ def request(
1414
method,
1515
path,
1616
headers = nil,
17-
body = nil,
17+
params = nil,
1818
api_version = EasyPost::InternalUtilities::Constants::API_VERSION
1919
)
2020
# Remove leading slash from path.
2121
path = path[1..] if path[0] == '/'
2222

23-
uri = URI.parse("#{@base_url}/#{api_version}/#{path}")
2423
headers = @config[:headers].merge(headers || {})
25-
serialized_body = JSON.dump(EasyPost::InternalUtilities.objects_to_ids(body)) if body
2624
open_timeout = @config[:open_timeout]
2725
read_timeout = @config[:read_timeout]
2826
request_timestamp = Time.now
2927
request_uuid = SecureRandom.uuid
3028

29+
uri = URI.parse("#{@base_url}/#{api_version}/#{path}")
30+
serialized_body = nil
31+
32+
if params
33+
if [:get, :delete].include?(method)
34+
uri.query = URI.encode_www_form(params)
35+
elsif params
36+
serialized_body = JSON.dump(EasyPost::InternalUtilities.objects_to_ids(params))
37+
end
38+
end
39+
3140
if EasyPost::Hooks.any_subscribers?(:request)
3241
request_context = EasyPost::Hooks::RequestContext.new(
3342
method: method,
3443
path: uri.to_s,
3544
headers: headers,
36-
request_body: body,
45+
request_body: serialized_body,
3746
request_timestamp: request_timestamp,
3847
request_uuid: request_uuid,
3948
)

lib/easypost/services/user.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def all_children(params = {})
9090
def get_next_page_of_children(collection, page_size = nil)
9191
raise EasyPost::Errors::EndOfPaginationError.new unless more_pages?(collection)
9292

93-
params = { before_id: collection.children.last.id }
93+
params = { after_id: collection.children.last.id }
9494
params[:page_size] = page_size unless page_size.nil?
9595

9696
all_children(params)

spec/cassettes/address/EasyPost_Services_Address_address_service_creates_an_address.yml

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

spec/cassettes/address/EasyPost_Services_Address_address_service_creates_an_address_with_an_array_verify_param.yml

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

spec/cassettes/address/EasyPost_Services_Address_address_service_creates_an_address_with_verify_param.yml

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

spec/cassettes/address/EasyPost_Services_Address_address_service_creates_an_address_with_verify_strict_param.yml

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

0 commit comments

Comments
 (0)