osc_ruby 0.1.10 → 0.1.11

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: ca63de8b887f3fd7a4f053fa2169013a9ec0121a
4
- data.tar.gz: d51fe8fd736021ed2bcd74cf68b758e92ba0f25e
3
+ metadata.gz: 4bc50905b48d26b1698634ac20061eab7cce0419
4
+ data.tar.gz: 97085cc0a83a89712f99237331127003c33df28a
5
5
  SHA512:
6
- metadata.gz: c907042c7cbad989ae25e304bfc85182b92295fd55c07eeb3159ff1af9695f93577383c68c27dd0a693bfb28b609e388b60efd805aaab044100d627fa50d7f41
7
- data.tar.gz: e6340ed3dc8cf652e92cbfcac44abc7b184ef42c509e22c2f39c19144e6d358f04ebba1d8e6815348aca1a285313db841e54e0bdfa254b97e036c27501ebe757
6
+ metadata.gz: 61715b80abd499d58a54a092ca2182fddeb7d060c2cb5d4110310a23e677d8ca33aee8cfdcb9f89019ad4b9663fdeeca4952872d2b40bac617487c78baa87347
7
+ data.tar.gz: 4bdadebfd21df4e8a7d9f9d5a33250f138852020b357d9e1ad0f2ce2660e9441454c993c315bc2837d8ff5b3219654d2d5cb9418a1a8f8659e1093a1bb79d0bc
data/README.md CHANGED
@@ -40,6 +40,18 @@ An (under development) Ruby ORM for using Oracle Service Cloud influenced by the
40
40
  # callback with JSON details
41
41
 
42
42
 
43
+
44
+
45
+ # NOTE: Make sure that in a production environment
46
+ # that the following methods are wrapped in a try/catch block.
47
+
48
+ # If a null set is returned by your query
49
+ # an exception will be raised
50
+ # this is to ensure that you
51
+ # handle your errors explicitly
52
+ # when writing scripts
53
+
54
+
43
55
  # ServiceProduct fetch example (Completed 12/28/2016)
44
56
 
45
57
  product = OSCRuby::ServiceProduct.find(rn_client,100)
@@ -53,7 +65,7 @@ An (under development) Ruby ORM for using Oracle Service Cloud influenced by the
53
65
  puts product.displayOrder
54
66
  # => 3
55
67
 
56
- # ServiceProduct fetch all example
68
+ # ServiceProduct fetch all example (Completed 01/05/2017)
57
69
 
58
70
  products = OSCRuby::ServiceProduct.all(rn_client)
59
71
 
@@ -71,6 +83,24 @@ An (under development) Ruby ORM for using Oracle Service Cloud influenced by the
71
83
  # => QS Series
72
84
  # => QT Series
73
85
 
86
+ # ServiceProduct where example
87
+
88
+ products_lvl_1 = OSCRuby::ServiceProduct.where(rn_client,'parent is null and lookupName!="Unsure"')
89
+
90
+ products_lvl_1.each do |p|
91
+
92
+ puts p.name
93
+
94
+ end
95
+
96
+ # => DVR/NVR
97
+ # => Cameras
98
+ # => Accessories
99
+
100
+
101
+
102
+
103
+
74
104
  # ServiceProduct update example
75
105
 
76
106
  product_to_update = OSCRuby::ServiceProduct.find(rn_client,100)
@@ -128,18 +158,14 @@ An (under development) Ruby ORM for using Oracle Service Cloud influenced by the
128
158
  - [x] Create a OSCRuby::ServiceProduct class
129
159
 
130
160
  - [x] Build a QueryModule Module with the following query methods to be shared between most if not all classes:
161
+
162
+ - [x] create
131
163
 
132
164
  - [x] find
165
+
166
+ - [x] where
133
167
 
134
- - [ ] find_by
135
-
136
- - [ ] where
137
-
138
- - [ ] all
139
-
140
- - [ ] Also add the following remaining CRUD Functionality:
141
-
142
- - [x] create
168
+ - [x] all
143
169
 
144
170
  - [ ] update
145
171
 
@@ -153,6 +179,8 @@ An (under development) Ruby ORM for using Oracle Service Cloud influenced by the
153
179
 
154
180
  - [ ] Make version default to 1.3 but an option to be set in the config class
155
181
 
182
+ - [ ] Allow for the prefer:exclude-null-properties header => update config and connect class, update tests
183
+
156
184
  - [ ] Allow for Session Authorization => update config class and connect classes, update tests
157
185
 
158
186
  - [ ] Figure out how to do RDoc/Yardoc documentation or best in class documentation for using this Ruby ORM
@@ -3,6 +3,7 @@ require 'osc_ruby/client'
3
3
  require 'net/http'
4
4
  require 'openssl'
5
5
  require 'uri'
6
+ require 'cgi'
6
7
 
7
8
  module OSCRuby
8
9
 
@@ -14,6 +15,7 @@ module OSCRuby
14
15
  @final_config = get_check(client,resource_url)
15
16
 
16
17
  @uri = @final_config['site_url']
18
+
17
19
  @username = @final_config['username']
18
20
  @password = @final_config['password']
19
21
 
@@ -11,9 +11,16 @@ module OSCRuby
11
11
 
12
12
  obj_to_find = OSCRuby::Connect.get(rn_client,resource)
13
13
 
14
- check_obj_for_errors(obj_to_find)
14
+ if obj_to_find.code.to_i == 200 || obj_to_find.code.to_i == 201
15
15
 
16
- normalize(obj_to_find)
16
+ check_obj_for_errors(obj_to_find)
17
+
18
+ normalize(obj_to_find)
19
+ else
20
+
21
+ obj_to_find.body
22
+
23
+ end
17
24
 
18
25
  end
19
26
 
@@ -57,7 +64,7 @@ module OSCRuby
57
64
 
58
65
  json_obj = JSON.parse(obj_to_check.body)
59
66
 
60
- if json_obj['items'][0]['rows'].count == 0
67
+ if !json_obj.nil? && json_obj['items'][0]['rows'].count == 0
61
68
 
62
69
  raise ArgumentError, 'There were no objects matching your query; please try again.'
63
70
 
@@ -116,6 +116,8 @@ module OSCRuby
116
116
  end
117
117
 
118
118
  def self.all(client, return_json = false)
119
+
120
+ check_client(client)
119
121
 
120
122
  resource = URI.escape("queryResults/?query=select * from serviceproducts")
121
123
 
@@ -135,6 +137,35 @@ module OSCRuby
135
137
 
136
138
  end
137
139
 
140
+ def self.where(client, query = '', return_json = false)
141
+
142
+ check_client(client)
143
+
144
+ check_query(query)
145
+
146
+ @query = URI.escape("queryResults/?query=select * from serviceproducts where #{query}")
147
+
148
+ service_product_json = QueryModule::find(client,@query)
149
+
150
+ if return_json == true
151
+
152
+ service_product_json
153
+
154
+ else
155
+
156
+ service_product_json_final = JSON.parse(service_product_json)
157
+
158
+ service_product_json_final.map { |attributes| new_from_fetch(attributes) }
159
+
160
+ end
161
+
162
+ end
163
+
164
+
165
+
166
+ # Convenience Methods for making the CRUD operations nicer to use
167
+
168
+
138
169
  def self.new_from_fetch(attributes)
139
170
 
140
171
  check_attributes(attributes)
@@ -143,6 +174,7 @@ module OSCRuby
143
174
 
144
175
  end
145
176
 
177
+
146
178
  def self.check_self_for_create_method(obj)
147
179
 
148
180
  empty_arr = []
@@ -181,6 +213,16 @@ module OSCRuby
181
213
 
182
214
  end
183
215
 
216
+ def self.check_query(query)
217
+
218
+ if query.empty?
219
+
220
+ raise ArgumentError, 'A query must be specified when using the "where" method'
221
+
222
+ end
223
+
224
+ end
225
+
184
226
  def self.check_client(client)
185
227
 
186
228
  if client.class != OSCRuby::Client || client.nil?
@@ -1,3 +1,3 @@
1
1
  module OSCRuby
2
- VERSION = "0.1.10"
2
+ VERSION = "0.1.11"
3
3
  end
@@ -232,13 +232,23 @@ describe OSCRuby::ServiceProduct do
232
232
 
233
233
  context '#all' do
234
234
 
235
+ it 'should expect client is an instance of OSCRuby::Client class and raise an error if does not' do
236
+
237
+ expect(client).to be_an(OSCRuby::Client)
238
+
239
+ client = nil
240
+
241
+ expect{OSCRuby::ServiceProduct.all(client)}.to raise_error('Client must have some configuration set; please create an instance of OSCRuby::Client with configuration settings')
242
+
243
+ end
244
+
235
245
  it 'should return multiple instances of OSCRuby::ServiceProduct' do
236
246
 
237
247
  products = OSCRuby::ServiceProduct.all(client)
238
248
 
239
249
  expect(products.size).to be > 0
240
250
 
241
- puts "Checking if OSCRuby::ServiceProduct.all produces multiple instances of products"
251
+ # puts "Checking if OSCRuby::ServiceProduct.all produces multiple instances of products"
242
252
 
243
253
  products.each_with_index do |p,i|
244
254
 
@@ -246,6 +256,8 @@ describe OSCRuby::ServiceProduct do
246
256
 
247
257
  expect(p).to be_an(OSCRuby::ServiceProduct)
248
258
 
259
+ # puts p.name
260
+
249
261
  end
250
262
 
251
263
  end
@@ -260,7 +272,59 @@ describe OSCRuby::ServiceProduct do
260
272
 
261
273
  end
262
274
 
263
- contect '#where' do
275
+ context '#where' do
276
+
277
+ it 'should expect client is an instance of OSCRuby::Client class and raise an error if does not' do
278
+
279
+ expect(client).to be_an(OSCRuby::Client)
280
+
281
+ client = nil
282
+
283
+ expect{OSCRuby::ServiceProduct.where(client,'query')}.to raise_error('Client must have some configuration set; please create an instance of OSCRuby::Client with configuration settings')
284
+
285
+ end
286
+
287
+ it 'should raise an error if there is no query' do
288
+
289
+ expect{OSCRuby::ServiceProduct.where(client)}.to raise_error('A query must be specified when using the "where" method')
290
+
291
+ end
292
+
293
+ it 'should take a query and return results' do
294
+
295
+ products_lvl_1 = OSCRuby::ServiceProduct.where(client,"parent is null and lookupname not like 'Unsure'")
296
+
297
+ expect(products_lvl_1.count).to be > 0
298
+
299
+ products_lvl_1.each_with_index do |p,i|
300
+
301
+ if i < 10
302
+
303
+ expect(p).to be_an(OSCRuby::ServiceProduct)
304
+
305
+ # puts p.name
306
+
307
+ end
308
+
309
+ end
310
+
311
+ end
312
+
313
+ it 'should raise an error if the query returns 0 results' do
314
+
315
+ expect{OSCRuby::ServiceProduct.where(client,"parent = 6546546546546")}.to raise_error('There were no objects matching your query; please try again.')
316
+
317
+ end
318
+
319
+ it 'should just return JSON if the return_json parameter is set to true' do
320
+
321
+ parents = OSCRuby::ServiceProduct.where(client,"parent is null and lookupname not like 'Unsure'",true)
322
+
323
+ expect(parents).to be_a(String)
324
+
325
+ # puts parents
326
+
327
+ end
264
328
 
265
329
  end
266
330
 
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.10
4
+ version: 0.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rajan Davis