Class: Kucoin::Api::Endpoints::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/kucoin/api/endpoints/base.rb

Direct Known Subclasses

Markets, Other, Trade, User, Websocket

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Base

Returns a new instance of Base.



7
8
9
# File 'lib/kucoin/api/endpoints/base.rb', line 7

def initialize client
  @client = client
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



6
7
8
# File 'lib/kucoin/api/endpoints/base.rb', line 6

def client
  @client
end

Instance Method Details

#assert_param_is_one_of(options, param, valid_values) ⇒ Object



37
38
39
40
# File 'lib/kucoin/api/endpoints/base.rb', line 37

def assert_param_is_one_of options, param, valid_values
  return if valid_values.include? options[param].to_s
  raise Kucoin::Api::InvalidParamError.new("#{param} must be one of #{valid_values.inspect}")
end

#assert_required_param(options, param, valid_values = nil) ⇒ Object



32
33
34
35
# File 'lib/kucoin/api/endpoints/base.rb', line 32

def assert_required_param options, param, valid_values=nil
  raise Kucoin::Api::MissingParamError.new("#{param} is required") unless options.has_key?(param)
  assert_param_is_one_of options, param, valid_values if valid_values
end

#authObject



15
16
17
# File 'lib/kucoin/api/endpoints/base.rb', line 15

def auth
  client.auth(self)
end

#openObject



11
12
13
# File 'lib/kucoin/api/endpoints/base.rb', line 11

def open
  client.open(self)
end

#pathObject



19
20
21
22
23
24
25
# File 'lib/kucoin/api/endpoints/base.rb', line 19

def path
  self.class.name
    .gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
    .gsub(/([a-z\d])([A-Z])/,'\1_\2')
    .tr('-', '_')
    .downcase.split('::')[3..-1].join('::')
end

#url(action) ⇒ Object



27
28
29
30
# File 'lib/kucoin/api/endpoints/base.rb', line 27

def url action
  path_array = path.split('::').map(&:to_sym)
  path_array.reduce(Kucoin::Api::ENDPOINTS) { |m, k| m.fetch(k, {}) }[action]
end