Class: Kucoin::Api::REST::Connection
- Inherits:
-
Object
- Object
- Kucoin::Api::REST::Connection
- Defined in:
- lib/kucoin/api/rest/connection.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#endpoint ⇒ Object
readonly
Returns the value of attribute endpoint.
Instance Method Summary collapse
-
#initialize(endpoint, options = {}, &block) ⇒ Connection
constructor
A new instance of Connection.
- #ku_request(method, subpath, options = {}) ⇒ Object
Constructor Details
#initialize(endpoint, options = {}, &block) ⇒ Connection
Returns a new instance of Connection.
7 8 9 10 |
# File 'lib/kucoin/api/rest/connection.rb', line 7 def initialize endpoint, ={}, &block @endpoint = endpoint @client = ::Faraday.new(, &block) end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
6 7 8 |
# File 'lib/kucoin/api/rest/connection.rb', line 6 def client @client end |
#endpoint ⇒ Object (readonly)
Returns the value of attribute endpoint.
6 7 8 |
# File 'lib/kucoin/api/rest/connection.rb', line 6 def endpoint @endpoint end |
Instance Method Details
#ku_request(method, subpath, options = {}) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/kucoin/api/rest/connection.rb', line 12 def ku_request method, subpath, = {} response = client.public_send(method) do |req| # substitute path parameters and remove from options hash endpoint_url = endpoint.url(subpath).dup .each do |option, value| path_param = /:#{option}/ if endpoint_url.match? path_param .delete(option) endpoint_url.gsub!(path_param, value.to_s) end end req.url endpoint_url # parameters go into request body, not headers on POSTs if method == :post req.body = else req.params.merge!() end end success_or_error response end |