Class: KucoinRuby::Net
- Inherits:
-
Object
- Object
- KucoinRuby::Net
- Defined in:
- lib/kucoin_ruby/net.rb
Constant Summary collapse
- API_HOST =
'https://api.kucoin.com'
Class Method Summary collapse
- .get(endpoint) ⇒ Object
- .handle_response(response) ⇒ Object
- .headers(nonce, signature) ⇒ Object
- .key ⇒ Object
- .secret ⇒ Object
- .signed_get(endpoint, query_string = nil) ⇒ Object
- .signed_post(endpoint, payload = nil) ⇒ Object
Class Method Details
.get(endpoint) ⇒ Object
25 26 27 28 |
# File 'lib/kucoin_ruby/net.rb', line 25 def self.get(endpoint) uri = "#{API_HOST}#{endpoint}" handle_response(HTTParty.get(uri)) end |
.handle_response(response) ⇒ Object
52 53 54 55 56 57 |
# File 'lib/kucoin_ruby/net.rb', line 52 def self.handle_response(response) if response.code != 200 raise KucoinRuby::Exceptions::ResponseError.new(response) end JSON.parse(response.body) end |
.headers(nonce, signature) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/kucoin_ruby/net.rb', line 15 def self.headers(nonce, signature) { 'Content-Type' => 'application/json', 'KC-API-KEY' => key, 'KC-API-NONCE' => nonce, 'KC-API-SIGNATURE' => signature, "Accept-Language" => 'en_EN' } end |
.key ⇒ Object
7 8 9 |
# File 'lib/kucoin_ruby/net.rb', line 7 def self.key ENV['KUCOIN_KEY'] || 'fake_key' end |
.secret ⇒ Object
11 12 13 |
# File 'lib/kucoin_ruby/net.rb', line 11 def self.secret ENV['KUCOIN_SECRET'] || 'fake_secret' end |
.signed_get(endpoint, query_string = nil) ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/kucoin_ruby/net.rb', line 30 def self.signed_get(endpoint, query_string = nil) nonce, signature = KucoinRuby::Util.(endpoint, query_string) query_string = URI.encode_www_form(query_string) if query_string.is_a? Hash uri = "#{API_HOST}#{endpoint}?#{query_string}" response = HTTParty.get( uri, headers: headers(nonce, signature) ) handle_response(response) end |
.signed_post(endpoint, payload = nil) ⇒ Object
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/kucoin_ruby/net.rb', line 41 def self.signed_post(endpoint, payload = nil) nonce, signature = KucoinRuby::Util.(endpoint) uri = "#{API_HOST}#{endpoint}" response = HTTParty.post( uri, headers: headers(nonce, signature), body: payload ) handle_response(response) end |