Class: WolframAlpha::Client
- Inherits:
-
Object
- Object
- WolframAlpha::Client
- Defined in:
- library/wolfram-alpha/client.rb
Constant Summary collapse
- Options =
The default options for a new client, it is merged with the options set upon initialization.
{ timeout: 15 }
Instance Attribute Summary collapse
-
#token ⇒ Object
The Wolfram|Alpha API application id, which is set upon initialization.
Instance Method Summary collapse
-
#initialize(token, options = {}) ⇒ Client
constructor
Initialize a new client to communicate with the Wolfram|Alpha API.
-
#query(input) ⇒ Response
Compute the result of
input
, and return a new response.
Constructor Details
#initialize(token, options = {}) ⇒ Client
Initialize a new client to communicate with the Wolfram|Alpha API.
21 22 23 24 25 |
# File 'library/wolfram-alpha/client.rb', line 21 def initialize token, = {} @http = Net::HTTP.new RequestURI.host, RequestURI.port @token = token or raise "Invalid token" @options = Options.merge end |
Instance Attribute Details
#token ⇒ Object
The Wolfram|Alpha API application id, which is set upon initialization.
6 7 8 |
# File 'library/wolfram-alpha/client.rb', line 6 def token @token end |
Instance Method Details
#query(input) ⇒ Response
Compute the result of input
, and return a new response.
32 33 34 35 36 37 38 39 40 41 |
# File 'library/wolfram-alpha/client.rb', line 32 def query input response = @http.get request_url(input).request_uri document = Nokogiri::XML response.body if document.root.name == "queryresult" Response.new document else raise "Invalid response" end end |