Class: QuidaxBaseObject
- Inherits:
-
Object
- Object
- QuidaxBaseObject
- Defined in:
- lib/quidax/objects/base.rb
Overview
Base object for HTTP requests
Direct Known Subclasses
QuidaxBeneficiary, QuidaxDeposits, QuidaxFee, QuidaxInstantOrder, QuidaxMarkets, QuidaxOrder, QuidaxQuote, QuidaxTrade, QuidaxUser, QuidaxWallet, QuidaxWithdrawal
Instance Attribute Summary collapse
-
#quidax ⇒ Object
readonly
Returns the value of attribute quidax.
Class Method Summary collapse
- .get_request(q_object, path, params = {}) ⇒ Object
- .post_request(q_object, path, body = {}) ⇒ Object
- .put_request(q_object, path, body = {}) ⇒ Object
- .url(path) ⇒ Object
Instance Method Summary collapse
-
#initialize(quidax_object) ⇒ QuidaxBaseObject
constructor
A new instance of QuidaxBaseObject.
Constructor Details
#initialize(quidax_object) ⇒ QuidaxBaseObject
Returns a new instance of QuidaxBaseObject.
9 10 11 12 13 |
# File 'lib/quidax/objects/base.rb', line 9 def initialize(quidax_object) raise ArgumentError, "Quidax object cannot be nil!" if quidax_object.nil? @quidax = quidax_object end |
Instance Attribute Details
#quidax ⇒ Object (readonly)
Returns the value of attribute quidax.
7 8 9 |
# File 'lib/quidax/objects/base.rb', line 7 def quidax @quidax end |
Class Method Details
.get_request(q_object, path, params = {}) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/quidax/objects/base.rb', line 15 def self.get_request(q_object, path, params = {}) result = nil begin response = Faraday.get(url(path), params, { "Authorization" => "Bearer #{q_object.secret_key}" }) raise QuidaxServerError, response unless response.status == 200 || response.status == 201 result = JSON.parse(response.body) rescue QuidaxServerError => e Utils.handle_server_error(e) rescue JSON::ParserError => e raise QuidaxServerError.new(response), "Invalid result data. Could not parse JSON response body \n #{e.}" end result end |
.post_request(q_object, path, body = {}) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/quidax/objects/base.rb', line 32 def self.post_request(q_object, path, body = {}) result = nil begin response = Faraday.post(url(path), body.to_json, { "Authorization" => "Bearer #{q_object.secret_key}", "Content-Type" => "application/json", "Accept" => "application/json" }) raise QuidaxServerError, response unless response.status == 200 || response.status == 201 result = JSON.parse(response.body) rescue QuidaxServerError => e Utils.handle_server_error(e) end result end |
.put_request(q_object, path, body = {}) ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/quidax/objects/base.rb', line 47 def self.put_request(q_object, path, body = {}) response = Faraday.put("#{API::BASE_URL}#{path}", body, { "Authorization" => "Bearer #{q_object.secret_key}" }) raise QuidaxServerError, response unless response.status == 200 || response.status == 201 JSON.parse(response.body) rescue QuidaxServerError => e Utils.handle_server_error(e) end |