lib/bitcoin/ticker.rb in bitcoin-api-0.1.0 vs lib/bitcoin/ticker.rb in bitcoin-api-0.1.1
- old
+ new
@@ -1,13 +1,20 @@
class Bitcoin::Ticker
- attr_accessor :ask, :bid, :last, :open, :low, :high, :volume, :volumeQuote,
- :timestamp, :symbol
+ attr_accessor :ask, :bid, :last, :open, :low, :high, :volume, :volumeQuote, :timestamp, :symbol
- def self.new_from_symbol_name(symbol)
- data = JSON.parse(RestClient.get("#{Bitcoin::BASE}/public/ticker/#{symbol}"))
- Bitcoin::Ticker.new_from_object(data)
+ def display_details
+ puts <<-DOC
+ #{@symbol}
+ Best Ask : #{@ask.to_s.rjust(9)} || Best Bid: #{@bid}
+ Last Trade Price: #{@last}
+ Open: #{@open}
+ 24-Hour Low: #{@low.to_s.rjust(9)} || 24-Hour High: #{@high}
+ Total 24-Hour Volume (Base): #{@volume} (Quote): #{@volumeQuote}
+ #{@timestamp}
+
+ DOC
end
def self.new_from_object(data)
t = Bitcoin::Ticker.new
t.ask = data['ask'].to_f
@@ -21,25 +28,19 @@
t.timestamp = Time.parse(data['timestamp'])
t.symbol = data['symbol']
t
end
+ def self.new_from_symbol_name(symbol_name)
+ data = JSON.parse(RestClient.get("#{Bitcoin::BASE}/public/ticker/#{symbol_name}"))
+ Bitcoin::Ticker.new_from_object(data)
+ end
+
def self.all
data = JSON.parse(RestClient.get("#{Bitcoin::BASE}/public/ticker"))
data.map{ |ticker|
Bitcoin::Ticker.new_from_object(ticker)
}
end
- def display_details
- puts <<-DOC
- #{@symbol}
- Best Ask : #{@ask.to_s.rjust(9)} || Best Bid: #{@bid}
- Last Trade Price: #{@last}
- Open: #{@open}
- 24-Hour Low: #{@low.to_s.rjust(9)} || 24-Hour High: #{@high}
- Total 24-Hour Volume (Base): #{@volume} (Quote): #{@volumeQuote}
- #{@timestamp}
- DOC
- end
end