From 07283923ce38b6ee8a5888f799fc416243c4ccda Mon Sep 17 00:00:00 2001 From: Kyle Chapman Date: Tue, 17 Sep 2024 11:41:57 +0200 Subject: [PATCH] Allow get_response to use GET instead of only POST --- lib/ups/connection.rb | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/lib/ups/connection.rb b/lib/ups/connection.rb index 23b769c..6035172 100644 --- a/lib/ups/connection.rb +++ b/lib/ups/connection.rb @@ -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 @@ -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 = { @@ -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)