Class: YahooStock::Interface
- Inherits:
-
Object
- Object
- YahooStock::Interface
- Includes:
- Observable
- Defined in:
- lib/yahoo_stock/interface.rb
Overview
DESCRIPTION:
Class to generate the right url and interface with yahoo
Direct Known Subclasses
Defined Under Namespace
Classes: History, InterfaceError, Quote, ScripSymbol
Constant Summary collapse
- BASE_URLS =
{ :quote => "http://download.finance.yahoo.com/d/quotes.csv", :history => "http://ichart.finance.yahoo.com/table.csv", :scrip_symbol => "http://finance.yahoo.com/lookup/all" }
Instance Attribute Summary collapse
-
#base_url ⇒ Object
Returns the value of attribute base_url.
-
#uri_parameters ⇒ Object
Returns the value of attribute uri_parameters.
Instance Method Summary collapse
-
#get ⇒ Object
Send request to the uri and get results.
- #update ⇒ Object
-
#uri ⇒ Object
Generates full url to connect to yahoo.
-
#values ⇒ Object
Get result string.
Instance Attribute Details
#base_url ⇒ Object
Returns the value of attribute base_url.
22 23 24 |
# File 'lib/yahoo_stock/interface.rb', line 22 def base_url @base_url end |
#uri_parameters ⇒ Object
Returns the value of attribute uri_parameters.
22 23 24 |
# File 'lib/yahoo_stock/interface.rb', line 22 def uri_parameters @uri_parameters end |
Instance Method Details
#get ⇒ Object
Send request to the uri and get results
25 26 27 28 29 30 31 32 |
# File 'lib/yahoo_stock/interface.rb', line 25 def get begin response = Net::HTTP.get_response(URI.parse(uri)) rescue => e raise InterfaceError, "#{e.}\n\n#{e.backtrace}" end response.code == '200' ? response.body : response_error(response) end |
#update ⇒ Object
48 49 50 |
# File 'lib/yahoo_stock/interface.rb', line 48 def update @values = nil end |
#uri ⇒ Object
Generates full url to connect to yahoo
35 36 37 38 39 40 41 |
# File 'lib/yahoo_stock/interface.rb', line 35 def uri raise InterfaceError, 'Base url is require to generate full uri.' unless @base_url return @base_url if @uri_parameters.nil? || @uri_parameters.empty? params_with_values = [] @uri_parameters.each {|k,v| params_with_values << "#{k}=#{v}"} @base_url+'?'+params_with_values.join('&') end |
#values ⇒ Object
Get result string
44 45 46 |
# File 'lib/yahoo_stock/interface.rb', line 44 def values @values ||= get end |