osc_ruby 0.3.0 → 0.4.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: d6f94c0e39eee367ce2ed2811ae2591a3ebe91bf
4
- data.tar.gz: 3d3d0246225077d1a2089844a407d3f31dae51df
3
+ metadata.gz: f3699de5d5f0bfd43b0fa37ee16e2bbe47fed6ff
4
+ data.tar.gz: 31b35ce287cc0d343afb32e399b052fa9becff64
5
5
  SHA512:
6
- metadata.gz: 8a7e3f17d1c8674716e8a3f8a7962d4c9d894a77da731b1b2d4765ac0682bb4ba56555e853be0fa04fcd885cdaa5754acad86b771e380bb1b4f2faadebe3d161
7
- data.tar.gz: ba527034f663c100a58c42d0b97c79479ef3a9f5984c35e03ae87a3aafc574e0cb50f2f76e1789537bb23b943abf2a69b3769a9bb825a1d648b1d080709f94d0
6
+ metadata.gz: 3027967797e07efaecc469545382d6b521170d51ce5c5eb4bb43f1c8a046d0d3f42c32ee241b59485f36d53015eae58fa40ece9d62124d3d971c09b9416ea475
7
+ data.tar.gz: 760a5ce18c2dc9bcebe61b5fa31b8d4145228704d1bab14628dcea3e0bfb7abd89d805ca2160a49fdc67c94d436506809323c347de556ed1d0104993d5f21bcb
@@ -1,6 +1,7 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - 2.2.0
4
+ - jruby
4
5
  addons:
5
6
  code_climate:
6
7
  repo_token:
data/README.md CHANGED
@@ -12,7 +12,7 @@ This gem was tested against Oracle Service Cloud November 2016 using Ruby versio
12
12
 
13
13
  The create, update, and destroy methods should work on any version of Oracle Service Cloud since version May 2015; however, there maybe some issues with querying items on any version before November 2016. This is because I am using the ROQL queries to generate values for Common Objects
14
14
 
15
- Currently supporting the following objects:
15
+ Currently supporting the following objects from the REST API:
16
16
 
17
17
  ServiceProduct
18
18
 
@@ -20,6 +20,8 @@ Currently supporting the following objects:
20
20
 
21
21
  Answer
22
22
 
23
+ QueryResults (does not support CRUD)
24
+
23
25
  At this time, subclasses such as ServiceProduct.CategoryLinks are not currently supported.
24
26
 
25
27
  I am trying to build a few more classes and have a pretty solid testing suite and codebase before implementing this functionality.
@@ -2,4 +2,18 @@ class String
2
2
  def is_i?
3
3
  /\A[-+]?\d+\z/ === self
4
4
  end
5
+
6
+ def camel_case_lower
7
+ @class_to_array = self.split('')
8
+ @class_name_length = @class_to_array.length - 1
9
+ @output = @class_to_array.each_with_index do |letter,i|
10
+ if i ==0
11
+ letter.downcase!
12
+ elsif i == @class_name_length
13
+ letter.gsub!(/y/,'ie')
14
+ end
15
+ end.join
16
+
17
+ @output + 's'
18
+ end
5
19
  end
@@ -2,6 +2,9 @@ module OSCRuby; end
2
2
 
3
3
  require 'osc_ruby/client'
4
4
  require 'osc_ruby/connect'
5
+ require 'osc_ruby/service_class'
6
+ require 'osc_ruby/product_category_shared'
5
7
  require 'osc_ruby/service_product'
6
8
  require 'osc_ruby/service_category'
7
- require 'osc_ruby/answer'
9
+ require 'osc_ruby/answer'
10
+ require 'osc_ruby/query_results'
@@ -1,20 +1,9 @@
1
- require 'osc_ruby/client'
2
- require 'osc_ruby/query_module'
3
- require 'osc_ruby/validations_module'
4
- require 'osc_ruby/class_factory_module'
5
- require 'json'
6
- require 'uri'
7
-
8
1
  module OSCRuby
9
2
 
10
- class Answer
11
-
12
- include QueryModule
13
- include ValidationsModule
14
- include ClassFactoryModule
3
+ class Answer < ServiceClass
15
4
 
16
5
  attr_accessor :answerType, :language, :summary, :id, :lookupName, :createdTime, :updatedTime, :accessLevels, :name, :adminLastAccessTime, :expiresDate, :guidedAssistance, :keywords, :lastAccessTime, :lastNotificationTime, :nextNotificationTime, :originalReferenceNumber, :positionInList,
17
- :publishOnDate, :question, :solution, :updatedByAccount, :uRL
6
+ :publishOnDate, :question, :solution, :updatedByAccount, :uRL, :categories
18
7
 
19
8
  def initialize(attributes = nil)
20
9
 
@@ -24,6 +13,7 @@ module OSCRuby
24
13
  @summary = "Answer summary text"
25
14
  @language = {}
26
15
  @question = nil
16
+ @categories = []
27
17
 
28
18
  else
29
19
 
@@ -55,53 +45,6 @@ module OSCRuby
55
45
 
56
46
  end
57
47
 
58
- def create(client,return_json = false)
59
-
60
- ClassFactoryModule.create(client,self,"/answers",return_json)
61
-
62
- end
63
-
64
-
65
- def self.find(client,id = nil,return_json = false)
66
-
67
- ClassFactoryModule.find(client,id,'answers',return_json,OSCRuby::Answer)
68
-
69
- end
70
-
71
-
72
- def self.all(client, return_json = false)
73
-
74
- ClassFactoryModule.all(client,'answers',return_json,OSCRuby::Answer)
75
-
76
- end
77
-
78
- def self.where(client, query = '', return_json = false)
79
-
80
- ClassFactoryModule.where(client,query,'answers',return_json,OSCRuby::Answer)
81
-
82
- end
83
-
84
- def update(client, return_json = false)
85
-
86
- ClassFactoryModule::update(client,self,"answers",return_json)
87
-
88
- end
89
-
90
- def destroy(client, return_json = false)
91
-
92
- ClassFactoryModule.destroy(client,self,'answers',return_json)
93
-
94
- end
95
-
96
-
97
-
98
-
99
-
100
-
101
-
102
-
103
-
104
-
105
48
 
106
49
  # Convenience Methods for making the CRUD operations nicer to use
107
50
 
@@ -82,7 +82,7 @@ module OSCRuby
82
82
 
83
83
  ValidationsModule::check_client(client)
84
84
 
85
- ValidationsModule::check_query(query)
85
+ ValidationsModule::check_query(query,'where')
86
86
 
87
87
  @query = URI.escape("queryResults/?query=select * from #{object_in_query} where #{query}")
88
88
 
@@ -0,0 +1,118 @@
1
+ module OSCRuby
2
+
3
+ class ProductCategoryShared < ServiceClass
4
+
5
+ attr_accessor :names,:parent,:displayOrder,:adminVisibleInterfaces,:endUserVisibleInterfaces,:id,:lookupName,:createdTime,:updatedTime,:name
6
+
7
+ def initialize(attributes = nil)
8
+
9
+ @names = []
10
+ @adminVisibleInterfaces = []
11
+ @endUserVisibleInterfaces = []
12
+
13
+ if attributes.nil?
14
+
15
+ @parent = {}
16
+ @displayOrder = 1
17
+
18
+ else
19
+
20
+ @id = attributes["id"]
21
+ @lookupName = attributes["lookupName"]
22
+ @createdTime = attributes["createdTime"]
23
+ @updatedTime = attributes["updatedTime"]
24
+ @displayOrder = attributes["displayOrder"]
25
+ @name = attributes["name"]
26
+ @parent = attributes["parent"]
27
+
28
+ end
29
+
30
+ end
31
+
32
+ # Convenience Methods for making the CRUD operations nicer to use
33
+
34
+ def set_attributes(response_body)
35
+
36
+ self.id = response_body["id"]
37
+
38
+ self.name = response_body["lookupName"]
39
+
40
+ self.lookupName = response_body["lookupName"]
41
+
42
+ self.displayOrder = response_body["displayOrder"]
43
+
44
+ if !response_body["parent"].nil?
45
+
46
+ self.parent = response_body["parent"]["links"][0]["href"].split('/').pop.to_i
47
+
48
+ else
49
+
50
+ self.parent = nil
51
+
52
+ end
53
+
54
+ end
55
+
56
+ def update_attributes(updated_product)
57
+
58
+ self.lookupName = updated_product.lookupName
59
+
60
+ self.createdTime = updated_product.createdTime
61
+
62
+ self.updatedTime = updated_product.updatedTime
63
+
64
+ self.name = updated_product.name
65
+
66
+ self.parent = updated_product.parent
67
+
68
+ end
69
+
70
+ def self.check_self(obj,is_update = false)
71
+
72
+ class_name = self.to_s.split('::')[1]
73
+
74
+ obj_attrs = ValidationsModule::extract_attributes(obj)
75
+
76
+ obj_attrs = ValidationsModule::check_interfaces(obj_attrs)
77
+
78
+ if is_update == true
79
+
80
+ obj_attrs = remove_unused_new_attrs(obj_attrs)
81
+
82
+ else
83
+
84
+ obj_attrs = ValidationsModule::check_for_names(obj_attrs,class_name)
85
+
86
+ obj_attrs = ValidationsModule::check_for_parents(obj_attrs)
87
+
88
+ end
89
+
90
+ obj_attrs
91
+
92
+ end
93
+
94
+ def self.remove_unused_new_attrs(obj_attrs)
95
+
96
+ obj_attrs[0].delete('id')
97
+
98
+ obj_attrs[0].delete('lookupName')
99
+
100
+ obj_attrs[0].delete('createdTime')
101
+
102
+ obj_attrs[0].delete('updatedTime')
103
+
104
+ obj_attrs[0].delete('name')
105
+
106
+ if !obj_attrs[0]['parent'].nil?
107
+
108
+ obj_attrs[0].delete('parent')
109
+
110
+ end
111
+
112
+ obj_attrs
113
+
114
+ end
115
+
116
+ end
117
+
118
+ end
@@ -0,0 +1,35 @@
1
+ require 'osc_ruby/connect'
2
+ require 'osc_ruby/validations_module'
3
+ require 'json'
4
+
5
+ module OSCRuby
6
+
7
+ class QueryResults
8
+
9
+ include QueryModule
10
+ include ValidationsModule
11
+
12
+ def initialize; end
13
+
14
+ def select(client,query)
15
+
16
+ ValidationsModule::check_client(client)
17
+
18
+ ValidationsModule::check_query(query,"select")
19
+
20
+ @query = URI.escape("queryResults/?query=#{query}")
21
+
22
+ response = QueryModule::find(client,@query)
23
+
24
+ json_response = JSON.parse(response)
25
+
26
+ puts "Results for '#{query}'"
27
+ puts
28
+ puts json_response
29
+ puts
30
+
31
+ end
32
+
33
+ end
34
+
35
+ end
@@ -1,214 +1,6 @@
1
- require 'osc_ruby/client'
2
- require 'osc_ruby/query_module'
3
- require 'osc_ruby/validations_module'
4
- require 'osc_ruby/class_factory_module'
5
- require 'json'
6
- require 'uri'
7
-
8
1
  module OSCRuby
9
-
10
- class ServiceCategory
11
-
12
- include QueryModule
13
- include ValidationsModule
14
- include ClassFactoryModule
15
-
16
- attr_accessor :names,:parent,:displayOrder,:adminVisibleInterfaces,:endUserVisibleInterfaces,:id,:lookupName,:createdTime,:updatedTime,:name
17
-
18
- def initialize(attributes = nil)
19
-
20
- @names = []
21
- @adminVisibleInterfaces = []
22
- @endUserVisibleInterfaces = []
23
-
24
- if attributes.nil?
25
-
26
- @parent = {}
27
- @displayOrder = 1
28
-
29
- else
30
-
31
- @id = attributes["id"]
32
- @lookupName = attributes["lookupName"]
33
- @createdTime = attributes["createdTime"]
34
- @updatedTime = attributes["updatedTime"]
35
- @displayOrder = attributes["displayOrder"]
36
- @name = attributes["name"]
37
- @parent = attributes["parent"]
38
-
39
- end
40
-
41
- end
42
-
43
-
44
- def create(client,return_json = false)
45
-
46
- ClassFactoryModule.create(client,self,"/serviceCategories",return_json)
47
-
48
- end
49
-
50
-
51
- def self.find(client,id = nil,return_json = false)
52
-
53
- ClassFactoryModule.find(client,id,'serviceCategories',return_json,OSCRuby::ServiceCategory)
54
-
55
- end
56
-
57
-
58
- def self.all(client, return_json = false)
59
-
60
- ClassFactoryModule.all(client,'serviceCategories',return_json,OSCRuby::ServiceCategory)
61
-
62
- end
63
-
64
-
65
- def self.where(client, query = '', return_json = false)
66
-
67
- ClassFactoryModule.where(client,query,'serviceCategories',return_json,OSCRuby::ServiceCategory)
68
-
69
- end
70
-
71
-
72
- def update(client, return_json = false)
73
-
74
- ClassFactoryModule::update(client,self,"serviceCategories",return_json)
75
-
76
- end
77
-
78
-
79
- def destroy(client, return_json = false)
80
-
81
- ClassFactoryModule.destroy(client,self,'serviceCategories',return_json)
82
-
83
- end
84
-
85
-
86
-
87
-
88
- # Convenience Methods for making the CRUD operations nicer to use
89
-
90
- def set_attributes(response_body)
91
-
92
- self.id = response_body["id"]
93
-
94
- self.name = response_body["lookupName"]
95
-
96
- self.lookupName = response_body["lookupName"]
97
-
98
- self.displayOrder = response_body["displayOrder"]
99
-
100
- if !response_body["parent"].nil?
101
-
102
- self.parent = response_body["parent"]["links"][0]["href"].split('/').pop.to_i
103
-
104
- else
105
-
106
- self.parent = nil
107
-
108
- end
109
-
110
- end
111
-
112
- def update_attributes(updated_category)
113
-
114
- self.lookupName = updated_category.lookupName
115
-
116
- self.createdTime = updated_category.createdTime
117
-
118
- self.updatedTime = updated_category.updatedTime
119
-
120
- self.name = updated_category.name
121
-
122
- self.parent = updated_category.parent
123
-
124
- end
125
-
126
- def self.check_self(obj,is_update = false)
127
-
128
- obj_attrs = ValidationsModule::extract_attributes(obj)
129
-
130
- obj_attrs = check_interfaces(obj_attrs)
131
-
132
- if is_update == true
133
-
134
- obj_attrs = remove_unused_new_attrs(obj_attrs)
135
-
136
- else
137
-
138
- obj_attrs = check_for_names(obj_attrs)
139
-
140
- obj_attrs = check_for_parents(obj_attrs)
141
-
142
- end
143
-
144
- obj_attrs
145
-
146
- end
147
-
148
- def self.check_for_names(obj_attrs)
149
-
150
- if obj_attrs[0]['names'].count == 0 || obj_attrs[0]['names'][0]['labelText'].nil? || obj_attrs[0]['names'][0]['language'].nil?
151
-
152
- raise ArgumentError, 'ServiceCategory should at least have one name set (new_service_category.names[0] = {"labelText" => "QTH45-test", "language" => {"id" => 1}} )'
153
-
154
- end
155
-
156
- obj_attrs
157
-
158
- end
159
-
160
- def self.check_for_parents(obj_attrs)
161
-
162
- if !obj_attrs[0]['parent'].nil? && obj_attrs[0]['parent'].is_a?(Hash) && !obj_attrs[0]['parent'].key?('id') && !obj_attrs[0]['parent'].key?('lookupName')
163
-
164
- obj_attrs[0].delete('parent')
165
-
166
- end
167
-
168
- obj_attrs
169
-
170
- end
171
-
172
- def self.remove_unused_new_attrs(obj_attrs)
173
-
174
- obj_attrs[0].delete('id')
175
-
176
- obj_attrs[0].delete('lookupName')
177
-
178
- obj_attrs[0].delete('createdTime')
179
-
180
- obj_attrs[0].delete('updatedTime')
181
-
182
- obj_attrs[0].delete('name')
183
-
184
- if !obj_attrs[0]['parent'].nil?
185
-
186
- obj_attrs[0].delete('parent')
187
-
188
- end
189
-
190
- obj_attrs
191
-
192
- end
193
-
194
- def self.check_interfaces(empty_arr)
195
-
196
- if empty_arr[0]['adminVisibleInterfaces'].empty?
197
-
198
- empty_arr[0].delete('adminVisibleInterfaces')
199
-
200
- end
201
-
202
- if empty_arr[0]['endUserVisibleInterfaces'].empty?
203
-
204
- empty_arr[0].delete('endUserVisibleInterfaces')
205
-
206
- end
207
-
208
- empty_arr
209
-
210
- end
211
2
 
3
+ class ServiceCategory < ProductCategoryShared
212
4
  end
213
-
5
+
214
6
  end
@@ -0,0 +1,66 @@
1
+ require 'osc_ruby/client'
2
+ require 'osc_ruby/query_module'
3
+ require 'osc_ruby/validations_module'
4
+ require 'osc_ruby/class_factory_module'
5
+ require 'json'
6
+ require 'uri'
7
+ require_relative '../ext/string'
8
+
9
+ module OSCRuby
10
+
11
+ class ServiceClass
12
+
13
+ include QueryModule
14
+ include ValidationsModule
15
+ include ClassFactoryModule
16
+
17
+ def self.url
18
+
19
+ self.to_s.split('::')[1].camel_case_lower
20
+
21
+ end
22
+
23
+ def create(client,return_json = false)
24
+
25
+ ClassFactoryModule.create(client,self,self.class.url,return_json)
26
+
27
+ end
28
+
29
+
30
+ def self.find(client,id = nil,return_json = false)
31
+
32
+ ClassFactoryModule.find(client,id,url,return_json,self)
33
+
34
+ end
35
+
36
+
37
+ def self.all(client, return_json = false)
38
+
39
+ ClassFactoryModule.all(client,url,return_json,self)
40
+
41
+ end
42
+
43
+
44
+ def self.where(client, query = '', return_json = false)
45
+
46
+ ClassFactoryModule.where(client,query,url,return_json,self)
47
+
48
+ end
49
+
50
+
51
+ def update(client, return_json = false)
52
+
53
+ ClassFactoryModule::update(client,self,self.class.url,return_json)
54
+
55
+ end
56
+
57
+
58
+ def destroy(client, return_json = false)
59
+
60
+ ClassFactoryModule.destroy(client,self,self.class.url,return_json)
61
+
62
+ end
63
+
64
+ end
65
+
66
+ end
@@ -1,214 +1,6 @@
1
- require 'osc_ruby/client'
2
- require 'osc_ruby/query_module'
3
- require 'osc_ruby/validations_module'
4
- require 'osc_ruby/class_factory_module'
5
- require 'json'
6
- require 'uri'
7
-
8
1
  module OSCRuby
9
-
10
- class ServiceProduct
11
-
12
- include QueryModule
13
- include ValidationsModule
14
- include ClassFactoryModule
15
-
16
- attr_accessor :names,:parent,:displayOrder,:adminVisibleInterfaces,:endUserVisibleInterfaces,:id,:lookupName,:createdTime,:updatedTime,:name
17
-
18
- def initialize(attributes = nil)
19
-
20
- @names = []
21
- @adminVisibleInterfaces = []
22
- @endUserVisibleInterfaces = []
23
-
24
- if attributes.nil?
25
-
26
- @parent = {}
27
- @displayOrder = 1
28
-
29
- else
30
-
31
- @id = attributes["id"]
32
- @lookupName = attributes["lookupName"]
33
- @createdTime = attributes["createdTime"]
34
- @updatedTime = attributes["updatedTime"]
35
- @displayOrder = attributes["displayOrder"]
36
- @name = attributes["name"]
37
- @parent = attributes["parent"]
38
-
39
- end
40
-
41
- end
42
-
43
-
44
- def create(client,return_json = false)
45
-
46
- ClassFactoryModule.create(client,self,"/serviceProducts",return_json)
47
-
48
- end
49
-
50
-
51
- def self.find(client,id = nil,return_json = false)
52
-
53
- ClassFactoryModule.find(client,id,'serviceproducts',return_json,OSCRuby::ServiceProduct)
54
-
55
- end
56
-
57
-
58
- def self.all(client, return_json = false)
59
-
60
- ClassFactoryModule.all(client,'serviceproducts',return_json,OSCRuby::ServiceProduct)
61
-
62
- end
63
-
64
-
65
- def self.where(client, query = '', return_json = false)
66
-
67
- ClassFactoryModule.where(client,query,'serviceproducts',return_json,OSCRuby::ServiceProduct)
68
-
69
- end
70
-
71
-
72
- def update(client, return_json = false)
73
-
74
- ClassFactoryModule::update(client,self,"serviceProducts",return_json)
75
-
76
- end
77
-
78
-
79
- def destroy(client, return_json = false)
80
-
81
- ClassFactoryModule.destroy(client,self,'serviceProducts',return_json)
82
-
83
- end
84
-
85
-
86
-
87
-
88
- # Convenience Methods for making the CRUD operations nicer to use
89
-
90
- def set_attributes(response_body)
91
-
92
- self.id = response_body["id"]
93
-
94
- self.name = response_body["lookupName"]
95
-
96
- self.lookupName = response_body["lookupName"]
97
-
98
- self.displayOrder = response_body["displayOrder"]
99
-
100
- if !response_body["parent"].nil?
101
-
102
- self.parent = response_body["parent"]["links"][0]["href"].split('/').pop.to_i
103
-
104
- else
105
-
106
- self.parent = nil
107
-
108
- end
109
-
110
- end
111
-
112
- def update_attributes(updated_product)
113
-
114
- self.lookupName = updated_product.lookupName
115
-
116
- self.createdTime = updated_product.createdTime
117
-
118
- self.updatedTime = updated_product.updatedTime
119
-
120
- self.name = updated_product.name
121
-
122
- self.parent = updated_product.parent
123
-
124
- end
125
-
126
- def self.check_self(obj,is_update = false)
127
-
128
- obj_attrs = ValidationsModule::extract_attributes(obj)
129
-
130
- obj_attrs = check_interfaces(obj_attrs)
131
-
132
- if is_update == true
133
-
134
- obj_attrs = remove_unused_new_attrs(obj_attrs)
135
-
136
- else
137
-
138
- obj_attrs = check_for_names(obj_attrs)
139
-
140
- obj_attrs = check_for_parents(obj_attrs)
141
-
142
- end
143
-
144
- obj_attrs
145
-
146
- end
147
-
148
- def self.check_for_names(obj_attrs)
149
-
150
- if obj_attrs[0]['names'].count == 0 || obj_attrs[0]['names'][0]['labelText'].nil? || obj_attrs[0]['names'][0]['language'].nil?
151
-
152
- raise ArgumentError, 'ServiceProduct should at least have one name set (new_service_product.names[0] = {"labelText" => "QTH45-test", "language" => {"id" => 1}} )'
153
-
154
- end
155
-
156
- obj_attrs
157
-
158
- end
159
-
160
- def self.check_for_parents(obj_attrs)
161
-
162
- if !obj_attrs[0]['parent'].nil? && obj_attrs[0]['parent'].is_a?(Hash) && !obj_attrs[0]['parent'].key?('id') && !obj_attrs[0]['parent'].key?('lookupName')
163
-
164
- obj_attrs[0].delete('parent')
165
-
166
- end
167
-
168
- obj_attrs
169
-
170
- end
171
-
172
- def self.remove_unused_new_attrs(obj_attrs)
173
-
174
- obj_attrs[0].delete('id')
175
-
176
- obj_attrs[0].delete('lookupName')
177
-
178
- obj_attrs[0].delete('createdTime')
179
-
180
- obj_attrs[0].delete('updatedTime')
181
-
182
- obj_attrs[0].delete('name')
183
-
184
- if !obj_attrs[0]['parent'].nil?
185
-
186
- obj_attrs[0].delete('parent')
187
-
188
- end
189
-
190
- obj_attrs
191
-
192
- end
193
-
194
- def self.check_interfaces(empty_arr)
195
-
196
- if empty_arr[0]['adminVisibleInterfaces'].empty?
197
-
198
- empty_arr[0].delete('adminVisibleInterfaces')
199
-
200
- end
201
-
202
- if empty_arr[0]['endUserVisibleInterfaces'].empty?
203
-
204
- empty_arr[0].delete('endUserVisibleInterfaces')
205
-
206
- end
207
-
208
- empty_arr
209
-
210
- end
211
2
 
3
+ class ServiceProduct < ProductCategoryShared
212
4
  end
213
5
 
214
6
  end
@@ -61,11 +61,21 @@ module OSCRuby
61
61
 
62
62
  end
63
63
 
64
- def check_query(query)
64
+ def check_query(query,method_name = "where")
65
65
 
66
66
  if query.empty?
67
67
 
68
- raise ArgumentError, 'A query must be specified when using the "where" method'
68
+ raise ArgumentError, "A query must be specified when using the '#{method_name}' method"
69
+
70
+ end
71
+
72
+ end
73
+
74
+ def check_attributes_request(attributes_request,class_name)
75
+
76
+ if attributes_request.empty?
77
+
78
+ raise ArgumentError, "The attributes you are requesting for the #{class_name} object must be specified when using the 'select' method"
69
79
 
70
80
  end
71
81
 
@@ -87,6 +97,48 @@ module OSCRuby
87
97
 
88
98
  end
89
99
 
100
+ def check_for_names(obj_attrs,class_name)
101
+
102
+ if obj_attrs[0]['names'].count == 0 || obj_attrs[0]['names'][0]['labelText'].nil? || obj_attrs[0]['names'][0]['language'].nil?
103
+
104
+ raise ArgumentError, "#{class_name} should at least have one name set"
105
+
106
+ end
107
+
108
+ obj_attrs
109
+
110
+ end
111
+
112
+ def check_for_parents(obj_attrs)
113
+
114
+ if !obj_attrs[0]['parent'].nil? && obj_attrs[0]['parent'].is_a?(Hash) && !obj_attrs[0]['parent'].key?('id') && !obj_attrs[0]['parent'].key?('lookupName')
115
+
116
+ obj_attrs[0].delete('parent')
117
+
118
+ end
119
+
120
+ obj_attrs
121
+
122
+ end
123
+
124
+ def check_interfaces(empty_arr)
125
+
126
+ if empty_arr[0]['adminVisibleInterfaces'].empty?
127
+
128
+ empty_arr[0].delete('adminVisibleInterfaces')
129
+
130
+ end
131
+
132
+ if empty_arr[0]['endUserVisibleInterfaces'].empty?
133
+
134
+ empty_arr[0].delete('endUserVisibleInterfaces')
135
+
136
+ end
137
+
138
+ empty_arr
139
+
140
+ end
141
+
90
142
  end
91
143
 
92
144
  end
@@ -1,3 +1,3 @@
1
1
  module OSCRuby
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -182,6 +182,25 @@ describe OSCRuby::Answer do
182
182
 
183
183
  end
184
184
 
185
+ it 'should expect the categories to be an array' do
186
+
187
+ expect(new_answer.categories).to be_an(Array)
188
+
189
+ end
190
+
191
+ it 'should expect that a hash with an id key for categories should create an answer without issue', :vcr do
192
+
193
+ new_answer.language['id'] = 1
194
+ new_answer.answerType['lookupName'] = "HTML"
195
+
196
+ new_answer.categories[0] = {'id' => 6}
197
+
198
+ new_answer.create(client)
199
+
200
+ expect(new_answer).to be_a(OSCRuby::Answer)
201
+
202
+ end
203
+
185
204
  it 'should return an instance of an OSCRuby::Answer if the json_response param is set to false (which it is by default)', :vcr do
186
205
 
187
206
  new_answer.language['id'] = 1
@@ -337,7 +356,7 @@ describe OSCRuby::Answer do
337
356
 
338
357
  it 'should raise an error if there is no query' do
339
358
 
340
- expect{OSCRuby::Answer.where(client)}.to raise_error('A query must be specified when using the "where" method')
359
+ expect{OSCRuby::Answer.where(client)}.to raise_error("A query must be specified when using the 'where' method")
341
360
 
342
361
  end
343
362
 
@@ -0,0 +1,54 @@
1
+ require 'core/spec_helper'
2
+ require 'json'
3
+ require 'uri'
4
+
5
+ describe OSCRuby::QueryResults do
6
+
7
+ let(:client) {
8
+
9
+ OSCRuby::Client.new do |config|
10
+
11
+ config.interface = ENV['OSC_TEST_SITE']
12
+
13
+ config.username = ENV['OSC_ADMIN']
14
+
15
+ config.password = ENV['OSC_PASSWORD']
16
+
17
+ end
18
+ }
19
+
20
+ let(:query_results){
21
+ OSCRuby::QueryResults.new
22
+ }
23
+
24
+ context "#select" do
25
+
26
+ it 'should expect client is an instance of OSCRuby::Client class and raise an error if does not' do
27
+
28
+ expect(client).to be_an(OSCRuby::Client)
29
+
30
+ client = nil
31
+
32
+ expect{query_results.select(client,'describe')}.to raise_error('Client must have some configuration set; please create an instance of OSCRuby::Client with configuration settings')
33
+
34
+ end
35
+
36
+ it 'should expect a query' do
37
+
38
+ expect(client).to be_an(OSCRuby::Client)
39
+
40
+ expect{query_results.select(client,"")}.to raise_error("A query must be specified when using the 'select' method")
41
+
42
+ end
43
+
44
+ it 'should put results in array of hashes',:vcr do
45
+
46
+ expect(query_results.select(client,"describe")).to eq(nil)
47
+
48
+ expect(query_results.select(client,"describe answers")).to eq(nil)
49
+
50
+ end
51
+
52
+ end
53
+
54
+ end
@@ -121,7 +121,7 @@ describe OSCRuby::ServiceCategory do
121
121
 
122
122
  it 'should check the object and make sure that it at least has a name set' do
123
123
 
124
- expect{new_service_category.create(client)}.to raise_error('ServiceCategory should at least have one name set (new_service_category.names[0] = {"labelText" => "QTH45-test", "language" => {"id" => 1}} )')
124
+ expect{new_service_category.create(client)}.to raise_error('ServiceCategory should at least have one name set')
125
125
 
126
126
  end
127
127
 
@@ -129,7 +129,7 @@ describe OSCRuby::ServiceCategory do
129
129
 
130
130
  new_service_category.names[0] = "new category name"
131
131
 
132
- expect{new_service_category.create(client)}.to raise_error('ServiceCategory should at least have one name set (new_service_category.names[0] = {"labelText" => "QTH45-test", "language" => {"id" => 1}} )')
132
+ expect{new_service_category.create(client)}.to raise_error('ServiceCategory should at least have one name set')
133
133
 
134
134
  end
135
135
 
@@ -137,7 +137,7 @@ describe OSCRuby::ServiceCategory do
137
137
 
138
138
  new_service_category.names[0] = {"labelText" => "New Category"}
139
139
 
140
- expect{new_service_category.create(client)}.to raise_error('ServiceCategory should at least have one name set (new_service_category.names[0] = {"labelText" => "QTH45-test", "language" => {"id" => 1}} )')
140
+ expect{new_service_category.create(client)}.to raise_error('ServiceCategory should at least have one name set')
141
141
 
142
142
  end
143
143
 
@@ -287,7 +287,7 @@ describe OSCRuby::ServiceCategory do
287
287
 
288
288
  it 'should raise an error if there is no query' do
289
289
 
290
- expect{OSCRuby::ServiceCategory.where(client)}.to raise_error('A query must be specified when using the "where" method')
290
+ expect{OSCRuby::ServiceCategory.where(client)}.to raise_error("A query must be specified when using the 'where' method")
291
291
 
292
292
  end
293
293
 
@@ -121,7 +121,7 @@ describe OSCRuby::ServiceProduct do
121
121
 
122
122
  it 'should check the object and make sure that it at least has a name set' do
123
123
 
124
- expect{new_service_product.create(client)}.to raise_error('ServiceProduct should at least have one name set (new_service_product.names[0] = {"labelText" => "QTH45-test", "language" => {"id" => 1}} )')
124
+ expect{new_service_product.create(client)}.to raise_error('ServiceProduct should at least have one name set')
125
125
 
126
126
  end
127
127
 
@@ -129,7 +129,7 @@ describe OSCRuby::ServiceProduct do
129
129
 
130
130
  new_service_product.names[0] = "new product name"
131
131
 
132
- expect{new_service_product.create(client)}.to raise_error('ServiceProduct should at least have one name set (new_service_product.names[0] = {"labelText" => "QTH45-test", "language" => {"id" => 1}} )')
132
+ expect{new_service_product.create(client)}.to raise_error('ServiceProduct should at least have one name set')
133
133
 
134
134
  end
135
135
 
@@ -137,7 +137,7 @@ describe OSCRuby::ServiceProduct do
137
137
 
138
138
  new_service_product.names[0] = {"labelText" => "QTH45-test"}
139
139
 
140
- expect{new_service_product.create(client)}.to raise_error('ServiceProduct should at least have one name set (new_service_product.names[0] = {"labelText" => "QTH45-test", "language" => {"id" => 1}} )')
140
+ expect{new_service_product.create(client)}.to raise_error('ServiceProduct should at least have one name set')
141
141
 
142
142
  end
143
143
 
@@ -285,7 +285,7 @@ describe OSCRuby::ServiceProduct do
285
285
 
286
286
  it 'should raise an error if there is no query' do
287
287
 
288
- expect{OSCRuby::ServiceProduct.where(client)}.to raise_error('A query must be specified when using the "where" method')
288
+ expect{OSCRuby::ServiceProduct.where(client)}.to raise_error("A query must be specified when using the 'where' method")
289
289
 
290
290
  end
291
291
 
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: 0.3.0
4
+ version: 0.4.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-01-16 00:00:00.000000000 Z
11
+ date: 2017-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: simplecov
@@ -147,8 +147,11 @@ files:
147
147
  - lib/osc_ruby/configuration.rb
148
148
  - lib/osc_ruby/connect.rb
149
149
  - lib/osc_ruby/incident.rb
150
+ - lib/osc_ruby/product_category_shared.rb
150
151
  - lib/osc_ruby/query_module.rb
152
+ - lib/osc_ruby/query_results.rb
151
153
  - lib/osc_ruby/service_category.rb
154
+ - lib/osc_ruby/service_class.rb
152
155
  - lib/osc_ruby/service_product.rb
153
156
  - lib/osc_ruby/validations_module.rb
154
157
  - lib/osc_ruby/version.rb
@@ -157,6 +160,7 @@ files:
157
160
  - spec/core/client_spec.rb
158
161
  - spec/core/configuration_spec.rb
159
162
  - spec/core/connect_spec.rb
163
+ - spec/core/query_results_spec.rb
160
164
  - spec/core/service_category_spec.rb
161
165
  - spec/core/service_product_spec.rb
162
166
  - spec/core/spec_helper.rb
@@ -190,7 +194,7 @@ test_files:
190
194
  - spec/core/client_spec.rb
191
195
  - spec/core/configuration_spec.rb
192
196
  - spec/core/connect_spec.rb
197
+ - spec/core/query_results_spec.rb
193
198
  - spec/core/service_category_spec.rb
194
199
  - spec/core/service_product_spec.rb
195
200
  - spec/core/spec_helper.rb
196
- has_rdoc: