Last active
June 24, 2016 16:27
-
-
Save amanelis/844f53055cfbea2ec0f646c5742bd9ad to your computer and use it in GitHub Desktop.
Stock prices with a bonus of Bitcoin at the end
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'json' | |
require 'open-uri' | |
class Stocks | |
def self.get_by_symbols(symbols) | |
return symbols.inject([]) { |memo, sym| | |
result = JSON.parse(open("http://dev.markitondemand.com/MODApis/Api/v2/Quote/json?symbol=#{sym}").read) | |
memo << {symbol: result['Symbol'], lastPrice: result['LastPrice']} | |
} | |
end | |
end | |
class Bitcoin | |
def self.get_last_price | |
return JSON.parse(open('https://api.bitcoinaverage.com/all').read)['USD']['averages']['last'] | |
end | |
end | |
puts Stocks.get_by_symbols(['msft', 'aapl', 'c']) | |
puts Bitcoin.get_last_price |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment