Skip to content

Commit

Permalink
[fix] Use body for POST/PUT/PATCH and query for GET/DELETE requests (#…
Browse files Browse the repository at this point in the history
…310)

- Use body for POST/PUT/PATCH and query for GET/DELETE requests
- Re-record all cassettes

Co-authored-by: jchen293 <[email protected]>
  • Loading branch information
nwithan8 and jchen293 authored Aug 1, 2024
1 parent 98beadf commit 195fa40
Show file tree
Hide file tree
Showing 164 changed files with 5,293 additions and 4,413 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# CHANGELOG

## Next release

- Send GET requests as query parameters instead of JSON body parameters
- Fix get_next_page_of_children function for User service with correct filter key

## v6.4.0 (2024-07-24)

- Adds new `Claim` service for filing claims on EasyPost shipments and insurances
Expand Down
2 changes: 1 addition & 1 deletion examples
Submodule examples updated 40 files
+21 −0 official/docs/csharp/current/claims/cancel.cs
+43 −0 official/docs/csharp/current/claims/create.cs
+27 −0 official/docs/csharp/current/claims/list.cs
+21 −0 official/docs/csharp/current/claims/retrieve.cs
+2 −0 official/docs/curl/current/claims/cancel.sh
+13 −0 official/docs/curl/current/claims/create.sh
+2 −0 official/docs/curl/current/claims/list.sh
+2 −0 official/docs/curl/current/claims/retrieve.sh
+15 −0 official/docs/golang/current/claims/cancel.go
+25 −0 official/docs/golang/current/claims/create.go
+19 −0 official/docs/golang/current/claims/list.go
+15 −0 official/docs/golang/current/claims/retrieve.go
+15 −0 official/docs/java/current/claims/cancel.java
+30 −0 official/docs/java/current/claims/create.java
+20 −0 official/docs/java/current/claims/list.java
+15 −0 official/docs/java/current/claims/retrieve.java
+9 −0 official/docs/node/current/claims/cancel.js
+18 −0 official/docs/node/current/claims/create.js
+11 −0 official/docs/node/current/claims/list.js
+9 −0 official/docs/node/current/claims/retrieve.js
+7 −0 official/docs/php/current/claims/cancel.php
+19 −0 official/docs/php/current/claims/create.php
+9 −0 official/docs/php/current/claims/list.php
+7 −0 official/docs/php/current/claims/retrieve.php
+7 −0 official/docs/python/current/claims/cancel.py
+16 −0 official/docs/python/current/claims/create.py
+7 −0 official/docs/python/current/claims/list.py
+7 −0 official/docs/python/current/claims/retrieve.py
+40 −0 official/docs/responses/claim/claim-cancel.json
+35 −0 official/docs/responses/claim/claim-create.json
+185 −0 official/docs/responses/claim/claim-list.json
+35 −0 official/docs/responses/claim/claim-retrieve.json
+7 −0 official/docs/ruby/current/claim/cancel.rb
+19 −0 official/docs/ruby/current/claim/create.rb
+9 −0 official/docs/ruby/current/claim/list.rb
+7 −0 official/docs/ruby/current/claim/retrieve.rb
+1 −1 official/fixtures/client-library-fixtures.json
+13 −0 official/guides/create-carrier-curls/quick.sh
+26 −31 style_guides/node/.eslintrc
+0 −4 style_guides/node/.prettierignore
6 changes: 3 additions & 3 deletions lib/easypost/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,17 @@ def initialize(api_key:, read_timeout: 60, open_timeout: 30, api_base: 'https://
#
# @param method [Symbol] the HTTP Verb (get, method, put, post, etc.)
# @param endpoint [String] URI path of the resource
# @param body [Object] (nil) object to be dumped to JSON
# @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
# @return [Hash] JSON object parsed from the response body
def make_request(
method,
endpoint,
body = nil,
params = nil,
api_version = EasyPost::InternalUtilities::Constants::API_VERSION
)
response = @http_client.request(method, endpoint, nil, body, api_version)
response = @http_client.request(method, endpoint, nil, params, api_version)

potential_error = EasyPost::Errors::ApiError.handle_api_error(response)
raise potential_error unless potential_error.nil?
Expand Down
17 changes: 13 additions & 4 deletions lib/easypost/http_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,35 @@ def request(
method,
path,
headers = nil,
body = nil,
params = nil,
api_version = EasyPost::InternalUtilities::Constants::API_VERSION
)
# Remove leading slash from path.
path = path[1..] if path[0] == '/'

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

uri = URI.parse("#{@base_url}/#{api_version}/#{path}")
serialized_body = nil

if params
if [:get, :delete].include?(method)
uri.query = URI.encode_www_form(params)
elsif params
serialized_body = JSON.dump(EasyPost::InternalUtilities.objects_to_ids(params))
end
end

if EasyPost::Hooks.any_subscribers?(:request)
request_context = EasyPost::Hooks::RequestContext.new(
method: method,
path: uri.to_s,
headers: headers,
request_body: body,
request_body: serialized_body,
request_timestamp: request_timestamp,
request_uuid: request_uuid,
)
Expand Down
2 changes: 1 addition & 1 deletion lib/easypost/services/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def all_children(params = {})
def get_next_page_of_children(collection, page_size = nil)
raise EasyPost::Errors::EndOfPaginationError.new unless more_pages?(collection)

params = { before_id: collection.children.last.id }
params = { after_id: collection.children.last.id }
params[:page_size] = page_size unless page_size.nil?

all_children(params)
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.

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.

Loading

0 comments on commit 195fa40

Please sign in to comment.