quasar_rest_client 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +14 -0
- data/Rakefile +5 -0
- data/lib/quasar_rest_client.rb +25 -0
- data/lib/quasar_rest_client/mogrify_vars.rb +41 -0
- data/lib/quasar_rest_client/proxy.rb +58 -8
- data/lib/quasar_rest_client/version.rb +1 -1
- data/live_spec/config/config.sample.yml +11 -0
- data/live_spec/live_spec.rb +61 -0
- data/live_spec/live_spec_helper.rb +8 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: da105ccd0c72f3dc04e764b3426613e3c7e6dc6d
|
4
|
+
data.tar.gz: 469a399d6fc2f048170d497faefc84727196f5fe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 711a821b75a5d903da87b3642acb867121d86e02f156a6f0443b31dc477a712fb7667b7be638f67a8079366c44a6f42e66fb1bf0c2f67337296f3d976c515e6b
|
7
|
+
data.tar.gz: b98c29831f3ec5cd58127a6b507de54d1144e43549245d537f0e5927dcbad446eb9027dab59d6c7eabc649207874406f56df11c104eea9202d8b1b57d32962fe
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -105,6 +105,20 @@ install`. To release a new version, update the version number in
|
|
105
105
|
create a git tag for the version, push git commits and tags, and push
|
106
106
|
the `.gem` file to [rubygems.org](https://rubygems.org).
|
107
107
|
|
108
|
+
### Live Testing
|
109
|
+
|
110
|
+
To live test the client, you will need a working quasar server, and a
|
111
|
+
working mongodb server with data in it.
|
112
|
+
|
113
|
+
The `./live_spec` directory contains the spec tests for live testing,
|
114
|
+
and depends up on the `./live_spec/config/config.yml` file to be set
|
115
|
+
with the appropriate information to make the connection work. You can
|
116
|
+
copy the `./live_spec/config/config.sample.yml` file and fill in the
|
117
|
+
details.
|
118
|
+
|
119
|
+
A rake task `live_spec` is also available to make running these tests
|
120
|
+
simpler.
|
121
|
+
|
108
122
|
## Contributing
|
109
123
|
|
110
124
|
Bug reports and pull requests are welcome on GitHub at
|
data/Rakefile
CHANGED
data/lib/quasar_rest_client.rb
CHANGED
@@ -71,4 +71,29 @@ module QuasarRestClient
|
|
71
71
|
proxy.simple_query
|
72
72
|
end
|
73
73
|
|
74
|
+
# @param [String] q - query string
|
75
|
+
# @param [String] dest - destination collection to create
|
76
|
+
# @param [Hash] opts - options
|
77
|
+
# @return [String] JSON reponse
|
78
|
+
def self.long_query(q='', dest='', opts={})
|
79
|
+
proxy = Proxy.new(q, opts)
|
80
|
+
proxy.long_query(destination: dest)
|
81
|
+
end
|
82
|
+
|
83
|
+
# @param [String] coll - collection to retrieve
|
84
|
+
# @param [Hash] opts - options
|
85
|
+
# @return [String] JSON reponse
|
86
|
+
def self.get_data(coll='', opts={})
|
87
|
+
proxy = Proxy.new(nil, opts)
|
88
|
+
proxy.get_data(collection: coll)
|
89
|
+
end
|
90
|
+
|
91
|
+
# @param [String] coll - collection to delete
|
92
|
+
# @param [Hash] opts - options
|
93
|
+
# @return [String] JSON reponse
|
94
|
+
def self.delete_data(coll='', opts={})
|
95
|
+
proxy = Proxy.new(nil, opts)
|
96
|
+
proxy.delete_data(collection: coll)
|
97
|
+
end
|
98
|
+
|
74
99
|
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'time'
|
2
|
+
require 'date'
|
3
|
+
|
4
|
+
# Include this module
|
5
|
+
module QuasarRestClient
|
6
|
+
module MogrifyVars
|
7
|
+
|
8
|
+
def mogrify_vars(hash)
|
9
|
+
vars = hash[:var]&.map do |k, v|
|
10
|
+
new_key = "var.#{k}"
|
11
|
+
|
12
|
+
# This is hacky-hack, at best
|
13
|
+
# E.g. given var: { email: "yacht@mail.com"} =>
|
14
|
+
# var.email: '"yacht@mail.com"'
|
15
|
+
# i.e. quasar requires the double quotes
|
16
|
+
# Note that the documentation says single quotes, but it is WRONG
|
17
|
+
new_val = case v
|
18
|
+
when String
|
19
|
+
v.inspect
|
20
|
+
# NOTE: order is important: DateTime must precede Date
|
21
|
+
when DateTime
|
22
|
+
"TIMESTAMP '#{v.strftime("%F %T")}'"
|
23
|
+
when Date
|
24
|
+
"DATE '#{v.strftime("%F")}'"
|
25
|
+
when Time
|
26
|
+
"TIME '#{v.strftime("%T")}'"
|
27
|
+
when Array
|
28
|
+
v.inspect
|
29
|
+
else
|
30
|
+
v
|
31
|
+
end
|
32
|
+
|
33
|
+
[new_key, new_val]
|
34
|
+
end.to_h
|
35
|
+
|
36
|
+
hash.delete(:var)
|
37
|
+
hash.merge(vars)
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
@@ -1,8 +1,10 @@
|
|
1
1
|
require "httparty"
|
2
|
+
require "quasar_rest_client/mogrify_vars"
|
2
3
|
|
3
4
|
module QuasarRestClient
|
4
5
|
class Proxy
|
5
6
|
include HTTParty
|
7
|
+
include MogrifyVars
|
6
8
|
|
7
9
|
# @!attribute query_hash
|
8
10
|
# @return [Hash] values to form the query string for the request
|
@@ -36,10 +38,10 @@ module QuasarRestClient
|
|
36
38
|
self.query_hash.merge!(opts)
|
37
39
|
end
|
38
40
|
|
39
|
-
# @return [String] JSON response from query
|
41
|
+
# @return [String] JSON response from get query
|
40
42
|
def simple_query
|
41
43
|
self.class.get(
|
42
|
-
|
44
|
+
'/query/fs',
|
43
45
|
query: request_query,
|
44
46
|
headers: request_headers,
|
45
47
|
logger: Base.config.logger,
|
@@ -47,17 +49,65 @@ module QuasarRestClient
|
|
47
49
|
)
|
48
50
|
end
|
49
51
|
|
52
|
+
# @param [String] destination collection name to create for later extraction
|
53
|
+
# @return [String] JSON response from post query
|
54
|
+
def long_query(destination:)
|
55
|
+
fail "must provide a destination: #{destination.inspect} #{destination.class}" unless (String === destination && destination.length > 0)
|
56
|
+
body = query_hash.delete(:q)
|
57
|
+
self.class.post(
|
58
|
+
'/query/fs',
|
59
|
+
query: request_query,
|
60
|
+
body: body,
|
61
|
+
headers: request_headers.merge({"destination" => destination}),
|
62
|
+
logger: Base.config.logger,
|
63
|
+
base_uri: Base.config.endpoint
|
64
|
+
)
|
65
|
+
end
|
66
|
+
|
67
|
+
# @param [String] collection name of the collection to retrieve
|
68
|
+
# @return [String] JSON response
|
69
|
+
def get_data(collection:)
|
70
|
+
fail "must provide a collection: #{collection.inspect} [#{collection.class}]" unless (String === collection && collection.length > 0)
|
71
|
+
|
72
|
+
unless collection[0] == ?/
|
73
|
+
collection = ?/ + collection
|
74
|
+
end
|
75
|
+
|
76
|
+
query_hash.delete(:q)
|
77
|
+
query_hash.delete(:var)
|
78
|
+
|
79
|
+
self.class.get(
|
80
|
+
'/data/fs' + collection,
|
81
|
+
query: request_query,
|
82
|
+
headers: request_headers,
|
83
|
+
logger: Base.config.logger,
|
84
|
+
base_uri: Base.config.endpoint
|
85
|
+
)
|
86
|
+
end
|
87
|
+
|
88
|
+
# @param [String] collection name of the collection to delete
|
89
|
+
# @return [String] JSON response
|
90
|
+
def delete_data(collection:)
|
91
|
+
fail "must provide a collection: #{collection.inspect} [#{collection.class}]" unless (String === collection && collection.length > 0)
|
92
|
+
|
93
|
+
unless collection[0] == ?/
|
94
|
+
collection = ?/ + collection
|
95
|
+
end
|
96
|
+
|
97
|
+
self.class.delete(
|
98
|
+
'/data/fs' + collection,
|
99
|
+
headers: request_headers,
|
100
|
+
logger: Base.config.logger,
|
101
|
+
base_uri: Base.config.endpoint
|
102
|
+
)
|
103
|
+
end
|
104
|
+
|
50
105
|
private
|
51
106
|
|
52
107
|
def endpoint
|
53
108
|
Base.config.endpoint
|
54
109
|
end
|
55
110
|
|
56
|
-
# TODO: return proper path based on query type for future expansion
|
57
|
-
def path
|
58
|
-
'/query/fs'
|
59
|
-
end
|
60
|
-
|
61
111
|
def request_headers
|
62
112
|
{
|
63
113
|
"accept-encoding" => '',
|
@@ -66,7 +116,7 @@ module QuasarRestClient
|
|
66
116
|
end
|
67
117
|
|
68
118
|
def request_query
|
69
|
-
stringify_keys(query_hash)
|
119
|
+
stringify_keys(mogrify_vars(query_hash))
|
70
120
|
end
|
71
121
|
|
72
122
|
def stringify_keys(hash)
|
@@ -0,0 +1,61 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "live_spec_helper"
|
4
|
+
require "logger"
|
5
|
+
require 'ostruct'
|
6
|
+
require "erb"
|
7
|
+
require "yaml"
|
8
|
+
|
9
|
+
def read_config(file = File.join(File.dirname(__FILE__), 'config', 'config.yml'))
|
10
|
+
conf = YAML.load(ERB.new(File.read(file)).result)
|
11
|
+
OpenStruct.new(conf)
|
12
|
+
end
|
13
|
+
|
14
|
+
def show_response(resp)
|
15
|
+
"response code: #{resp.code} \n" +
|
16
|
+
"response request: #{resp.request.uri}"
|
17
|
+
end
|
18
|
+
|
19
|
+
RSpec.describe "Live Testing" do
|
20
|
+
let(:config) { read_config }
|
21
|
+
let!(:collection_path) { ["", config.mount, config.parent, config.collection].join('/') }
|
22
|
+
let!(:new_collection_path) { ["", config.mount, config.parent, config.new_collection].join('/') }
|
23
|
+
let!(:endpoint) { "http://#{config.endpoint_host}:#{config.endpoint_port}" }
|
24
|
+
let!(:sql_format) { "SELECT %s FROM `#{collection_path}` WHERE #{config.where_clause}" }
|
25
|
+
let!(:sql_count) { sql_format % "count(*)" }
|
26
|
+
let!(:sql_fetch) { sql_format % "*" }
|
27
|
+
let!(:logger) { nil }
|
28
|
+
|
29
|
+
before do
|
30
|
+
QuasarRestClient.config.endpoint = endpoint
|
31
|
+
QuasarRestClient.config.logger = logger
|
32
|
+
end
|
33
|
+
|
34
|
+
it "count_query" do
|
35
|
+
resp = QuasarRestClient.simple_query(sql_count, var: config.vars)
|
36
|
+
expect(resp.code).to(eq(200), show_response(resp))
|
37
|
+
end
|
38
|
+
|
39
|
+
it "fetch_query" do
|
40
|
+
resp = QuasarRestClient.simple_query(sql_fetch, limit: 2, var: config.vars)
|
41
|
+
expect(resp.code).to(eq(200), show_response(resp))
|
42
|
+
end
|
43
|
+
|
44
|
+
it "long_query" do
|
45
|
+
resp = QuasarRestClient.long_query(sql_fetch, new_collection_path, var: config.vars)
|
46
|
+
expect(resp.code).to(eq(200), show_response(resp))
|
47
|
+
end
|
48
|
+
|
49
|
+
it "get_data" do
|
50
|
+
QuasarRestClient.long_query(sql_fetch, new_collection_path, var: config.vars)
|
51
|
+
resp = QuasarRestClient.get_data(new_collection_path, limit: 2)
|
52
|
+
expect(resp.code).to(eq(200), show_response(resp))
|
53
|
+
end
|
54
|
+
|
55
|
+
it "delete_data" do
|
56
|
+
QuasarRestClient.long_query(sql_fetch, new_collection_path, var: config.vars)
|
57
|
+
resp = QuasarRestClient.delete_data(new_collection_path, limit: 2)
|
58
|
+
expect(resp.code).to(eq(204), show_response(resp))
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: quasar_rest_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tamara Temple
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-08-
|
11
|
+
date: 2016-08-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -134,8 +134,12 @@ files:
|
|
134
134
|
- lib/quasar_rest_client.rb
|
135
135
|
- lib/quasar_rest_client/base.rb
|
136
136
|
- lib/quasar_rest_client/config.rb
|
137
|
+
- lib/quasar_rest_client/mogrify_vars.rb
|
137
138
|
- lib/quasar_rest_client/proxy.rb
|
138
139
|
- lib/quasar_rest_client/version.rb
|
140
|
+
- live_spec/config/config.sample.yml
|
141
|
+
- live_spec/live_spec.rb
|
142
|
+
- live_spec/live_spec_helper.rb
|
139
143
|
- quasar_rest_client.gemspec
|
140
144
|
homepage: https://github.com/riverock/quasar_rest_client
|
141
145
|
licenses: []
|