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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a4816953d57954604bf2efef9a71e993c9e064da
4
- data.tar.gz: 06cd0e61915650193c822b2b56ccb0d8e2ebb877
3
+ metadata.gz: addca70579faf163b99b0b41f76e84f500c3cad4
4
+ data.tar.gz: b945a6eb88f1c95752a9191bbaa3eaac7a0ebf4a
5
5
  SHA512:
6
- metadata.gz: 17c8a7590f2f1338459fe44736a98d7309d6b12329c3925a612fd670bbbf2c4b1bd6fa832c4169ddb5ec91506619b53057dd6a2e62a3d1d94245e00263459f8b
7
- data.tar.gz: 67e0b1571808aaa97b26ac5dfb5207444bac3a65ddbfe8a4cfa103adbc3394ee77f419662fabb0c5e4559496ca6c36ee0a5dc2b68c761c2e3fc96f7d73454ad4
6
+ metadata.gz: 97dab4e79cfbcd88c0679b8c8e482939a578192431017d6bd24cc11f00b7b743488ca325cafaf60e749e5026c0db966c93700a6a26c7e9b65b61a8646a621dd4
7
+ data.tar.gz: 5bef5ced6a2eb9b464ebf89e75e8bb056b64a5bf557e9216bd744ce600fef9ea912751f353b71a303d501f7ac285f2f5a5b523c4807218d271652b6b29fafe59
data/Rakefile CHANGED
@@ -1,3 +1,4 @@
1
1
  require "bundler/gem_tasks"
2
+ task :default => :spec
2
3
 
3
4
  Dir.glob('tasks/**/*.rake').each(&method(:import))
@@ -2,4 +2,5 @@ module OSCRuby; end
2
2
 
3
3
  require 'osc_ruby/client'
4
4
  require 'osc_ruby/connect'
5
- require 'osc_ruby/classes/query_results'
5
+ require 'osc_ruby/classes/query_results'
6
+ require 'osc_ruby/classes/query_results_set'
@@ -13,7 +13,7 @@ module OSCRuby
13
13
 
14
14
  def initialize; end
15
15
 
16
- def query(client,query,return_json = false)
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
- json_response = JSON.parse(response)
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
- item['rows'].each_with_index do |row,row_i|
25
+ results_array = []
24
26
 
25
- obj_hash = {}
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
- final_hash.push(obj_hash)
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
- if json_input['items'].count > 1 && (item['rows'].count-1 <= row_i)
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
- final_hash.push("\n")
42
+ # push the hash into the array
43
+ results_array.push(obj_hash)
36
44
 
37
- end
45
+ end
38
46
 
39
- end
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
@@ -1,3 +1,3 @@
1
1
  module OSCRuby
2
- VERSION = "1.0.3"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -10,13 +10,15 @@ describe OSCRuby::Connect do
10
10
 
11
11
  OSCRuby::Client.new do |config|
12
12
 
13
- config.interface = ENV['REDBOX_TEST']
13
+ config.interface = ENV['OSC_SITE']
14
14
 
15
- config.username = ENV['REDBOX_ADMIN']
15
+ config.username = ENV['OSC_ADMIN']
16
16
 
17
- config.password = ENV['REDBOX_PASSWORD']
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['REDBOX_ADMIN'])
133
+ expect(final_config['username']).to eq(ENV['OSC_ADMIN'])
132
134
 
133
- expect(final_config['password']).to eq(ENV['REDBOX_PASSWORD'])
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['REDBOX_TEST']
11
+ config.interface = ENV['OSC_SITE']
12
12
 
13
- config.username = ENV['REDBOX_ADMIN']
13
+ config.username = ENV['OSC_ADMIN']
14
14
 
15
- config.password = ENV['REDBOX_PASSWORD']
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",true)).to be_an(Array)
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
 
@@ -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['OSC_TEST1_SITE'] }
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.3
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-09 00:00:00.000000000 Z
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