Class: CurrencyCloud::RequestHandler
- Inherits:
-
Object
- Object
- CurrencyCloud::RequestHandler
- Defined in:
- lib/currency_cloud/request_handler.rb
Instance Attribute Summary collapse
-
#session ⇒ Object
readonly
Returns the value of attribute session.
Instance Method Summary collapse
- #get(route, params = {}, opts = {}) ⇒ Object
-
#initialize(session = CurrencyCloud.session) ⇒ RequestHandler
constructor
A new instance of RequestHandler.
- #post(route, params = {}, opts = {}) ⇒ Object
- #put(route, params = {}, opts = {}) ⇒ Object
Constructor Details
#initialize(session = CurrencyCloud.session) ⇒ RequestHandler
Returns a new instance of RequestHandler.
5 6 7 |
# File 'lib/currency_cloud/request_handler.rb', line 5 def initialize(session = CurrencyCloud.session) @session = session end |
Instance Attribute Details
#session ⇒ Object (readonly)
Returns the value of attribute session.
3 4 5 |
# File 'lib/currency_cloud/request_handler.rb', line 3 def session @session end |
Instance Method Details
#get(route, params = {}, opts = {}) ⇒ Object
9 10 11 12 13 14 |
# File 'lib/currency_cloud/request_handler.rb', line 9 def get(route, params = {}, opts = {}) retry_authenticate('get', route, params, opts) do |url, new_params, | [:query] = new_params HTTParty.get(url, ) end end |
#post(route, params = {}, opts = {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/currency_cloud/request_handler.rb', line 16 def post(route, params = {}, opts = {}) return_response_headers = opts.delete(:return_response_headers) || false raw_response = nil response = retry_authenticate('post', route, params, opts) do |url, new_params, | [:body] = new_params raw_response = HTTParty.post(url, ) raw_response end if return_response_headers [response, raw_response&.headers || {}] else response end end |
#put(route, params = {}, opts = {}) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/currency_cloud/request_handler.rb', line 32 def put(route, params = {}, opts = {}) return_response_headers = opts.delete(:return_response_headers) || false raw_response = nil response = retry_authenticate('put', route, params, opts) do |url, new_params, | [:body] = new_params raw_response = HTTParty.put(url, ) raw_response end if return_response_headers [response, raw_response&.headers || {}] else response end end |