class Yafa::StockChart

Constants

DATA_SOURCE
READ_TIMEOUT
YAHOO_CHART_API

Public Class Methods

new(ticker) click to toggle source
# File lib/yafa/stock_chart.rb, line 11
def initialize(ticker)
  @ticker = ticker
end

Public Instance Methods

fetch() click to toggle source
# File lib/yafa/stock_chart.rb, line 15
def fetch
  quote_data = call_api @ticker
  parse_quote quote_data
end

Private Instance Methods

call_api(ticker) click to toggle source
# File lib/yafa/stock_chart.rb, line 22
def call_api(ticker)
  url      = format_api_url ticker
  response = perform_api_request url

  response.read
end
format_api_url(yahoo_ticker) click to toggle source
# File lib/yafa/stock_chart.rb, line 37
def format_api_url(yahoo_ticker)
  YAHOO_CHART_API.sub('yahoo_ticker', yahoo_ticker)
end
json_regex_match() click to toggle source
# File lib/yafa/stock_chart.rb, line 46
def json_regex_match
  /\(|\)/
end
parse_quote(data) click to toggle source
# File lib/yafa/stock_chart.rb, line 41
def parse_quote(data)
  json_string = data.split json_regex_match
  JSON.parse json_string[1]
end
perform_api_request(url) click to toggle source
# File lib/yafa/stock_chart.rb, line 29
def perform_api_request(url)
  open(
    url,
    ssl_verify_mode: OpenSSL::SSL::VERIFY_NONE,
    read_timeout:    READ_TIMEOUT
  )
end