osc_ruby 1.0.3 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Rakefile +1 -0
- data/lib/osc_ruby.rb +2 -1
- data/lib/osc_ruby/classes/query_results.rb +4 -14
- data/lib/osc_ruby/classes/query_results_set.rb +40 -0
- data/lib/osc_ruby/modules/normalize_module.rb +29 -44
- data/lib/osc_ruby/version.rb +1 -1
- data/spec/core/connect_spec.rb +7 -5
- data/spec/core/query_results_set_spec.rb +109 -0
- data/spec/core/query_results_spec.rb +6 -4
- data/spec/core/spec_helper.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: addca70579faf163b99b0b41f76e84f500c3cad4
|
4
|
+
data.tar.gz: b945a6eb88f1c95752a9191bbaa3eaac7a0ebf4a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 97dab4e79cfbcd88c0679b8c8e482939a578192431017d6bd24cc11f00b7b743488ca325cafaf60e749e5026c0db966c93700a6a26c7e9b65b61a8646a621dd4
|
7
|
+
data.tar.gz: 5bef5ced6a2eb9b464ebf89e75e8bb056b64a5bf557e9216bd744ce600fef9ea912751f353b71a303d501f7ac285f2f5a5b523c4807218d271652b6b29fafe59
|
data/Rakefile
CHANGED
data/lib/osc_ruby.rb
CHANGED
@@ -13,7 +13,7 @@ module OSCRuby
|
|
13
13
|
|
14
14
|
def initialize; end
|
15
15
|
|
16
|
-
def query(client,query
|
16
|
+
def query(client,query)
|
17
17
|
|
18
18
|
ValidationsModule::check_client(client)
|
19
19
|
|
@@ -23,21 +23,11 @@ module OSCRuby
|
|
23
23
|
|
24
24
|
response = QueryModule::find(client,@query)
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
if return_json == true
|
29
|
-
json_response_final = NormalizeModule::query_injection(query,json_response)
|
30
|
-
puts json_response_final
|
31
|
-
end
|
32
|
-
|
33
|
-
if return_json.class == Hash
|
34
|
-
puts json_response.body
|
35
|
-
else
|
36
|
-
json_response.unshift("\n")
|
37
|
-
NormalizeModule::remove_new_lines(json_response)
|
38
|
-
end
|
26
|
+
JSON.parse(response)
|
39
27
|
|
40
28
|
end
|
29
|
+
|
30
|
+
|
41
31
|
|
42
32
|
end
|
43
33
|
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require_relative 'query_results'
|
2
|
+
require 'osc_ruby/modules/validations_module'
|
3
|
+
require 'ostruct'
|
4
|
+
|
5
|
+
module OSCRuby
|
6
|
+
|
7
|
+
class QueryResultsSet < OpenStruct
|
8
|
+
|
9
|
+
include ValidationsModule
|
10
|
+
|
11
|
+
def query_set(client,*args)
|
12
|
+
|
13
|
+
ValidationsModule::check_client(client)
|
14
|
+
|
15
|
+
query_arr = []
|
16
|
+
|
17
|
+
key_map = []
|
18
|
+
|
19
|
+
args.each do |qh|
|
20
|
+
|
21
|
+
key_map.push(qh[:key])
|
22
|
+
|
23
|
+
query_arr.push(qh[:query])
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
query_results_set = OpenStruct.new
|
28
|
+
query_search = OSCRuby::QueryResults.new
|
29
|
+
|
30
|
+
|
31
|
+
final_query_arr = query_arr.join('; ')
|
32
|
+
final_results = query_search.query(client,final_query_arr)
|
33
|
+
|
34
|
+
key_map.each_with_index {|k,i| query_results_set[k] = final_results[i]}
|
35
|
+
query_results_set
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
@@ -16,30 +16,45 @@ module OSCRuby
|
|
16
16
|
|
17
17
|
json_input = JSON.parse(input.body)
|
18
18
|
|
19
|
+
# initialize an array to hold all of the objects
|
19
20
|
final_hash = []
|
20
21
|
|
22
|
+
# loop through the items from the returned JSON response
|
21
23
|
json_input['items'].each do |item|
|
22
24
|
|
23
|
-
|
25
|
+
results_array = []
|
24
26
|
|
25
|
-
|
26
|
-
|
27
|
-
item['columnNames'].each_with_index do |column,i|
|
28
|
-
obj_hash[column] = if !row[i].nil? && row[i].is_i? == true then row[i].to_i else row[i] end
|
29
|
-
end
|
27
|
+
# loop through rows
|
28
|
+
item['rows'].each_with_index do |row,row_i|
|
30
29
|
|
31
|
-
|
30
|
+
# initialize a hash to create the object
|
31
|
+
obj_hash = {}
|
32
|
+
|
33
|
+
# loop through the column names from the query
|
34
|
+
item['columnNames'].each_with_index do |column,i|
|
32
35
|
|
33
|
-
|
36
|
+
# set the object property to the value of the row
|
37
|
+
# where the index of the value within that row
|
38
|
+
# matches the index of the column name
|
39
|
+
obj_hash[column] = if !row[i].nil? && row[i].is_i? == true then row[i].to_i else row[i] end
|
40
|
+
end
|
34
41
|
|
35
|
-
|
42
|
+
# push the hash into the array
|
43
|
+
results_array.push(obj_hash)
|
36
44
|
|
37
|
-
|
45
|
+
end
|
38
46
|
|
39
|
-
|
47
|
+
# puts "this is an array: #{final_hash}"
|
48
|
+
final_hash.push(results_array)
|
40
49
|
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
if final_hash.size === 1
|
54
|
+
final_hash = final_hash.flatten!
|
41
55
|
end
|
42
56
|
|
57
|
+
|
43
58
|
final_hash.to_json
|
44
59
|
|
45
60
|
end
|
@@ -55,7 +70,7 @@ module OSCRuby
|
|
55
70
|
else
|
56
71
|
|
57
72
|
json_input = JSON.parse(input.body)
|
58
|
-
|
73
|
+
|
59
74
|
final_hash = []
|
60
75
|
|
61
76
|
json_input['items'].each do |item|
|
@@ -78,7 +93,6 @@ module OSCRuby
|
|
78
93
|
|
79
94
|
end
|
80
95
|
|
81
|
-
puts JSON.pretty_generate(final_hash)
|
82
96
|
|
83
97
|
final_hash.to_json
|
84
98
|
|
@@ -86,37 +100,8 @@ module OSCRuby
|
|
86
100
|
|
87
101
|
end
|
88
102
|
|
89
|
-
def query_injection(query,json_response)
|
90
|
-
|
91
|
-
queries = query.split(';')
|
92
|
-
|
93
|
-
count = 0
|
94
|
-
|
95
|
-
json_response.each_with_index do |hash,i|
|
96
|
-
if hash == "\n" && queries.count > 1
|
97
|
-
json_response[i] = "\nResults for #{queries[count]}:"
|
98
|
-
count += 1
|
99
|
-
elsif hash == "\n"
|
100
|
-
json_response.delete_at(i)
|
101
|
-
elsif json_response.last == "\n"
|
102
|
-
json_response.delete_at(json_response.count - 1)
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
json_response
|
107
|
-
|
108
|
-
end
|
109
|
-
|
110
|
-
def remove_new_lines(json_response)
|
111
|
-
json_response.each_with_index do |hash,i|
|
112
|
-
if hash == "\n"
|
113
|
-
json_response.delete_at(i)
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
json_response
|
118
|
-
end
|
119
|
-
|
120
103
|
end
|
104
|
+
|
121
105
|
end
|
106
|
+
|
122
107
|
end
|
data/lib/osc_ruby/version.rb
CHANGED
data/spec/core/connect_spec.rb
CHANGED
@@ -10,13 +10,15 @@ describe OSCRuby::Connect do
|
|
10
10
|
|
11
11
|
OSCRuby::Client.new do |config|
|
12
12
|
|
13
|
-
config.interface = ENV['
|
13
|
+
config.interface = ENV['OSC_SITE']
|
14
14
|
|
15
|
-
config.username = ENV['
|
15
|
+
config.username = ENV['OSC_ADMIN']
|
16
16
|
|
17
|
-
config.password = ENV['
|
17
|
+
config.password = ENV['OSC_PASSWORD']
|
18
18
|
|
19
19
|
config.suppress_rules = true
|
20
|
+
|
21
|
+
config.demo_site = true
|
20
22
|
|
21
23
|
end
|
22
24
|
}
|
@@ -128,9 +130,9 @@ describe OSCRuby::Connect do
|
|
128
130
|
|
129
131
|
expect(final_config['site_url']).to be_an(URI::HTTPS)
|
130
132
|
|
131
|
-
expect(final_config['username']).to eq(ENV['
|
133
|
+
expect(final_config['username']).to eq(ENV['OSC_ADMIN'])
|
132
134
|
|
133
|
-
expect(final_config['password']).to eq(ENV['
|
135
|
+
expect(final_config['password']).to eq(ENV['OSC_PASSWORD'])
|
134
136
|
|
135
137
|
end
|
136
138
|
|
@@ -0,0 +1,109 @@
|
|
1
|
+
require 'core/spec_helper'
|
2
|
+
require 'json'
|
3
|
+
require 'uri'
|
4
|
+
|
5
|
+
describe OSCRuby::QueryResultsSet do
|
6
|
+
|
7
|
+
let(:client) {
|
8
|
+
|
9
|
+
OSCRuby::Client.new do |config|
|
10
|
+
|
11
|
+
config.interface = ENV['OSC_SITE']
|
12
|
+
|
13
|
+
config.username = ENV['OSC_ADMIN']
|
14
|
+
|
15
|
+
config.password = ENV['OSC_PASSWORD']
|
16
|
+
|
17
|
+
config.demo_site = true
|
18
|
+
|
19
|
+
end
|
20
|
+
}
|
21
|
+
|
22
|
+
let(:query_results_set){
|
23
|
+
OSCRuby::QueryResultsSet.new
|
24
|
+
}
|
25
|
+
|
26
|
+
|
27
|
+
|
28
|
+
let(:table){ "answers" }
|
29
|
+
let(:nested_attributes){
|
30
|
+
[ "*",
|
31
|
+
"accessLevels.namedIDList.*",
|
32
|
+
"answerType.*",
|
33
|
+
"assignedTo.account.*",
|
34
|
+
"assignedTo.staffGroup.*",
|
35
|
+
"banner.*",
|
36
|
+
"banner.importanceFlag.*",
|
37
|
+
"banner.updatedByAccount.*",
|
38
|
+
"categories.categoriesList.*",
|
39
|
+
"commonAttachments.fileAttachmentList.*",
|
40
|
+
"commonAttachments.fileAttachmentList.names.labelList.labelText",
|
41
|
+
"commonAttachments.fileAttachmentList.names.labelList.language.*",
|
42
|
+
"fileAttachments.fileAttachmentList.*",
|
43
|
+
"guidedAssistance.*",
|
44
|
+
"language.*",
|
45
|
+
"notes.noteList.*",
|
46
|
+
"positionInList.*",
|
47
|
+
"products.productsList.*",
|
48
|
+
"relatedAnswers.answerRelatedAnswerList.*",
|
49
|
+
"relatedAnswers.answerRelatedAnswerList.toAnswer.*",
|
50
|
+
"siblingAnswers.*",
|
51
|
+
"statusWithType.statusType.*",
|
52
|
+
"updatedByAccount.*",
|
53
|
+
"customFields.c.*"
|
54
|
+
]
|
55
|
+
}
|
56
|
+
|
57
|
+
|
58
|
+
context "#query_set" do
|
59
|
+
|
60
|
+
it 'should expect client is an instance of OSCRuby::Client class and raise an error if does not' do
|
61
|
+
|
62
|
+
expect(client).to be_an(OSCRuby::Client)
|
63
|
+
|
64
|
+
client = nil
|
65
|
+
|
66
|
+
expect{query_results_set.query_set(client,'describe')}.to raise_error('Client must have some configuration set; please create an instance of OSCRuby::Client with configuration settings')
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
|
71
|
+
## TO DO
|
72
|
+
|
73
|
+
# it 'should expect a hash with a key and query value set' do
|
74
|
+
|
75
|
+
# expect(client).to be_an(OSCRuby::Client)
|
76
|
+
|
77
|
+
# expect{query_results_set.query_set(client,"")}.to raise_error("A query must be specified when using the 'query' method")
|
78
|
+
|
79
|
+
# end
|
80
|
+
|
81
|
+
|
82
|
+
it 'should return results in set of OSCRuby::QueryResults',:vcr do
|
83
|
+
|
84
|
+
expect(query_results_set.query_set(client,{key:"answers", query:"select * from answers LIMIT 2"},
|
85
|
+
{key:"incidents", query:"describe incidents"})).to be_an(OpenStruct)
|
86
|
+
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'should be able to manipulate and assign results data',:vcr do
|
91
|
+
|
92
|
+
test = query_results_set.query_set(client, {key:"incidents", query:"select * from incidents limit 10"},
|
93
|
+
{key:"serviceCategories", query:"describe serviceCategories"})
|
94
|
+
expect(test.incidents).to be_an(Array)
|
95
|
+
expect(test.incidents.first).to be_a(Hash)
|
96
|
+
expect(test.incidents.first['id']).to be_a(Fixnum)
|
97
|
+
expect(test.serviceCategories).to be_an(Array)
|
98
|
+
|
99
|
+
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'should be able to take multiple queries', :vcr do
|
103
|
+
answer_attrs = nested_attributes.map { |attr| {key: attr, query: "SELECT #{attr} FROM #{table} WHERE ID = 1"} }
|
104
|
+
test = query_results_set.query_set(client,*answer_attrs)
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
@@ -8,11 +8,13 @@ describe OSCRuby::QueryResults do
|
|
8
8
|
|
9
9
|
OSCRuby::Client.new do |config|
|
10
10
|
|
11
|
-
config.interface = ENV['
|
11
|
+
config.interface = ENV['OSC_SITE']
|
12
12
|
|
13
|
-
config.username = ENV['
|
13
|
+
config.username = ENV['OSC_ADMIN']
|
14
14
|
|
15
|
-
config.password = ENV['
|
15
|
+
config.password = ENV['OSC_PASSWORD']
|
16
|
+
|
17
|
+
config.demo_site = true
|
16
18
|
|
17
19
|
end
|
18
20
|
}
|
@@ -81,7 +83,7 @@ describe OSCRuby::QueryResults do
|
|
81
83
|
|
82
84
|
# expect(query_results.query(client,"describe answers")).not_to eq(nil)
|
83
85
|
|
84
|
-
expect(query_results.query(client,"describe answers;describe serviceproducts"
|
86
|
+
expect(query_results.query(client,"describe answers;describe serviceproducts")).to be_an(Array)
|
85
87
|
|
86
88
|
# expect(query_results.query(client,"describe answers;describe servicecategories")).not_to eq(nil)
|
87
89
|
|
data/spec/core/spec_helper.rb
CHANGED
@@ -9,7 +9,7 @@ VCR.configure do |c|
|
|
9
9
|
c.allow_http_connections_when_no_cassette = true
|
10
10
|
c.filter_sensitive_data('<OSC_ADMIN_USERNAME>') { ENV['OSC_ADMIN'] }
|
11
11
|
c.filter_sensitive_data('<OSC_ADMIN_PASSWORD>') { ENV['OSC_PASSWORD'] }
|
12
|
-
c.filter_sensitive_data('<TEST_INTERFACE>') { ENV['
|
12
|
+
c.filter_sensitive_data('<TEST_INTERFACE>') { ENV['OSC_SITE'] }
|
13
13
|
c.filter_sensitive_data('<BASIC_AUTH>') { ENV['OSC_BASIC_64'] }
|
14
14
|
end
|
15
15
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: osc_ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rajan Davis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-08-
|
11
|
+
date: 2017-08-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: simplecov
|
@@ -160,6 +160,7 @@ files:
|
|
160
160
|
- lib/ext/string.rb
|
161
161
|
- lib/osc_ruby.rb
|
162
162
|
- lib/osc_ruby/classes/query_results.rb
|
163
|
+
- lib/osc_ruby/classes/query_results_set.rb
|
163
164
|
- lib/osc_ruby/client.rb
|
164
165
|
- lib/osc_ruby/configuration.rb
|
165
166
|
- lib/osc_ruby/connect.rb
|
@@ -172,6 +173,7 @@ files:
|
|
172
173
|
- spec/core/client_spec.rb
|
173
174
|
- spec/core/configuration_spec.rb
|
174
175
|
- spec/core/connect_spec.rb
|
176
|
+
- spec/core/query_results_set_spec.rb
|
175
177
|
- spec/core/query_results_spec.rb
|
176
178
|
- spec/core/spec_helper.rb
|
177
179
|
- tasks/rspec.rake
|
@@ -203,5 +205,6 @@ test_files:
|
|
203
205
|
- spec/core/client_spec.rb
|
204
206
|
- spec/core/configuration_spec.rb
|
205
207
|
- spec/core/connect_spec.rb
|
208
|
+
- spec/core/query_results_set_spec.rb
|
206
209
|
- spec/core/query_results_spec.rb
|
207
210
|
- spec/core/spec_helper.rb
|