Module: Query28io

Defined in:
lib/query_28io.rb

Overview

This module allows to run public 28.io queries

Class Method Summary collapse

Class Method Details

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

This method run a public 28.io query at the specified URL and return its results.

A GET request will be issued to the specified URL. Optionally, you can specify one or more parameters to be passed to the query. They will be passed to the specified query by means of the request URL.

The server response will be returned as an RestClient::Response object. The code, cookies, and body methods can be used to retrieve the server response code, cookies and body respectively. Additional information can be found at rubydoc.info/gems/rest-client/1.6.7/frames.

Example:

>>response = Query28io.runQuery "http://example.28.io/example.jq"
>>response.code
# => 200
>>response.body
# => {...}

Example, with optional parameters:

>>response = Query28io.runQuery "http://example.28.io/example.jq", {:foo => 'bar'}
>>response.code
# => 200
>>response.body
# => {...}

Parameters:

  • url (String)

    the public query URL

  • params (Hash) (defaults to: {})

    the query arguments (optional)

Returns:

  • (Object)

    server respose



42
43
44
# File 'lib/query_28io.rb', line 42

def self.runQuery(url, params={})
  RestClient.get(url, {:params => params}){|response, request, result| response }
end

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

This method run a public 28.io query at the specified URL and return its results.

A POST request will be issued to the specified URL. Optionally, you can specify one or more parameters to be passed to the query. They will be passed to the specified query by means of the request body.

The server response will be returned as an RestClient::Response object. The code, cookies, and body methods can be used to retrieve the server response code, cookies and body respectively. Additional information can be found at rubydoc.info/gems/rest-client/1.6.7/frames.

Example:

>>response = Query28io.runQuery "http://example.28.io/example.jq"
>>response.code
# => 200
>>response.body
# => {...}

Example, with optional parameters:

>>response = Query28io.runQuery "http://example.28.io/example.jq", {:foo => 'bar'}
>>response.code
# => 200
>>response.body
# => {...}

Parameters:

  • url (String)

    the public query URL

  • params (Hash) (defaults to: {})

    the query arguments (optional)

Returns:

  • (Object)

    server respose



79
80
81
# File 'lib/query_28io.rb', line 79

def self.runQueryPost(url, params ={})
  RestClient.post(url, params){|response, request, result| response }
end