Class: BitcoinAverage::Ticker

Inherits:
Object
  • Object
show all
Includes:
Requester
Defined in:
lib/bitcoinaverage/ticker.rb

Direct Known Subclasses

GlobalTicker, MarketTicker

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Requester

#available_currencies, #get, #known_currency?

Instance Attribute Details

#askObject

Returns the value of attribute ask.



7
8
9
# File 'lib/bitcoinaverage/ticker.rb', line 7

def ask
  @ask
end

#avg_24hObject

Returns the value of attribute avg_24h.



7
8
9
# File 'lib/bitcoinaverage/ticker.rb', line 7

def avg_24h
  @avg_24h
end

#bidObject

Returns the value of attribute bid.



7
8
9
# File 'lib/bitcoinaverage/ticker.rb', line 7

def bid
  @bid
end

#lastObject

Returns the value of attribute last.



7
8
9
# File 'lib/bitcoinaverage/ticker.rb', line 7

def last
  @last
end

#timestampObject

Returns the value of attribute timestamp.



7
8
9
# File 'lib/bitcoinaverage/ticker.rb', line 7

def timestamp
  @timestamp
end

Instance Method Details

#request_info(currency = 'USD') ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/bitcoinaverage/ticker.rb', line 9

def request_info(currency = 'USD')
  response = get(avg_type, currency)
  if response.success?
    # Small patch since an attribute can't be named "24h_avg"
    response = JSON.load(response.to_s) unless response.is_a?(Hash)
    self.avg_24h = response['24h_avg']
    response.delete('24h_avg')
    response.each do |key, value|
      send("#{key}=", value)
    end
    self
  else
    fail 'Error receiving response' # TODO: extended
  end
end