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 +4 -4
- data/README.md +17 -6
- data/lib/osc_ruby/query_module.rb +6 -0
- data/lib/osc_ruby/service_product.rb +56 -15
- data/lib/osc_ruby/version.rb +1 -1
- data/spec/core/service_product_spec.rb +41 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c5fceb5a701385dfdf593d2018410925e3d2c631
|
4
|
+
data.tar.gz: a710392b55caf3ccf113c13336a0d7515732bc7a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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)
|
@@ -13,17 +13,17 @@ module OSCRuby
|
|
13
13
|
|
14
14
|
def initialize(attributes = nil)
|
15
15
|
|
16
|
-
|
16
|
+
@names = []
|
17
17
|
|
18
|
-
@
|
18
|
+
@adminVisibleInterfaces = []
|
19
19
|
|
20
|
-
@
|
20
|
+
@endUserVisibleInterfaces = []
|
21
21
|
|
22
|
-
|
22
|
+
if attributes.nil?
|
23
23
|
|
24
|
-
@
|
24
|
+
@parent = {}
|
25
25
|
|
26
|
-
@
|
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.
|
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
|
-
|
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.
|
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
|
-
|
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
|
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
|
|
data/lib/osc_ruby/version.rb
CHANGED
@@ -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
|