tiny-queries 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/tiny-queries.rb +60 -0
- metadata +44 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5e464ce85a67154de3fe030ca4fedae1e2d3a0ca
|
4
|
+
data.tar.gz: ccaa2a9141e1457f208a1933a1df8c916249d09e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ae55ba89e79a9588da400005d2b503ee72a7f256c71c8756ddc49cdca42d9e50f7928749da92d659a2d2feb598280c75202bf7f2034c6bfb8b7c2b360ac692ac
|
7
|
+
data.tar.gz: a79f0ab80a5bcd7c7928be7740e9317813af889f19da57391a60c04b5dd3b75d21362dd39c0f536e290278d1ce9464b492485bdeb48e2109f0f3bc8e716f5261
|
data/lib/tiny-queries.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
class TinyQueries
|
4
|
+
# This class can be used to call compiled queries generated by the TinyQueries compiler
|
5
|
+
#
|
6
|
+
# Example:
|
7
|
+
# >> tq = TinyQueries.new()
|
8
|
+
# >> tq.connector = "<executable TinyQueries connector>"
|
9
|
+
# >> result = tq.run("my-query")
|
10
|
+
#
|
11
|
+
|
12
|
+
# :connector should be set to an executable TinyQueries connector
|
13
|
+
attr_accessor :connector
|
14
|
+
|
15
|
+
# :globals is a hash to be used for global query parameters
|
16
|
+
# Global query parameters are send to each query call along with the regular query parameters
|
17
|
+
attr_accessor :globals
|
18
|
+
|
19
|
+
# Constructor
|
20
|
+
def initialize()
|
21
|
+
@connector = nil
|
22
|
+
@globals = {}
|
23
|
+
end
|
24
|
+
|
25
|
+
# Runs a query term and returns the result as a hash
|
26
|
+
# Params:
|
27
|
+
# +term+:: query term, like "a" or "a(b)" or "a:b"
|
28
|
+
# +params+:: a hash for the query parameters
|
29
|
+
def run(term, params=nil)
|
30
|
+
|
31
|
+
# Check if connector is set
|
32
|
+
if @connector.nil?
|
33
|
+
raise "You need to set connector first - calling queries without connector is not supported yet"
|
34
|
+
end
|
35
|
+
|
36
|
+
command = @connector + " \"" + term + "\""
|
37
|
+
|
38
|
+
# Add parameters to query call if present
|
39
|
+
if !params.nil?
|
40
|
+
if params.class != Hash
|
41
|
+
raise "Parameters should be passed as a Hash"
|
42
|
+
end
|
43
|
+
|
44
|
+
command += " \"" + JSON.generate( params.merge( @globals ) ).gsub(/\"/,"\\\"") + "\"";
|
45
|
+
end
|
46
|
+
|
47
|
+
# Execute the command and capture the output
|
48
|
+
json = `#{command}`
|
49
|
+
|
50
|
+
result = JSON.parse( json )
|
51
|
+
|
52
|
+
# Check if result contains error message
|
53
|
+
if result.class == Hash and result.has_key?("error")
|
54
|
+
raise result["error"]
|
55
|
+
end
|
56
|
+
|
57
|
+
return result
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
metadata
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tiny-queries
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Wouter Diesveld
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-07-20 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: ''
|
14
|
+
email: wouter@tinyqueries.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/tiny-queries.rb
|
20
|
+
homepage: http://tinyqueries.com
|
21
|
+
licenses:
|
22
|
+
- MIT
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubyforge_project:
|
40
|
+
rubygems_version: 2.2.3
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: TinyQueries client lib for Ruby
|
44
|
+
test_files: []
|