class StockMarkit::Lookup
@attr_reader [String,Symbol] symbol The symbol of the stock to lookup @attr_reader [Hash] options Options hash for httparty @attr_reader [Array<StockMarkit::Stock>] results The stocks that match the symbol. This is populated on the first call of <#fetch>
@author Michael Heijmans (parabuzzle@gmail.com)
- Copyright
-
Copyright © 2016 Michael Heijmans
- License
-
MIT
Attributes
results[R]
symbol[R]
Public Class Methods
new(symbol)
click to toggle source
@param [String, Symbol] symbol The stock's ticker symbol
# File lib/stock-markit/lookup.rb, line 25 def initialize(symbol) @symbol = symbol.to_sym.upcase @options = { query: {input: @symbol} } end
Public Instance Methods
fetch()
click to toggle source
Fetch stocks matching @symbol from the api
This method memoizes the results and returns the contents of the results variable instead of asking the api again @return [Array<StockMarkit::Stock>]
# File lib/stock-markit/lookup.rb, line 35 def fetch @results ||= lookup_with_api end
Private Instance Methods
lookup_with_api()
click to toggle source
# File lib/stock-markit/lookup.rb, line 41 def lookup_with_api results = self.class.get("/MODApis/Api/v2/Lookup/json", @options) unless results.code == 200 raise ApiException.new("An error occured while attempting to communicate with the api", results) end map_stocks( Oj.load( results.body ) ) end
map_stocks(stocks)
click to toggle source
# File lib/stock-markit/lookup.rb, line 49 def map_stocks(stocks) stocks.map do |stock| Stock.new(stock["Symbol"], stock['Name'], stock["Exchange"]) end end