Class: Yql::Client
- Inherits:
-
Object
- Object
- Yql::Client
- Defined in:
- lib/yql/client.rb
Constant Summary collapse
- BASE_URL =
'query.yahooapis.com'
- VERSION =
'v1'
- URL_SUFFIX =
'public/yql'
- YQL_ENV =
'http://datatables.org/alltables.env'
Instance Attribute Summary collapse
-
#diagnostics ⇒ Object
Returns the value of attribute diagnostics.
-
#format ⇒ Object
Returns the value of attribute format.
-
#query ⇒ Object
Returns the value of attribute query.
Instance Method Summary collapse
- #add_diagnostics(existing_parameters) ⇒ Object
- #add_format(existing_parameters) ⇒ Object
- #full_url ⇒ Object
- #get ⇒ Object
-
#initialize(args = {}) ⇒ Client
constructor
A new instance of Client.
- #parameters ⇒ Object
- #version ⇒ Object
Constructor Details
#initialize(args = {}) ⇒ Client
Returns a new instance of Client.
12 13 14 15 16 17 |
# File 'lib/yql/client.rb', line 12 def initialize(args={}) @diagnostics = args[:diagnostics] #true or false @version = args[:version] @query = args[:query] @format = args[:format] || 'xml' end |
Instance Attribute Details
#diagnostics ⇒ Object
Returns the value of attribute diagnostics.
10 11 12 |
# File 'lib/yql/client.rb', line 10 def diagnostics @diagnostics end |
#format ⇒ Object
Returns the value of attribute format.
10 11 12 |
# File 'lib/yql/client.rb', line 10 def format @format end |
#query ⇒ Object
Returns the value of attribute query.
10 11 12 |
# File 'lib/yql/client.rb', line 10 def query @query end |
Instance Method Details
#add_diagnostics(existing_parameters) ⇒ Object
53 54 55 56 57 |
# File 'lib/yql/client.rb', line 53 def add_diagnostics(existing_parameters) return unless existing_parameters return existing_parameters unless diagnostics return existing_parameters + "&diagnostics=true" end |
#add_format(existing_parameters) ⇒ Object
47 48 49 50 51 |
# File 'lib/yql/client.rb', line 47 def add_format(existing_parameters) return unless existing_parameters return existing_parameters unless format return existing_parameters + "&format=#{format}" end |
#full_url ⇒ Object
27 28 29 |
# File 'lib/yql/client.rb', line 27 def full_url "#{version}/#{URL_SUFFIX}" end |
#get ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/yql/client.rb', line 31 def get if query.nil? raise Yql::IncompleteRequestParameter, "Query not specified" end http = Net::HTTP.new(BASE_URL, Net::HTTP.https_default_port) http.use_ssl = true path = "/#{version}/#{URL_SUFFIX}" Yql::Response.new(http.post(path, parameters), format) end |
#parameters ⇒ Object
41 42 43 44 45 |
# File 'lib/yql/client.rb', line 41 def parameters url_parameters = "q=#{CGI.escape(query)}&env=#{YQL_ENV}" url_parameters = add_format(url_parameters) add_diagnostics(url_parameters) end |
#version ⇒ Object
23 24 25 |
# File 'lib/yql/client.rb', line 23 def version @version ||= VERSION end |