Class: Ytterb::Yql::Client
- Inherits:
-
Object
- Object
- Ytterb::Yql::Client
- Defined in:
- lib/ytterb/yql/client.rb
Instance Method Summary collapse
- #get_symbol_historical(my_symbol, start_date = nil, end_date = nil) ⇒ Object
- #get_yql_endpoint ⇒ Object
-
#initialize ⇒ Client
constructor
A new instance of Client.
- #run_select_query(query) ⇒ Object
Constructor Details
#initialize ⇒ Client
Returns a new instance of Client.
11 12 13 |
# File 'lib/ytterb/yql/client.rb', line 11 def initialize @endpoint = "http://query.yahooapis.com/v1/public/yql" end |
Instance Method Details
#get_symbol_historical(my_symbol, start_date = nil, end_date = nil) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/ytterb/yql/client.rb', line 28 def get_symbol_historical(my_symbol, start_date = nil, end_date = nil) requested_end = Date.parse(end_date) if end_date requested_end = Date.today unless requested_end requested_start = Date.parse(start_date) if start_date requested_start = requested_end - 30 unless requested_start run_select_query("select * from yahoo.finance.historicaldata" << " where symbol in (\"#{my_symbol}\")" << " and startDate='#{requested_start}'" << " and endDate='#{requested_end}'") end |
#get_yql_endpoint ⇒ Object
15 16 17 |
# File 'lib/ytterb/yql/client.rb', line 15 def get_yql_endpoint @endpoint end |
#run_select_query(query) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/ytterb/yql/client.rb', line 19 def run_select_query(query) RestClient.get("#{get_yql_endpoint}?q=#{CGI::escape(query)}&format=json&env=store://datatables.org/alltableswithkeys") do |response, request, result| raise ClientYqlError, "Failed performing YQLQuery\n" << "Request: #{request.inspect}\n" << "Response #{response.inspect}" unless response.code == 200 return Response.new(response).lines end end |