osc_ruby 0.1.11 → 0.1.12

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: 4bc50905b48d26b1698634ac20061eab7cce0419
4
- data.tar.gz: 97085cc0a83a89712f99237331127003c33df28a
3
+ metadata.gz: c5fceb5a701385dfdf593d2018410925e3d2c631
4
+ data.tar.gz: a710392b55caf3ccf113c13336a0d7515732bc7a
5
5
  SHA512:
6
- metadata.gz: 61715b80abd499d58a54a092ca2182fddeb7d060c2cb5d4110310a23e677d8ca33aee8cfdcb9f89019ad4b9663fdeeca4952872d2b40bac617487c78baa87347
7
- data.tar.gz: 4bdadebfd21df4e8a7d9f9d5a33250f138852020b357d9e1ad0f2ce2660e9441454c993c315bc2837d8ff5b3219654d2d5cb9418a1a8f8659e1093a1bb79d0bc
6
+ metadata.gz: 5595b2e78e460d81cf28f7e6492c23e419c10af3fa2c3f36b9a4ee51a47d43513b11ba26a564cd16cb79ba78687557d8b98489e6217f763c1ddafb7ad3bc8dcd
7
+ data.tar.gz: 66147bd97652d38700723080f4c28e4760de2f4aa65cb3bfc49f80fbf623b0abfee0a239ea0f7eac074c0f440480c9df89a25d2d215a61fa78d955d8c9459085
data/README.md CHANGED
@@ -83,9 +83,21 @@ An (under development) Ruby ORM for using Oracle Service Cloud influenced by the
83
83
  # => QS Series
84
84
  # => QT Series
85
85
 
86
- # ServiceProduct where example
87
86
 
88
- products_lvl_1 = OSCRuby::ServiceProduct.where(rn_client,'parent is null and lookupName!="Unsure"')
87
+ # ServiceProduct where example (Completed 01/05/2017)
88
+
89
+ # NOTE: Make sure to put your queries wrapped in doublequotes("")
90
+ # this is because when Ruby converts the queries into a URI
91
+ # the REST API does not like it when the queries are wrapped in single quotes ('')
92
+ # with strings escaped by double quotes
93
+
94
+ # Just a weird little quirk I noticed :laughing:
95
+
96
+ # For example
97
+ # "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!
99
+
100
+ products_lvl_1 = OSCRuby::ServiceProduct.where(rn_client,"parent is null and lookupName!='Unsure'")
89
101
 
90
102
  products_lvl_1.each do |p|
91
103
 
@@ -98,10 +110,7 @@ An (under development) Ruby ORM for using Oracle Service Cloud influenced by the
98
110
  # => Accessories
99
111
 
100
112
 
101
-
102
-
103
-
104
- # ServiceProduct update example
113
+ # ServiceProduct update example (Completed 01/05/2017)
105
114
 
106
115
  product_to_update = OSCRuby::ServiceProduct.find(rn_client,100)
107
116
 
@@ -112,6 +121,8 @@ An (under development) Ruby ORM for using Oracle Service Cloud influenced by the
112
121
  # ServiceProduct updated
113
122
 
114
123
 
124
+
125
+
115
126
  # ServiceProduct destroy example
116
127
 
117
128
  product_to_delete = OSCRuby::ServiceProduct.find(rn_client,100)
@@ -30,6 +30,12 @@ module OSCRuby
30
30
 
31
31
  end
32
32
 
33
+ def self.update(rn_client,resource,json_content)
34
+
35
+ OSCRuby::Connect.post_or_patch(rn_client,resource,json_content,true)
36
+
37
+ end
38
+
33
39
  def self.normalize(input)
34
40
 
35
41
  if input.code.to_i == 404
@@ -13,17 +13,17 @@ module OSCRuby
13
13
 
14
14
  def initialize(attributes = nil)
15
15
 
16
- if attributes.nil?
16
+ @names = []
17
17
 
18
- @names = []
18
+ @adminVisibleInterfaces = []
19
19
 
20
- @parent = {}
20
+ @endUserVisibleInterfaces = []
21
21
 
22
- @displayOrder = 1
22
+ if attributes.nil?
23
23
 
24
- @adminVisibleInterfaces = []
24
+ @parent = {}
25
25
 
26
- @endUserVisibleInterfaces = []
26
+ @displayOrder = 1
27
27
 
28
28
  else
29
29
 
@@ -51,7 +51,7 @@ module OSCRuby
51
51
 
52
52
  new_product = self
53
53
 
54
- final_json = self.class.check_self_for_create_method(new_product)
54
+ final_json = self.class.check_self_for_create_and_update_methods(new_product)
55
55
 
56
56
  resource = URI.escape("/serviceProducts")
57
57
 
@@ -161,10 +161,41 @@ module OSCRuby
161
161
 
162
162
  end
163
163
 
164
+ def update(client, return_json = false)
165
+
166
+ self.class.check_client(client)
164
167
 
168
+ product_to_update = self
165
169
 
166
- # Convenience Methods for making the CRUD operations nicer to use
170
+ final_json = self.class.check_self_for_create_and_update_methods(product_to_update,true)
171
+
172
+ resource = URI.escape("/serviceProducts/#{product_to_update.id}")
173
+
174
+ response = QueryModule::update(client,resource,final_json)
175
+
176
+ if response.code.to_i == 200 && return_json == false
177
+
178
+ updated_product = OSCRuby::ServiceProduct.find(client,product_to_update.id)
167
179
 
180
+ self.lookupName = updated_product.lookupName
181
+
182
+ self.createdTime = updated_product.createdTime
183
+
184
+ self.updatedTime = updated_product.updatedTime
185
+
186
+ self.name = updated_product.name
187
+
188
+ self.parent = updated_product.parent
189
+
190
+ elsif return_json == true
191
+
192
+ response.body
193
+
194
+ end
195
+
196
+ end
197
+
198
+ # Convenience Methods for making the CRUD operations nicer to use
168
199
 
169
200
  def self.new_from_fetch(attributes)
170
201
 
@@ -175,27 +206,37 @@ module OSCRuby
175
206
  end
176
207
 
177
208
 
178
- def self.check_self_for_create_method(obj)
209
+ def self.check_self_for_create_and_update_methods(obj,is_update = false)
179
210
 
180
- empty_arr = []
211
+ empty_arr = []
181
212
 
182
- empty_arr[0] = {}
213
+ empty_arr[0] = {}
183
214
 
184
215
  obj.instance_variables.each {|var| empty_arr[0][var.to_s.delete("@")] = obj.instance_variable_get(var)}
185
216
 
186
- if empty_arr[0]['names'].count == 0 || empty_arr[0]['names'][0]['labelText'].nil? || empty_arr[0]['names'][0]['language'].nil?
217
+ 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')
223
+ end
224
+
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?)
187
226
  raise ArgumentError, 'ServiceProduct should at least have one name set (new_service_product.names[0] = {"labelText" => "QTH45-test", "language" => {"id" => 1}} )'
188
227
  end
189
228
 
190
- if empty_arr[0]['adminVisibleInterfaces'].empty?
229
+ if !empty_arr[0]['adminVisibleInterfaces'].nil? && empty_arr[0]['adminVisibleInterfaces'].empty?
191
230
  empty_arr[0].delete('adminVisibleInterfaces')
192
231
  end
193
232
 
194
- if empty_arr[0]['endUserVisibleInterfaces'].empty?
233
+ if !empty_arr[0]['endUserVisibleInterfaces'].nil? && empty_arr[0]['endUserVisibleInterfaces'].empty?
195
234
  empty_arr[0].delete('endUserVisibleInterfaces')
196
235
  end
197
236
 
198
- if !empty_arr[0]['parent'].key?('id') && !empty_arr[0]['parent'].key?('lookupName')
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?
199
240
  empty_arr[0].delete('parent')
200
241
  end
201
242
 
@@ -1,3 +1,3 @@
1
1
  module OSCRuby
2
- VERSION = "0.1.11"
2
+ VERSION = "0.1.12"
3
3
  end
@@ -206,10 +206,12 @@ describe OSCRuby::ServiceProduct do
206
206
 
207
207
  end
208
208
 
209
+
209
210
  let(:known_working_product){
210
211
  OSCRuby::ServiceProduct.find(client, 100)
211
212
  }
212
213
 
214
+
213
215
  it 'should return an instance of a new OSCRuby::ServiceProduct object with at least a name and displayOrder' do
214
216
 
215
217
  expect(known_working_product).to be_an(OSCRuby::ServiceProduct)
@@ -328,4 +330,43 @@ describe OSCRuby::ServiceProduct do
328
330
 
329
331
  end
330
332
 
333
+ let(:known_working_product){
334
+ OSCRuby::ServiceProduct.find(client, 100)
335
+ }
336
+
337
+ context 'update' do
338
+
339
+ it 'should expect client is an instance of OSCRuby::Client class and raise an error if does not' do
340
+
341
+ expect(client).to be_an(OSCRuby::Client)
342
+
343
+ client = nil
344
+
345
+ expect{known_working_product.update(client)}.to raise_error('Client must have some configuration set; please create an instance of OSCRuby::Client with configuration settings')
346
+
347
+ end
348
+
349
+ it 'should update name when the names is updated' do
350
+
351
+ test_prods = OSCRuby::ServiceProduct.where(client,"name like 'QTH45-test'")
352
+ first_prod = test_prods[0]
353
+
354
+ first_prod.names[0] = {"labelText" => "QTH45-test-UPDATED", "language" => {"id" => 1}}
355
+
356
+ first_prod.update(client)
357
+
358
+ expect(first_prod.name).to eq('QTH45-test-UPDATED')
359
+
360
+ end
361
+
362
+ it 'should just return JSON if the return_json parameter is set to true' do
363
+
364
+ test = known_working_product.update(client,true)
365
+
366
+ expect(test).to be_a(String)
367
+
368
+ end
369
+
370
+ end
371
+
331
372
  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.11
4
+ version: 0.1.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rajan Davis