osc_ruby 0.1.12 → 0.1.13

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: c5fceb5a701385dfdf593d2018410925e3d2c631
4
- data.tar.gz: a710392b55caf3ccf113c13336a0d7515732bc7a
3
+ metadata.gz: 3886686a1a45880611a4e06689c3c4ae573a3f30
4
+ data.tar.gz: 276a472588a6495a688103ac8756184c03b60904
5
5
  SHA512:
6
- metadata.gz: 5595b2e78e460d81cf28f7e6492c23e419c10af3fa2c3f36b9a4ee51a47d43513b11ba26a564cd16cb79ba78687557d8b98489e6217f763c1ddafb7ad3bc8dcd
7
- data.tar.gz: 66147bd97652d38700723080f4c28e4760de2f4aa65cb3bfc49f80fbf623b0abfee0a239ea0f7eac074c0f440480c9df89a25d2d215a61fa78d955d8c9459085
6
+ metadata.gz: f9cd46f98226b08627060983f4d16bd722a05048bb06f9c0bb135a16743c4e68c6e5dfc2a6538e703d8fee299158a7694b256388ab78ad309931684d7cd3103b
7
+ data.tar.gz: a940df9e72dda18074ab014b1be6b490044bfe3a6aa141fe142e5a1af8206fc33fd5f69428b6a4d1dfd733d30d81ee59bf39b634a474d70d71d18db15815238c
data/README.md CHANGED
@@ -43,7 +43,7 @@ An (under development) Ruby ORM for using Oracle Service Cloud influenced by the
43
43
 
44
44
 
45
45
  # NOTE: Make sure that in a production environment
46
- # that the following methods are wrapped in a try/catch block.
46
+ # that the following methods are wrapped in a begin/rescue block.
47
47
 
48
48
  # If a null set is returned by your query
49
49
  # an exception will be raised
@@ -91,11 +91,10 @@ An (under development) Ruby ORM for using Oracle Service Cloud influenced by the
91
91
  # the REST API does not like it when the queries are wrapped in single quotes ('')
92
92
  # with strings escaped by double quotes
93
93
 
94
- # Just a weird little quirk I noticed :laughing:
95
-
96
94
  # For example
97
95
  # "parent is null and lookupName!='Unsure'" => great!
98
- # 'parent is null and lookupName!="Unsure"' => don't do this, it will spit back an error from the REST API!
96
+ # 'parent is null and lookupName!="Unsure"' => don't do this
97
+ # it will spit back an error from the REST API!
99
98
 
100
99
  products_lvl_1 = OSCRuby::ServiceProduct.where(rn_client,"parent is null and lookupName!='Unsure'")
101
100
 
@@ -178,7 +177,7 @@ An (under development) Ruby ORM for using Oracle Service Cloud influenced by the
178
177
 
179
178
  - [x] all
180
179
 
181
- - [ ] update
180
+ - [x] update
182
181
 
183
182
  - [ ] destroy
184
183
 
@@ -36,6 +36,12 @@ module OSCRuby
36
36
 
37
37
  end
38
38
 
39
+ def self.destroy(rn_client,resource)
40
+
41
+ OSCRuby::Connect.delete(rn_client,resource)
42
+
43
+ end
44
+
39
45
  def self.normalize(input)
40
46
 
41
47
  if input.code.to_i == 404
@@ -13,11 +13,11 @@ module OSCRuby
13
13
 
14
14
  def initialize(attributes = nil)
15
15
 
16
- @names = []
16
+ @names = []
17
17
 
18
- @adminVisibleInterfaces = []
18
+ @adminVisibleInterfaces = []
19
19
 
20
- @endUserVisibleInterfaces = []
20
+ @endUserVisibleInterfaces = []
21
21
 
22
22
  if attributes.nil?
23
23
 
@@ -51,7 +51,7 @@ module OSCRuby
51
51
 
52
52
  new_product = self
53
53
 
54
- final_json = self.class.check_self_for_create_and_update_methods(new_product)
54
+ final_json = self.class.check_self(new_product)
55
55
 
56
56
  resource = URI.escape("/serviceProducts")
57
57
 
@@ -101,15 +101,15 @@ module OSCRuby
101
101
 
102
102
  service_product_json = QueryModule::find(client,resource)
103
103
 
104
- if return_json == true
104
+ if return_json == true
105
105
 
106
- service_product_json
106
+ service_product_json
107
107
 
108
- else
108
+ else
109
109
 
110
- service_product_json_final = JSON.parse(service_product_json)
110
+ service_product_json_final = JSON.parse(service_product_json)
111
111
 
112
- new_from_fetch(service_product_json_final[0])
112
+ new_from_fetch(service_product_json_final[0])
113
113
 
114
114
  end
115
115
 
@@ -167,7 +167,9 @@ module OSCRuby
167
167
 
168
168
  product_to_update = self
169
169
 
170
- final_json = self.class.check_self_for_create_and_update_methods(product_to_update,true)
170
+ self.class.check_for_id(product_to_update)
171
+
172
+ final_json = self.class.check_self(product_to_update,true)
171
173
 
172
174
  resource = URI.escape("/serviceProducts/#{product_to_update.id}")
173
175
 
@@ -195,6 +197,40 @@ module OSCRuby
195
197
 
196
198
  end
197
199
 
200
+ def destroy(client, return_json = false)
201
+
202
+ self.class.check_client(client)
203
+
204
+ product_to_destroy = self
205
+
206
+ self.class.check_for_id(product_to_destroy)
207
+
208
+ resource = URI.escape("/serviceProducts/#{product_to_destroy.id}")
209
+
210
+ response = QueryModule::destroy(client,resource)
211
+
212
+ if response.code.to_i == 200 && return_json == false
213
+
214
+ nil
215
+
216
+ elsif return_json == true
217
+
218
+ response.body
219
+
220
+ end
221
+
222
+ end
223
+
224
+
225
+
226
+
227
+
228
+
229
+
230
+
231
+
232
+
233
+
198
234
  # Convenience Methods for making the CRUD operations nicer to use
199
235
 
200
236
  def self.new_from_fetch(attributes)
@@ -205,45 +241,118 @@ module OSCRuby
205
241
 
206
242
  end
207
243
 
208
-
209
- def self.check_self_for_create_and_update_methods(obj,is_update = false)
244
+ def self.check_for_id(obj)
245
+
246
+ if obj.id.nil?
210
247
 
211
- empty_arr = []
248
+ raise ArgumentError, 'OSCRuby::ServiceProduct must have a valid ID set'
249
+
250
+ end
251
+
252
+ end
212
253
 
213
- empty_arr[0] = {}
254
+ def self.check_self(obj,is_update = false)
214
255
 
215
- obj.instance_variables.each {|var| empty_arr[0][var.to_s.delete("@")] = obj.instance_variable_get(var)}
256
+ obj_attrs = self.extract_attributes(obj)
216
257
 
217
258
  if is_update == true
218
- empty_arr[0].delete('id')
219
- empty_arr[0].delete('lookupName')
220
- empty_arr[0].delete('createdTime')
221
- empty_arr[0].delete('updatedTime')
222
- empty_arr[0].delete('name')
259
+
260
+ obj_attrs = remove_unused_new_attrs(obj_attrs)
261
+
262
+ else
263
+
264
+ obj_attrs = check_for_names(obj_attrs)
265
+
266
+ obj_attrs = check_for_parents(obj_attrs)
267
+
223
268
  end
224
269
 
225
- if is_update == false && (empty_arr[0]['names'].count == 0 || empty_arr[0]['names'][0]['labelText'].nil? || empty_arr[0]['names'][0]['language'].nil?)
270
+ obj_attrs
271
+
272
+ end
273
+
274
+ def self.check_for_names(obj_attrs)
275
+
276
+ if obj_attrs[0]['names'].count == 0 || obj_attrs[0]['names'][0]['labelText'].nil? || obj_attrs[0]['names'][0]['language'].nil?
277
+
226
278
  raise ArgumentError, 'ServiceProduct should at least have one name set (new_service_product.names[0] = {"labelText" => "QTH45-test", "language" => {"id" => 1}} )'
279
+
227
280
  end
228
281
 
229
- if !empty_arr[0]['adminVisibleInterfaces'].nil? && empty_arr[0]['adminVisibleInterfaces'].empty?
230
- empty_arr[0].delete('adminVisibleInterfaces')
282
+ obj_attrs
283
+
284
+ end
285
+
286
+ def self.check_for_parents(obj_attrs)
287
+
288
+ 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')
289
+
290
+ obj_attrs[0].delete('parent')
291
+
231
292
  end
232
293
 
233
- if !empty_arr[0]['endUserVisibleInterfaces'].nil? && empty_arr[0]['endUserVisibleInterfaces'].empty?
234
- empty_arr[0].delete('endUserVisibleInterfaces')
294
+ obj_attrs
295
+
296
+ end
297
+
298
+ def self.remove_unused_new_attrs(obj_attrs)
299
+
300
+ obj_attrs[0].delete('id')
301
+
302
+ obj_attrs[0].delete('lookupName')
303
+
304
+ obj_attrs[0].delete('createdTime')
305
+
306
+ obj_attrs[0].delete('updatedTime')
307
+
308
+ obj_attrs[0].delete('name')
309
+
310
+ if !obj_attrs[0]['parent'].nil?
311
+
312
+ obj_attrs[0].delete('parent')
313
+
235
314
  end
236
315
 
237
- if !empty_arr[0]['parent'].nil? && empty_arr[0]['parent'].is_a?(Hash) && !empty_arr[0]['parent'].key?('id') && !empty_arr[0]['parent'].key?('lookupName')
238
- empty_arr[0].delete('parent')
239
- elsif is_update == true && !empty_arr[0]['parent'].nil?
240
- empty_arr[0].delete('parent')
316
+ obj_attrs
317
+
318
+ end
319
+
320
+ def self.extract_attributes(obj)
321
+
322
+ empty_arr = [{}]
323
+
324
+ obj_vars = obj.instance_variables
325
+
326
+ obj_vars.each do |var|
327
+
328
+ obj_attr = var.to_s.delete("@")
329
+
330
+ obj_attr_val = obj.instance_variable_get(var)
331
+
332
+ empty_arr[0][obj_attr] = obj_attr_val
333
+
334
+ end
335
+
336
+ if empty_arr[0]['adminVisibleInterfaces'].empty?
337
+
338
+ empty_arr[0].delete('adminVisibleInterfaces')
339
+
340
+ end
341
+
342
+ if empty_arr[0]['endUserVisibleInterfaces'].empty?
343
+
344
+ empty_arr[0].delete('endUserVisibleInterfaces')
345
+
241
346
  end
242
347
 
243
348
  empty_arr
244
349
 
245
350
  end
246
351
 
352
+
353
+
354
+ # Will probably extract the following into a Validations class or something
355
+
247
356
  def self.check_attributes(attributes)
248
357
 
249
358
  if attributes.class != Hash
@@ -256,7 +365,7 @@ module OSCRuby
256
365
 
257
366
  def self.check_query(query)
258
367
 
259
- if query.empty?
368
+ if query.empty?
260
369
 
261
370
  raise ArgumentError, 'A query must be specified when using the "where" method'
262
371
 
@@ -1,3 +1,3 @@
1
1
  module OSCRuby
2
- VERSION = "0.1.12"
2
+ VERSION = "0.1.13"
3
3
  end
@@ -143,8 +143,8 @@ describe OSCRuby::ServiceProduct do
143
143
 
144
144
  it 'should return an instance of an OSCRuby::ServiceProduct if the json_response param is set to false (which it is by default)' do
145
145
 
146
- new_service_product.names[0] = {"labelText" => "QTH45", "language" => {"id" => 1}}
147
- new_service_product.names[1] = {"labelText" => "QTH45", "language" => {"id" => 11}}
146
+ new_service_product.names[0] = {"labelText" => "TEST-PRODUCT", "language" => {"id" => 1}}
147
+ new_service_product.names[1] = {"labelText" => "TEST-PRODUCT", "language" => {"id" => 11}}
148
148
 
149
149
  new_service_product.parent = {'id' => 102}
150
150
 
@@ -154,9 +154,9 @@ describe OSCRuby::ServiceProduct do
154
154
 
155
155
  expect(new_service_product).to be_a(OSCRuby::ServiceProduct)
156
156
 
157
- expect(new_service_product.name).to eq("QTH45")
157
+ expect(new_service_product.name).to eq("TEST-PRODUCT")
158
158
 
159
- expect(new_service_product.lookupName).to eq("QTH45")
159
+ expect(new_service_product.lookupName).to eq("TEST-PRODUCT")
160
160
 
161
161
  expect(new_service_product.displayOrder).to eq(4)
162
162
 
@@ -167,8 +167,8 @@ describe OSCRuby::ServiceProduct do
167
167
 
168
168
  it 'should return the body object if the json_response param is set to true' do
169
169
 
170
- new_service_product.names[0] = {"labelText" => "QTH45-test", "language" => {"id" => 1}}
171
- new_service_product.names[1] = {'labelText' => 'QTH45-test', 'language' => {'id' => 11}}
170
+ new_service_product.names[0] = {"labelText" => "TEST-PRODUCT", "language" => {"id" => 1}}
171
+ new_service_product.names[1] = {'labelText' => 'TEST-PRODUCT', 'language' => {'id' => 11}}
172
172
 
173
173
  expect(new_service_product.create(client,true)).to be_a(String)
174
174
 
@@ -334,7 +334,7 @@ describe OSCRuby::ServiceProduct do
334
334
  OSCRuby::ServiceProduct.find(client, 100)
335
335
  }
336
336
 
337
- context 'update' do
337
+ context '#update' do
338
338
 
339
339
  it 'should expect client is an instance of OSCRuby::Client class and raise an error if does not' do
340
340
 
@@ -346,6 +346,20 @@ describe OSCRuby::ServiceProduct do
346
346
 
347
347
  end
348
348
 
349
+ it 'should expect that the Service Product is an instance of a OSCRuby::ServiceProduct' do
350
+
351
+ expect(known_working_product).to be_an(OSCRuby::ServiceProduct)
352
+
353
+ end
354
+
355
+ it 'should expect that the product has an ID and spit out an error if it does not' do
356
+
357
+ known_working_product.id = nil
358
+
359
+ expect{known_working_product.destroy(client)}.to raise_error('OSCRuby::ServiceProduct must have a valid ID set')
360
+
361
+ end
362
+
349
363
  it 'should update name when the names is updated' do
350
364
 
351
365
  test_prods = OSCRuby::ServiceProduct.where(client,"name like 'QTH45-test'")
@@ -369,4 +383,49 @@ describe OSCRuby::ServiceProduct do
369
383
 
370
384
  end
371
385
 
386
+ let(:product_to_delete){
387
+
388
+ test_prods = OSCRuby::ServiceProduct.where(client,"name like 'TEST-PRODUCT'")
389
+ test_prods[0]
390
+
391
+ }
392
+
393
+ context '#destroy' do
394
+
395
+ it 'should expect client is an instance of OSCRuby::Client class and raise an error if does not' do
396
+
397
+ expect(client).to be_an(OSCRuby::Client)
398
+
399
+ client = nil
400
+
401
+ expect{product_to_delete.destroy(client)}.to raise_error('Client must have some configuration set; please create an instance of OSCRuby::Client with configuration settings')
402
+
403
+ end
404
+
405
+ it 'should expect that the Service Product is an instance of a OSCRuby::ServiceProduct' do
406
+
407
+ expect(product_to_delete).to be_an(OSCRuby::ServiceProduct)
408
+
409
+ end
410
+
411
+ it 'should expect that the product has an ID and spit out an error if it does not' do
412
+
413
+ product_to_delete.id = nil
414
+
415
+ expect{product_to_delete.destroy(client)}.to raise_error('OSCRuby::ServiceProduct must have a valid ID set')
416
+
417
+ end
418
+
419
+ it 'should delete the product' do
420
+
421
+ id_to_find = product_to_delete.id
422
+
423
+ product_to_delete.destroy(client)
424
+
425
+ expect{OSCRuby::ServiceProduct.find(client, id_to_find)}.to raise_error('There were no objects matching your query; please try again.')
426
+
427
+ end
428
+
429
+ end
430
+
372
431
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: osc_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.12
4
+ version: 0.1.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rajan Davis