osc_ruby 0.7.1 → 1.0.2

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.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +25 -25
  3. data/.gitignore +15 -15
  4. data/.rspec +1 -1
  5. data/.rubocop.yml +1156 -1156
  6. data/.travis.yml +9 -9
  7. data/Gemfile +3 -3
  8. data/License.txt +21 -0
  9. data/README.md +95 -242
  10. data/Rakefile +2 -2
  11. data/lib/ext/string.rb +18 -18
  12. data/lib/osc_ruby/classes/query_results.rb +40 -60
  13. data/lib/osc_ruby/client.rb +40 -40
  14. data/lib/osc_ruby/configuration.rb +14 -13
  15. data/lib/osc_ruby/connect.rb +218 -209
  16. data/lib/osc_ruby/modules/normalize_module.rb +121 -121
  17. data/lib/osc_ruby/modules/query_module.rb +69 -69
  18. data/lib/osc_ruby/modules/validations_module.rb +168 -168
  19. data/lib/osc_ruby/version.rb +2 -2
  20. data/lib/osc_ruby.rb +4 -10
  21. data/osc_ruby.gemspec +28 -29
  22. data/spec/core/client_spec.rb +96 -96
  23. data/spec/core/configuration_spec.rb +4 -4
  24. data/spec/core/connect_spec.rb +366 -364
  25. data/spec/core/query_results_spec.rb +107 -133
  26. data/spec/core/spec_helper.rb +25 -25
  27. data/tasks/rspec.rake +2 -2
  28. metadata +23 -22
  29. data/LICENSE.txt +0 -22
  30. data/lib/osc_ruby/classes/account.rb +0 -75
  31. data/lib/osc_ruby/classes/answer.rb +0 -117
  32. data/lib/osc_ruby/classes/incident.rb +0 -13
  33. data/lib/osc_ruby/classes/product_category_shared.rb +0 -118
  34. data/lib/osc_ruby/classes/service_category.rb +0 -6
  35. data/lib/osc_ruby/classes/service_class.rb +0 -66
  36. data/lib/osc_ruby/classes/service_product.rb +0 -6
  37. data/lib/osc_ruby/modules/class_factory_module.rb +0 -165
  38. data/lib/osc_ruby/modules/nested_resource_module.rb +0 -10
  39. data/spec/core/account_spec.rb +0 -497
  40. data/spec/core/answer_spec.rb +0 -545
  41. data/spec/core/service_category_spec.rb +0 -445
  42. data/spec/core/service_product_spec.rb +0 -443
@@ -1,210 +1,219 @@
1
- require 'osc_ruby/client'
2
-
3
- require 'net/http'
4
- require 'openssl'
5
- require 'uri'
6
- require 'cgi'
7
-
8
- module OSCRuby
9
-
10
- class Connect
11
- # This class is purely to provide the underlying methods for CRUD functionality using Net::HTTP, URI, and OpenSSL
12
-
13
- def self.get(client,resource_url = nil)
14
-
15
- @final_config = get_check(client,resource_url)
16
-
17
- @uri = @final_config['site_url']
18
-
19
- @username = @final_config['username']
20
- @password = @final_config['password']
21
-
22
- Net::HTTP.start(@uri.host, @uri.port,
23
- :use_ssl => true,
24
- :verify_mode => @final_config['ssl']) do |http|
25
-
26
- request = Net::HTTP::Get.new @uri.request_uri
27
-
28
- request.add_field('Content-Type', 'application/x-www-form-urlencoded')
29
- if @final_config['suppress_rules'] == true
30
- request.add_field 'OSvC-CREST-Suppress-All',true
31
- end
32
-
33
- request.basic_auth @username, @password
34
-
35
- http.request request # Net::HTTPResponse object
36
-
37
- end
38
-
39
- end
40
-
41
- def self.post_or_patch(client,resource_url = nil, json_content = nil,patch_request = false)
42
-
43
- @final_config = post_and_patch_check(client,resource_url, json_content, patch_request)
44
-
45
- @uri = @final_config['site_url']
46
- @username = @final_config['username']
47
- @password = @final_config['password']
48
-
49
- Net::HTTP.start(@uri.host, @uri.port,
50
- :use_ssl => true,
51
- :verify_mode => @final_config['ssl']) do |http|
52
-
53
- request = Net::HTTP::Post.new @uri.request_uri
54
- request.basic_auth @username, @password
55
- request.content_type = "application/json"
56
- if @final_config['patch_request'] == true
57
- request.add_field 'X-HTTP-Method-Override','PATCH'
58
- end
59
- if @final_config['suppress_rules'] == true
60
- request.add_field 'OSvC-CREST-Suppress-All',true
61
- end
62
- request.body = JSON.dump(json_content)
63
-
64
- http.request request # Net::HTTPResponse object
65
-
66
- end
67
-
68
- end
69
-
70
- def self.delete(client,resource_url = nil)
71
-
72
- @final_config = delete_check(client,resource_url)
73
-
74
- @uri = @final_config['site_url']
75
- @username = @final_config['username']
76
- @password = @final_config['password']
77
-
78
- Net::HTTP.start(@uri.host, @uri.port,
79
- :use_ssl => true,
80
- :verify_mode => @final_config['ssl']) do |http|
81
-
82
- request = Net::HTTP::Delete.new @uri.request_uri
83
- request.basic_auth @username, @password
84
-
85
- http.request request # Net::HTTPResponse object
86
-
87
- end
88
-
89
- end
90
-
91
-
92
- ## checking methods
93
-
94
- def self.generate_url_and_config(client,resource_url = nil, patch_request = false)
95
-
96
- check_client_config(client)
97
-
98
- @config = client.config
99
-
100
- @version = @config.version
101
-
102
- @ssl_verification = ssl_check(@config)
103
-
104
- @rule_suppression = rule_suppress_check(@config)
105
-
106
- @url = "https://" + @config.interface + ".custhelp.com/services/rest/connect/#{@version}/#{resource_url}"
107
-
108
- @final_uri = URI(@url)
109
-
110
- @patch_request = patch_request == true ? true : false
111
-
112
- @final_config = {'site_url' => @final_uri,
113
- 'username' => @config.username,
114
- 'password' => @config.password,
115
- 'patch_request' => @patch_request,
116
- 'ssl' => @ssl_verification,
117
- 'suppress_rules' => @rule_suppression
118
- }
119
-
120
- end
121
-
122
- def self.rule_suppress_check(config)
123
-
124
- if config.suppress_rules == true || config.suppress_rules == "Yes"
125
-
126
- true
127
-
128
- else
129
-
130
- false
131
-
132
- end
133
-
134
- end
135
-
136
- def self.ssl_check(config)
137
-
138
- if config.no_ssl_verify == true
139
-
140
- OpenSSL::SSL::VERIFY_NONE
141
-
142
- else
143
-
144
- OpenSSL::SSL::VERIFY_PEER
145
-
146
- end
147
-
148
- end
149
-
150
- def self.check_client_config(client)
151
-
152
- if client.nil?
153
- raise ArgumentError, "Client must have some configuration set; please create an instance of OSCRuby::Client with configuration settings"
154
- else
155
- @config = client.config
156
- end
157
-
158
- if @config.nil?
159
- raise ArgumentError, "Client configuration cannot be nil or blank"
160
- elsif @config.interface.nil?
161
- raise ArgumentError, "The configured client interface cannot be nil or blank"
162
- elsif @config.username.nil?
163
- raise ArgumentError, "The configured client username cannot be nil or blank"
164
- elsif @config.password.nil?
165
- raise ArgumentError, "The configured client password cannot be nil or blank"
166
- end
167
-
168
- end
169
-
170
- def self.get_check(client,resource_url = nil)
171
-
172
- if client.nil?
173
- raise ArgumentError, "Client must have some configuration set; please create an instance of OSCRuby::Client with configuration settings"
174
- elsif !resource_url.nil?
175
- @final_config = generate_url_and_config(client,resource_url)
176
- else
177
- @final_config = generate_url_and_config(client,nil)
178
- end
179
-
180
- end
181
-
182
- def self.post_and_patch_check(client,resource_url = nil, json_content = nil, patch_request = false)
183
-
184
- if client.nil?
185
- raise ArgumentError, "Client must have some configuration set; please create an instance of OSCRuby::Client with configuration settings"
186
- elsif resource_url.nil?
187
- raise ArgumentError, "There is no URL resource provided; please specify a URL resource that you would like to send a POST or PATCH request to"
188
- elsif json_content.nil?
189
- raise ArgumentError, "There is no json content provided; please specify json content that you would like to send a POST or PATCH request with"
190
- elsif patch_request == true
191
- @final_config = generate_url_and_config(client,resource_url,true)
192
- else
193
- @final_config = generate_url_and_config(client,resource_url)
194
- end
195
-
196
- end
197
-
198
- def self.delete_check(client,resource_url = nil)
199
- if client.nil?
200
- raise ArgumentError, "Client must have some configuration set; please create an instance of OSCRuby::Client with configuration settings"
201
- elsif resource_url.nil?
202
- raise ArgumentError, "There is no URL resource provided; please specify a URL resource that you would like to send a POST or PATCH request to"
203
- else
204
- @final_config = generate_url_and_config(client,resource_url)
205
- end
206
- end
207
-
208
- end
209
-
1
+ require 'osc_ruby/client'
2
+
3
+ require 'net/http'
4
+ require 'openssl'
5
+ require 'uri'
6
+ require 'cgi'
7
+
8
+ module OSCRuby
9
+
10
+ class Connect
11
+ # This class is purely to provide the underlying methods for CRUD functionality using Net::HTTP, URI, and OpenSSL
12
+
13
+ def self.get(client,resource_url = nil)
14
+
15
+ @final_config = get_check(client,resource_url)
16
+
17
+ @uri = @final_config['site_url']
18
+
19
+ @username = @final_config['username']
20
+ @password = @final_config['password']
21
+
22
+ Net::HTTP.start(@uri.host, @uri.port,
23
+ :use_ssl => true,
24
+ :verify_mode => @final_config['ssl']) do |http|
25
+
26
+ request = Net::HTTP::Get.new @uri.request_uri
27
+
28
+ request.add_field('Content-Type', 'application/x-www-form-urlencoded')
29
+ if @final_config['suppress_rules'] == true
30
+ request.add_field 'OSvC-CREST-Suppress-All',true
31
+ end
32
+
33
+ request.basic_auth @username, @password
34
+
35
+ http.request request # Net::HTTPResponse object
36
+
37
+ end
38
+
39
+ end
40
+
41
+ def self.post_or_patch(client,resource_url = nil, json_content = nil,patch_request = false)
42
+
43
+ @final_config = post_and_patch_check(client,resource_url, json_content, patch_request)
44
+ @uri = @final_config['site_url']
45
+ @username = @final_config['username']
46
+ @password = @final_config['password']
47
+
48
+ Net::HTTP.start(@uri.host, @uri.port,
49
+ :use_ssl => true,
50
+ :verify_mode => @final_config['ssl']) do |http|
51
+
52
+ request = Net::HTTP::Post.new @uri.request_uri
53
+ request.basic_auth @username, @password
54
+ request.content_type = "application/json"
55
+ if @final_config['patch_request'] == true
56
+ request.add_field 'X-HTTP-Method-Override','PATCH'
57
+ end
58
+ if @final_config['suppress_rules'] == true
59
+ request.add_field 'OSvC-CREST-Suppress-All',true
60
+ end
61
+ request.body = JSON.dump(json_content)
62
+
63
+ http.request request # Net::HTTPResponse object
64
+
65
+ end
66
+
67
+ end
68
+
69
+ def self.delete(client,resource_url = nil)
70
+
71
+ @final_config = delete_check(client,resource_url)
72
+
73
+ @uri = @final_config['site_url']
74
+ @username = @final_config['username']
75
+ @password = @final_config['password']
76
+
77
+ Net::HTTP.start(@uri.host, @uri.port,
78
+ :use_ssl => true,
79
+ :verify_mode => @final_config['ssl']) do |http|
80
+
81
+ request = Net::HTTP::Delete.new @uri.request_uri
82
+ request.basic_auth @username, @password
83
+
84
+ http.request request # Net::HTTPResponse object
85
+
86
+ end
87
+
88
+ end
89
+
90
+
91
+ ## checking methods
92
+
93
+ def self.generate_url_and_config(client,resource_url = nil, patch_request = false)
94
+
95
+ check_client_config(client)
96
+
97
+ @config = client.config
98
+
99
+ @version = @config.version
100
+
101
+ @ssl_verification = ssl_check(@config)
102
+
103
+ @rule_suppression = rule_suppress_check(@config)
104
+
105
+ @cust_or_demo = demo_check(@config)
106
+
107
+ @url = "https://" + @config.interface + ".#{@cust_or_demo}.com/services/rest/connect/#{@version}/#{resource_url}"
108
+
109
+ @final_uri = URI(@url)
110
+
111
+ @patch_request = patch_request == true ? true : false
112
+
113
+ @final_config = {'site_url' => @final_uri,
114
+ 'username' => @config.username,
115
+ 'password' => @config.password,
116
+ 'patch_request' => @patch_request,
117
+ 'ssl' => @ssl_verification,
118
+ 'suppress_rules' => @rule_suppression
119
+ }
120
+
121
+ end
122
+
123
+ def self.demo_check(config)
124
+ if config.demo_site == true
125
+ "rightnowdemo"
126
+ else
127
+ "custhelp"
128
+ end
129
+ end
130
+
131
+ def self.rule_suppress_check(config)
132
+
133
+ if config.suppress_rules == true || config.suppress_rules == "Yes"
134
+
135
+ true
136
+
137
+ else
138
+
139
+ false
140
+
141
+ end
142
+
143
+ end
144
+
145
+ def self.ssl_check(config)
146
+
147
+ if config.no_ssl_verify == true
148
+
149
+ OpenSSL::SSL::VERIFY_NONE
150
+
151
+ else
152
+
153
+ OpenSSL::SSL::VERIFY_PEER
154
+
155
+ end
156
+
157
+ end
158
+
159
+ def self.check_client_config(client)
160
+
161
+ if client.nil?
162
+ raise ArgumentError, "Client must have some configuration set; please create an instance of OSCRuby::Client with configuration settings"
163
+ else
164
+ @config = client.config
165
+ end
166
+
167
+ if @config.nil?
168
+ raise ArgumentError, "Client configuration cannot be nil or blank"
169
+ elsif @config.interface.nil?
170
+ raise ArgumentError, "The configured client interface cannot be nil or blank"
171
+ elsif @config.username.nil?
172
+ raise ArgumentError, "The configured client username cannot be nil or blank"
173
+ elsif @config.password.nil?
174
+ raise ArgumentError, "The configured client password cannot be nil or blank"
175
+ end
176
+
177
+ end
178
+
179
+ def self.get_check(client,resource_url = nil)
180
+
181
+ if client.nil?
182
+ raise ArgumentError, "Client must have some configuration set; please create an instance of OSCRuby::Client with configuration settings"
183
+ elsif !resource_url.nil?
184
+ @final_config = generate_url_and_config(client,resource_url)
185
+ else
186
+ @final_config = generate_url_and_config(client,nil)
187
+ end
188
+
189
+ end
190
+
191
+ def self.post_and_patch_check(client,resource_url = nil, json_content = nil, patch_request = false)
192
+
193
+ if client.nil?
194
+ raise ArgumentError, "Client must have some configuration set; please create an instance of OSCRuby::Client with configuration settings"
195
+ elsif resource_url.nil?
196
+ raise ArgumentError, "There is no URL resource provided; please specify a URL resource that you would like to send a POST or PATCH request to"
197
+ elsif json_content.nil?
198
+ raise ArgumentError, "There is no json content provided; please specify json content that you would like to send a POST or PATCH request with"
199
+ elsif patch_request == true
200
+ @final_config = generate_url_and_config(client,resource_url,true)
201
+ else
202
+ @final_config = generate_url_and_config(client,resource_url)
203
+ end
204
+
205
+ end
206
+
207
+ def self.delete_check(client,resource_url = nil)
208
+ if client.nil?
209
+ raise ArgumentError, "Client must have some configuration set; please create an instance of OSCRuby::Client with configuration settings"
210
+ elsif resource_url.nil?
211
+ raise ArgumentError, "There is no URL resource provided; please specify a URL resource that you would like to send a POST or PATCH request to"
212
+ else
213
+ @final_config = generate_url_and_config(client,resource_url)
214
+ end
215
+ end
216
+
217
+ end
218
+
210
219
  end
@@ -1,122 +1,122 @@
1
- require 'json'
2
-
3
- module OSCRuby
4
-
5
- module NormalizeModule
6
-
7
- class << self
8
-
9
- def normalize(input,resource)
10
-
11
- if input.code.to_i == 404
12
-
13
- input.body
14
-
15
- else
16
-
17
- json_input = JSON.parse(input.body)
18
-
19
- final_hash = []
20
-
21
- json_input['items'].each do |item|
22
-
23
- item['rows'].each_with_index do |row,row_i|
24
-
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
30
-
31
- final_hash.push(obj_hash)
32
-
33
- if json_input['items'].count > 1 && (item['rows'].count-1 <= row_i)
34
-
35
- final_hash.push("\n")
36
-
37
- end
38
-
39
- end
40
-
41
- end
42
-
43
- final_hash.to_json
44
-
45
- end
46
-
47
- end
48
-
49
- def nested_normalize(input,resource)
50
-
51
- if input.code.to_i == 404
52
-
53
- input.body
54
-
55
- else
56
-
57
- json_input = JSON.parse(input.body)
58
-
59
- final_hash = []
60
-
61
- json_input['items'].each do |item|
62
-
63
- item_array = []
64
-
65
- item['rows'].each_with_index do |row,row_i|
66
-
67
- obj_hash = {}
68
-
69
- item['columnNames'].each_with_index do |column,i|
70
- obj_hash[column] = if !row[i].nil? && row[i].is_i? == true then row[i].to_i else row[i] end
71
- end
72
-
73
- item_array.push(obj_hash)
74
-
75
- end
76
-
77
- final_hash.push(item_array)
78
-
79
- end
80
-
81
- puts JSON.pretty_generate(final_hash)
82
-
83
- final_hash.to_json
84
-
85
- end
86
-
87
- end
88
-
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
- end
121
- end
1
+ require 'json'
2
+
3
+ module OSCRuby
4
+
5
+ module NormalizeModule
6
+
7
+ class << self
8
+
9
+ def normalize(input,resource)
10
+
11
+ if input.code.to_i == 404
12
+
13
+ input.body
14
+
15
+ else
16
+
17
+ json_input = JSON.parse(input.body)
18
+
19
+ final_hash = []
20
+
21
+ json_input['items'].each do |item|
22
+
23
+ item['rows'].each_with_index do |row,row_i|
24
+
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
30
+
31
+ final_hash.push(obj_hash)
32
+
33
+ if json_input['items'].count > 1 && (item['rows'].count-1 <= row_i)
34
+
35
+ final_hash.push("\n")
36
+
37
+ end
38
+
39
+ end
40
+
41
+ end
42
+
43
+ final_hash.to_json
44
+
45
+ end
46
+
47
+ end
48
+
49
+ def nested_normalize(input,resource)
50
+
51
+ if input.code.to_i == 404
52
+
53
+ input.body
54
+
55
+ else
56
+
57
+ json_input = JSON.parse(input.body)
58
+
59
+ final_hash = []
60
+
61
+ json_input['items'].each do |item|
62
+
63
+ item_array = []
64
+
65
+ item['rows'].each_with_index do |row,row_i|
66
+
67
+ obj_hash = {}
68
+
69
+ item['columnNames'].each_with_index do |column,i|
70
+ obj_hash[column] = if !row[i].nil? && row[i].is_i? == true then row[i].to_i else row[i] end
71
+ end
72
+
73
+ item_array.push(obj_hash)
74
+
75
+ end
76
+
77
+ final_hash.push(item_array)
78
+
79
+ end
80
+
81
+ puts JSON.pretty_generate(final_hash)
82
+
83
+ final_hash.to_json
84
+
85
+ end
86
+
87
+ end
88
+
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
+ end
121
+ end
122
122
  end