Class: Mcoin::Market::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/mcoin/market/base.rb

Overview

:nodoc:

Direct Known Subclasses

Bitfinex, Bitstamp, Kraken

Instance Method Summary collapse

Constructor Details

#initialize(type, currency) ⇒ Base

Returns a new instance of Base.



11
12
13
14
15
# File 'lib/mcoin/market/base.rb', line 11

def initialize(type, currency)
  @type = type
  @currency = currency
  @retries = 0
end

Instance Method Details

#fetchObject



21
22
23
24
25
26
27
28
# File 'lib/mcoin/market/base.rb', line 21

def fetch
  @data ||= JSON.parse(Net::HTTP.get(uri))
  self
rescue JSON::ParserError
  return nil if @retries >= 3
  @retries += 1
  retry
end

#nameObject



17
18
19
# File 'lib/mcoin/market/base.rb', line 17

def name
  self.class.name.split('::').last
end

#to_tickerObject

Raises:

  • (NotImplementedError)


30
31
32
# File 'lib/mcoin/market/base.rb', line 30

def to_ticker
  raise NotImplementedError
end

#uriObject



34
35
36
37
38
# File 'lib/mcoin/market/base.rb', line 34

def uri
  options = { type: @type.upcase, currency: @currency.upcase }
  uri = format(self.class.const_get(:ENDPOINT), options)
  URI(uri)
end