Class: QuasarRestClient::Proxy

Inherits:
Object
  • Object
show all
Includes:
HTTParty, MogrifyVars
Defined in:
lib/quasar_rest_client/proxy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from MogrifyVars

#mogrify_vars

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.

Parameters:

  • q (String) (defaults to: '')

    -- the SQL^2 query string passed in WITHOUT encoding

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

    -- options to pass along to the Quasar request

Options Hash (opts):

  • :limit (Integer)

    -- limit to the number of records retrieved

  • :offset (Integer)

    -- starting record

  • :var (Hash)

    -- variable substitutions for parametric queries



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_hashHash

Returns values to form the query string for the request.

Returns:

  • (Hash)

    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.

Parameters:

  • collection (String)

    name of the collection to delete

Returns:

  • (String)

    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.

Parameters:

  • collection (String)

    name of the collection to retrieve

Returns:

  • (String)

    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.

Parameters:

  • destination (String)

    collection name to create for later extraction

Returns:

  • (String)

    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_queryString

Returns JSON response from get query.

Returns:

  • (String)

    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