Skip to content

Commit

Permalink
Allow get_response to use GET instead of only POST
Browse files Browse the repository at this point in the history
  • Loading branch information
chapmankyle committed Sep 17, 2024
1 parent a834698 commit 0728392
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions lib/ups/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def track(number)
fail Exceptions::InvalidAttributeError, 'Tracking number is required'
end

response = get_response(TRACK_PATH + "/#{number}")
response = get_response(TRACK_PATH + "/#{number}", {}, 'GET')
UPS::Parsers::TrackParser.new(response.body)
end

Expand Down Expand Up @@ -192,8 +192,9 @@ def build_url(path)
#
# @param [String] path The path to make the request to
# @param [Optional, Hash] body The body to send with the request
# @param [Optional, String] method The method type to use for the request
# @return [Excon::Response] The response from the request
def get_response(path, body = {})
def get_response(path, body = {}, method = 'post')
access_token = get_access_token

headers = {
Expand All @@ -202,11 +203,18 @@ def get_response(path, body = {})
'transId' => SecureRandom.hex(16) # Unique identifier for this request
}

Excon.post(
build_url(path),
headers: headers,
body: body.to_json
)
if method.downcase == 'get'
Excon.get(
build_url(path),
headers: headers
)
else
Excon.post(
build_url(path),
headers: headers,
body: body.to_json
)
end
end

def make_confirm_request(confirm_builder)
Expand Down

0 comments on commit 0728392

Please sign in to comment.