class Lita::Handlers::CoinInfo

Public Instance Methods

diff(response) click to toggle source
# File lib/lita/handlers/coin_info.rb, line 23
def diff response
  url = 'https://blockchain.info/q/getdifficulty'

  diff = get_data url

  response.reply diff.to_f.to_s
end
get_and_parse_data(url) click to toggle source
# File lib/lita/handlers/coin_info.rb, line 35
def get_and_parse_data url
  JSON.parse HTTParty.get(url, format: :plain), symbolize_names: true
end
get_data(url) click to toggle source
# File lib/lita/handlers/coin_info.rb, line 31
def get_data url
  HTTParty.get(url, format: :plain)
end
price(response) click to toggle source
# File lib/lita/handlers/coin_info.rb, line 9
def price response
  coin          = response.matches[0][0]
  currency_pair = "#{ coin }-USD"
  url           = "https://api.coinbase.com/v2/prices/#{ currency_pair }/spot"

  price_json = get_and_parse_data url

  response.reply "$#{ price_json[:data][:amount] }"
end