Module: GStock

Defined in:
lib/gstock.rb,
lib/gstock/version.rb

Defined Under Namespace

Classes: NotFound

Constant Summary collapse

VERSION =
"1.0.0"

Class Method Summary collapse

Class Method Details

.connectionObject



26
27
28
29
30
31
32
# File 'lib/gstock.rb', line 26

def connection
  @conn ||= Faraday::Connection.new(:url => 'http://www.google.com') do |builder|
    builder.adapter :typhoeus
    builder.use Faraday::Response::ParseXml
    builder.use Faraday::Response::Mashify
  end
end

.get(url, params = {}) ⇒ Object



19
20
21
22
23
24
# File 'lib/gstock.rb', line 19

def get(url, params={})
  response = connection.get do |req|
    req.url url, params
  end
  response.body
end

.quote(symbol) ⇒ Object

Raises:



9
10
11
12
13
14
15
16
17
# File 'lib/gstock.rb', line 9

def quote(symbol)
  resp = get('/ig/api', :stock => symbol).xml_api_reply.finance
  resp.each do |key, value|
    resp[key] = value.kind_of?(Hashie::Mash) ? value.data : value
  end
  resp.reject! { |key, value | value.blank? }
  raise NotFound.new if resp.has_value?('UNKNOWN EXCHANGE')
  resp
end