class Object
Public Instance Methods
colorize(text, color_code)
click to toggle source
# File lib/rcbp.rb, line 41 def colorize(text, color_code) "\e[#{color_code}m#{text}\e[0m" end
getBuyPrice()
click to toggle source
# File lib/rcbp.rb, line 25 def getBuyPrice return getPrice("https://api.coinbase.com/v1/prices/buy?qty=1") end
getHistoricalPrice()
click to toggle source
# File lib/rcbp.rb, line 33 def getHistoricalPrice csv = String.new open("https://api.coinbase.com/v1/prices/historical") do |d| csv = CSV.parse(d.read, :col_sep => ",", :headers => "false") return csv[200][1] end end
getPrice(url)
click to toggle source
# File lib/rcbp.rb, line 8 def getPrice(url) amount = String.new currency = String.new open(url) do |d| json = JSON.parse(d.read) amount = json["amount"] currency = json["currency"] end return amount end
getSellPrice()
click to toggle source
# File lib/rcbp.rb, line 29 def getSellPrice return getPrice("https://api.coinbase.com/v1/prices/sell?qty=1") end
getSpotPrice()
click to toggle source
# File lib/rcbp.rb, line 21 def getSpotPrice return getPrice("https://api.coinbase.com/v1/prices/spot_rate") end
setColor(text)
click to toggle source
# File lib/rcbp.rb, line 45 def setColor(text) # If price went down, set text to red and vice versa to green if getHistoricalPrice.to_f >= getSpotPrice.to_f colorize(text, 31) else colorize(text, 32) end end