Class: QuasarRestClient::Proxy
- Inherits:
-
Object
- Object
- QuasarRestClient::Proxy
- Includes:
- HTTParty, MogrifyVars
- Defined in:
- lib/quasar_rest_client/proxy.rb
Instance Attribute Summary collapse
-
#query_hash ⇒ Hash
Values to form the query string for the request.
Instance Method Summary collapse
-
#delete_data(collection:) ⇒ String
JSON response.
-
#get_data(collection:) ⇒ String
JSON response.
-
#initialize(q = '', opts = {}) ⇒ Proxy
constructor
Set up the proxy object.
-
#long_query(destination:) ⇒ String
JSON response from post query.
-
#simple_query ⇒ String
JSON response from get query.
Methods included from MogrifyVars
Constructor Details
#initialize(q = '', opts = {}) ⇒ Proxy
Set up the proxy object
For the last option, :var
, the hash keys match the variable name used in
the query string. For example, given a query string of:
SELECT * WHERE pop < :cutoff
The var hash should have:
{ cutoff: 100 }
To set the value of the cutoff.
35 36 37 38 39 |
# File 'lib/quasar_rest_client/proxy.rb', line 35 def initialize(q='', opts={}) self.query_hash = Hash.new self.query_hash[:q] = q self.query_hash.merge!(opts) end |
Instance Attribute Details
#query_hash ⇒ Hash
Returns values to form the query string for the request.
11 12 13 |
# File 'lib/quasar_rest_client/proxy.rb', line 11 def query_hash @query_hash end |
Instance Method Details
#delete_data(collection:) ⇒ String
Returns JSON response.
90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/quasar_rest_client/proxy.rb', line 90 def delete_data(collection:) fail "must provide a collection: #{collection.inspect} [#{collection.class}]" unless (String === collection && collection.length > 0) unless collection[0] == ?/ collection = ?/ + collection end self.class.delete( '/data/fs' + collection, headers: request_headers, logger: Base.config.logger, base_uri: Base.config.endpoint ) end |
#get_data(collection:) ⇒ String
Returns JSON response.
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/quasar_rest_client/proxy.rb', line 69 def get_data(collection:) fail "must provide a collection: #{collection.inspect} [#{collection.class}]" unless (String === collection && collection.length > 0) unless collection[0] == ?/ collection = ?/ + collection end query_hash.delete(:q) query_hash.delete(:var) self.class.get( '/data/fs' + collection, query: request_query, headers: request_headers, logger: Base.config.logger, base_uri: Base.config.endpoint ) end |
#long_query(destination:) ⇒ String
Returns JSON response from post query.
54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/quasar_rest_client/proxy.rb', line 54 def long_query(destination:) fail "must provide a destination: #{destination.inspect} #{destination.class}" unless (String === destination && destination.length > 0) body = query_hash.delete(:q) self.class.post( '/query/fs', query: request_query, body: body, headers: request_headers.merge({"destination" => destination}), logger: Base.config.logger, base_uri: Base.config.endpoint ) end |
#simple_query ⇒ String
Returns JSON response from get query.
42 43 44 45 46 47 48 49 50 |
# File 'lib/quasar_rest_client/proxy.rb', line 42 def simple_query self.class.get( '/query/fs', query: request_query, headers: request_headers, logger: Base.config.logger, base_uri: Base.config.endpoint ) end |