osc_ruby 0.0.14 → 0.1.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: dee13cf76e6f6b83ce9267ad148881292dac66ac
4
- data.tar.gz: 4f47c7b2a5124275da8db617e33c57d9d98efedc
3
+ metadata.gz: 8037699e524a610096534990ff8c2a5c6b675375
4
+ data.tar.gz: de4304b8f05ed89f3226d67ab8b310d6c9ce430f
5
5
  SHA512:
6
- metadata.gz: 39721cd8d4fb63338a461f2f057eb38a3f80a0d69e8aaee1fd28c46ef6f07aba0edd8b262267154103b3d7f97ec44ca541241a86d54a8efa5c5d882945a0dc86
7
- data.tar.gz: 02ed3894d1a86a82b803d00f08fa3ca91795f17f2df036a143fa7fb8374444f0923ee05279ef3abb62f2c40669bc9e2e1811d3bf9330e4fd257a1a9edb8c7265
6
+ metadata.gz: eceab49e9e22cd4965d9e386c1f78fe2dccbe1676ddf48d4a47818c4cf039d8903c67b06aaf3717bf87783f7054f1cadb118202912ae8c2acf6cf85e9b6b6b6a
7
+ data.tar.gz: 202c440ec8081ddce1542131e1624dd97c7b1b0229fbd8efe64f99b404558778407446d7196ab10f6a0be88680c0e9fd173cbda80bb4b00db6ccbc06ae563a7d
data/README.md CHANGED
@@ -4,11 +4,7 @@
4
4
 
5
5
  [![Test Coverage](https://codeclimate.com/github/rajangdavis/osc_ruby/badges/coverage.svg)](https://codeclimate.com/github/rajangdavis/osc_ruby/coverage)
6
6
 
7
- Still developing this; will let ya know when this happens.
8
-
9
- The basic idea is to be able to do something simple like import a csv of information and post it into an Oracle Service Cloud site.
10
-
11
- The ultimate goal is to use this gem to make a Rails app for advanced administration/development that cannot be done with Oracle Service Cloud alone
7
+ An (under development) Ruby ORM for using Oracle Service Cloud influenced by the ConnectPHP API and ActiveRecord Gem
12
8
 
13
9
  ## Example (still coding this out, but trying to get this pretty simple)
14
10
 
@@ -22,38 +18,45 @@ The ultimate goal is to use this gem to make a Rails app for advanced administra
22
18
 
23
19
  product = OSCRuby::ServiceProduct.fetch(1)
24
20
 
21
+ # returns OSCRuby::ServiceProduct object with id of 1
22
+
25
23
  puts product.name
26
24
 
27
- # puts 'Product Lookup Name'
25
+ # =>'Product Lookup Name'
26
+
27
+ puts product.displayOrder
28
+
29
+ # => 64
30
+
31
+
32
+
28
33
 
29
34
  # Product Creation example
30
35
 
31
- names = []
36
+ new_product = OSCRuby::ServiceProduct.new
32
37
 
33
- names[0] = {:labelText => 'QTH45-test', :language => {:id => 1}}
34
- names[1] = {:labelText => 'QTH45-test', :language => {:id => 11}}
38
+ # use Ruby hashes to set field information
35
39
 
36
- parent = {:id => 102}
40
+ new_product.names[0] = {:labelText => 'QTH45-test', :language => {:id => 1}}
41
+ new_product.names[1] = {:labelText => 'QTH45-test', :language => {:id => 11}}
37
42
 
38
- displayOrder = {:id => 4}
43
+ new_product.parent = {:id => 102}
39
44
 
40
- admin_user_visible_interfaces = []
41
- admin_user_visible_interfaces[0] = {:id => 1}
45
+ new_product.displayOrder = {:id => 4}
42
46
 
43
- end_user_visible_interfaces = []
44
- end_user_visible_interfaces[0] = {:id => 1}
47
+ new_product.adminUserVisibleInterfaces[0] = {:id => 1}
45
48
 
46
- new_prod = []
47
- new_prod[0] = {:names => names,
48
- :parent => parent,
49
- :adminVisibleInterfaces => admin_user_visible_interfaces,
50
- :endUserVisibleInterfaces => end_user_visible_interfaces}
49
+ new_product.endUserVisibleInterfaces[0] = {:id => 1}
51
50
 
52
- OSCRuby::ServiceProduct.save(client, new_prod)
51
+ new_product.save(client)
53
52
 
54
53
  # callback with JSON details
55
54
 
56
- ## TODO
55
+
56
+
57
+
58
+
59
+ ## To do list
57
60
 
58
61
  - [x] Create a URL generator method into the Connect Class
59
62
 
@@ -79,18 +82,18 @@ The ultimate goal is to use this gem to make a Rails app for advanced administra
79
82
 
80
83
  - [x] Make a Post method
81
84
 
82
- - [ ] Add in tests for patch requests
85
+ - [x] Add in tests for patch requests
83
86
 
84
- - [ ] Make a patch method
87
+ - [x] Make a patch method
85
88
 
86
- - [ ] Add in tests for delete requests
89
+ - [x] Add in tests for delete requests
87
90
 
88
- - [ ] Make a delete method
89
-
90
- - [ ] I might need to do a transformation class that converts JSON response into a Ruby Hash
91
+ - [x] Make a delete method
91
92
 
92
93
  - [ ] Create a OSCRuby::ServiceProduct class
93
94
 
95
+ - [ ] I might need to do a transformation class that converts JSON response into a Ruby Hash
96
+
94
97
  - [ ] Figure out how to do RDoc/Yardoc documentation or best in class documentation for using this Ruby Wrapper
95
98
 
96
99
  - [ ] Add in VCR and WebMock as dependencies
@@ -32,9 +32,35 @@ module OSCRuby
32
32
 
33
33
  end
34
34
 
35
- def self.post(client,resource_url = nil, json_content = nil)
35
+ def self.post_or_patch(client,resource_url = nil, json_content = nil,patch_request = false)
36
36
 
37
- @final_config = post_check(client,resource_url, json_content)
37
+ @final_config = post_and_patch_check(client,resource_url, json_content, patch_request)
38
+
39
+ @uri = @final_config['site_url']
40
+ @username = @final_config['username']
41
+ @password = @final_config['password']
42
+
43
+ Net::HTTP.start(@uri.host, @uri.port,
44
+ :use_ssl => true,
45
+ :verify_mode => OpenSSL::SSL::VERIFY_NONE) do |http|
46
+
47
+ request = Net::HTTP::Post.new @uri.request_uri
48
+ request.basic_auth @username, @password
49
+ request.content_type = "application/json"
50
+ if @final_config['patch_request'] == true
51
+ request.add_field 'X-HTTP-Method-Override','PATCH'
52
+ end
53
+ request.body = JSON.dump(json_content)
54
+
55
+ http.request request # Net::HTTPResponse object
56
+
57
+ end
58
+
59
+ end
60
+
61
+ def self.delete(client,resource_url = nil)
62
+
63
+ @final_config = delete_check(client,resource_url)
38
64
 
39
65
  @uri = @final_config['site_url']
40
66
  @username = @final_config['username']
@@ -44,20 +70,19 @@ module OSCRuby
44
70
  :use_ssl => true,
45
71
  :verify_mode => OpenSSL::SSL::VERIFY_NONE) do |http|
46
72
 
47
- request = Net::HTTP::Post.new @uri.request_uri
73
+ request = Net::HTTP::Delete.new @uri.request_uri
48
74
  request.basic_auth @username, @password
49
- request.content_type = "application/json"
50
- request.body = JSON.dump(json_content)
51
75
 
52
76
  http.request request # Net::HTTPResponse object
53
77
 
54
78
  end
55
-
79
+
56
80
  end
57
81
 
58
- protected
59
82
 
60
- def self.generate_url_and_config(client,resource_url = nil)
83
+ ## checking methods
84
+
85
+ def self.generate_url_and_config(client,resource_url = nil, patch_request = false)
61
86
 
62
87
  check_client_config(client)
63
88
 
@@ -70,8 +95,10 @@ module OSCRuby
70
95
  @url = "https://" + @config.interface + ".custhelp.com/services/rest/connect/v1.3/#{resource_url}"
71
96
 
72
97
  @final_uri = URI(@url)
98
+
99
+ @patch_request = patch_request == true ? true : false
73
100
 
74
- @final_config = {'site_url' => @final_uri, 'username' => @config.username, 'password' => @config.password}
101
+ @final_config = {'site_url' => @final_uri, 'username' => @config.username, 'password' => @config.password, 'patch_request' => @patch_request}
75
102
 
76
103
  end
77
104
 
@@ -107,19 +134,32 @@ module OSCRuby
107
134
 
108
135
  end
109
136
 
110
- def self.post_check(client,resource_url = nil, json_content = nil)
137
+ def self.post_and_patch_check(client,resource_url = nil, json_content = nil, patch_request = false)
111
138
 
112
139
  if client.nil?
113
140
  raise ArgumentError, "Client must have some configuration set; please create an instance of OSCRuby::Client with configuration settings"
114
141
  elsif resource_url.nil?
115
- raise ArgumentError, "There is no URL resource provided; please specify a URL resource that you would like to send a POST request to"
142
+ raise ArgumentError, "There is no URL resource provided; please specify a URL resource that you would like to send a POST or PATCH request to"
116
143
  elsif json_content.nil?
117
- raise ArgumentError, "There is no json content provided; please specify json content that you would like to send a POST request with"
144
+ raise ArgumentError, "There is no json content provided; please specify json content that you would like to send a POST or PATCH request with"
145
+ elsif patch_request == true
146
+ @final_config = generate_url_and_config(client,resource_url,true)
118
147
  else
119
148
  @final_config = generate_url_and_config(client,resource_url)
120
149
  end
121
150
 
122
151
  end
123
152
 
124
- end
153
+ def self.delete_check(client,resource_url = nil)
154
+ if client.nil?
155
+ raise ArgumentError, "Client must have some configuration set; please create an instance of OSCRuby::Client with configuration settings"
156
+ elsif resource_url.nil?
157
+ raise ArgumentError, "There is no URL resource provided; please specify a URL resource that you would like to send a POST or PATCH request to"
158
+ else
159
+ @final_config = generate_url_and_config(client,resource_url)
160
+ end
161
+ end
162
+
163
+ end
164
+
125
165
  end
@@ -1,3 +1,3 @@
1
1
  module OSCRuby
2
- VERSION = "0.0.14"
2
+ VERSION = "0.1.0"
3
3
  end
data/osc_ruby.gemspec CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["Rajan Davis"]
10
10
  spec.email = ["rajangdavis@gmail.com"]
11
11
  spec.summary = %q{Making the best of opensource and enterprise technology}
12
- spec.description = %q{An unofficial Ruby wrapper for the Oracle Cloud Services (fka RightNow Technologies) REST API}
12
+ spec.description = %q{An unofficial Ruby ORM on top of the Oracle Cloud Services (fka RightNow Technologies) REST API}
13
13
  spec.homepage = %q{https://github.com/rajangdavis/osc_ruby}
14
14
  spec.license = "MIT"
15
15
 
@@ -129,6 +129,92 @@ describe OSCRuby::Connect do
129
129
 
130
130
  end
131
131
 
132
+ let(:json_content){
133
+ {:test => 'content'}
134
+ }
135
+
136
+ context '#post_or_patch' do
137
+
138
+ it 'should take at least a config parameter that is an instance of an OSCRuby::Client' do
139
+
140
+ expect(client).to be_an(OSCRuby::Client)
141
+
142
+ expect do
143
+
144
+ OSCRuby::Connect.post_or_patch(client,'serviceProducts',json_content)
145
+
146
+ end.not_to raise_error
147
+ end
148
+
149
+ it 'should raise an error if client is nil' do
150
+
151
+ expect do
152
+
153
+ client = nil
154
+
155
+ OSCRuby::Connect.post_or_patch(client,'serviceProducts',json_content)
156
+
157
+ end.to raise_error("Client must have some configuration set; please create an instance of OSCRuby::Client with configuration settings")
158
+
159
+ end
160
+
161
+ it 'should raise an error if resource_url is nil' do
162
+
163
+ expect do
164
+
165
+ OSCRuby::Connect.post_or_patch(client, nil, json_content)
166
+
167
+ end.to raise_error("There is no URL resource provided; please specify a URL resource that you would like to send a POST or PATCH request to")
168
+
169
+ end
170
+
171
+ it 'should raise an error if json_content is nil' do
172
+
173
+ expect do
174
+
175
+ OSCRuby::Connect.post_or_patch(client,'serviceProducts')
176
+
177
+ end.to raise_error("There is no json content provided; please specify json content that you would like to send a POST or PATCH request with")
178
+
179
+ end
180
+
181
+ it 'should produce a Net::HTTPResponse, should produce a 201 response code, and should produce a JSON Response form the response body' do
182
+
183
+ names = []
184
+
185
+ names[0] = {:labelText => 'PRODUCT-TEST', :language => {:id => 1}}
186
+ names[1] = {:labelText => 'PRODUCT-TEST', :language => {:id => 11}}
187
+
188
+ parent = {:id => 102}
189
+
190
+ displayOrder = {:id => 4}
191
+
192
+ admin_user_visible_interfaces = []
193
+ admin_user_visible_interfaces[0] = {:id => 1}
194
+
195
+ end_user_visible_interfaces = []
196
+ end_user_visible_interfaces[0] = {:id => 1}
197
+
198
+ new_prod = []
199
+ new_prod[0] = {:names => names,
200
+ :parent => parent,
201
+ :adminVisibleInterfaces => admin_user_visible_interfaces,
202
+ :endUserVisibleInterfaces => end_user_visible_interfaces}
203
+
204
+ test = OSCRuby::Connect.post_or_patch(client,'serviceProducts',new_prod[0])
205
+
206
+ expect(test).to be_an(Net::HTTPResponse)
207
+
208
+ expect(test.code).to eq("201")
209
+
210
+ expect(test.body).to be_an(String)
211
+
212
+ expect{JSON.parse(test.body)}.not_to raise_error
213
+
214
+ end
215
+
216
+ end
217
+
132
218
  let(:test){
133
219
  OSCRuby::Connect.get(client)
134
220
  }
@@ -146,6 +232,7 @@ describe OSCRuby::Connect do
146
232
  end.not_to raise_error
147
233
  end
148
234
 
235
+
149
236
  it 'should raise an error if client is nil' do
150
237
 
151
238
  expect do
@@ -170,93 +257,112 @@ describe OSCRuby::Connect do
170
257
 
171
258
  end
172
259
 
173
- it 'should produce a JSON Response form the response body' do
260
+ it 'should produce a JSON Response from the response body' do
174
261
 
175
262
  expect(test.body).to be_an(String)
176
263
 
177
264
  expect{JSON.parse(test.body)}.not_to raise_error
178
265
  end
179
266
 
180
- let(:json_content){
181
- {:test => 'content'}
182
- }
267
+ end
268
+
269
+ let(:product_test_id){
270
+
271
+ resource = URI.escape("queryResults/?query=select id from serviceproducts where lookupname = 'PRODUCT-TEST';")
272
+
273
+ product_test = OSCRuby::Connect.get(client,resource)
274
+
275
+ prod_json = JSON.parse(product_test.body).to_hash
276
+
277
+ prod_json['items'][0]['rows'][0][0].to_i
278
+
279
+ }
280
+
281
+ context '#post_or_patch' do
282
+
283
+ it 'should take an optional parameter to allow PATCH request; it should produce a Net::HTTPResponse, should produce a 200 code' do
183
284
 
184
- context '#post' do
285
+ names = []
185
286
 
186
- it 'should take at least a config parameter that is an instance of an OSCRuby::Client' do
287
+ names[0] = {:labelText => 'PRODUCT-TEST-updated', :language => {:id => 1}}
288
+ names[1] = {:labelText => 'PRODUCT-TEST-updated', :language => {:id => 11}}
187
289
 
188
- expect(client).to be_an(OSCRuby::Client)
290
+ parent = {:id => 102}
189
291
 
190
- expect do
292
+ displayOrder = {:id => 4}
191
293
 
192
- OSCRuby::Connect.post(client,'serviceProducts',json_content)
294
+ admin_user_visible_interfaces = []
295
+ admin_user_visible_interfaces[0] = {:id => 1}
193
296
 
194
- end.not_to raise_error
195
- end
297
+ end_user_visible_interfaces = []
298
+ end_user_visible_interfaces[0] = {:id => 1}
196
299
 
197
- it 'should raise an error if client is nil' do
300
+ new_prod = []
301
+ new_prod[0] = {:names => names,
302
+ :parent => parent,
303
+ :adminVisibleInterfaces => admin_user_visible_interfaces,
304
+ :endUserVisibleInterfaces => end_user_visible_interfaces}
198
305
 
199
- expect do
200
-
201
- client = nil
306
+ test = OSCRuby::Connect.post_or_patch(client,"serviceProducts/#{product_test_id}",new_prod[0],true)
202
307
 
203
- OSCRuby::Connect.post(client,'serviceProducts',json_content)
308
+ expect(test).to be_an(Net::HTTPResponse)
204
309
 
205
- end.to raise_error("Client must have some configuration set; please create an instance of OSCRuby::Client with configuration settings")
310
+ expect(test.body).to eq("")
206
311
 
207
- end
312
+ expect(test.code).to eq("200")
313
+
314
+ end
208
315
 
209
- it 'should raise an error if resource_url is nil' do
316
+ end
210
317
 
211
- expect do
318
+ let(:product_test_updated_id){
212
319
 
213
- OSCRuby::Connect.post(client,'serviceProducts')
320
+ resource = URI.escape("queryResults/?query=select id from serviceproducts where lookupname = 'PRODUCT-TEST-updated';")
214
321
 
215
- end.to raise_error("There is no json content provided; please specify json content that you would like to send a POST request with")
322
+ product_test_updated = OSCRuby::Connect.get(client,resource)
216
323
 
217
- end
324
+ prod_json = JSON.parse(product_test_updated.body).to_hash
218
325
 
219
- it 'should produce a Net::HTTPResponse, should produce a 201 response code, and should produce a JSON Response form the response body' do
326
+ prod_json['items'][0]['rows'][0][0].to_i
220
327
 
221
- names = []
328
+ }
222
329
 
223
- names[0] = {:labelText => 'QTH45-test', :language => {:id => 1}}
224
- names[1] = {:labelText => 'QTH45-test', :language => {:id => 11}}
330
+ context '#delete' do
225
331
 
226
- parent = {:id => 102}
332
+ it 'should raise an error if client is nil' do
227
333
 
228
- displayOrder = {:id => 4}
334
+ expect do
335
+
336
+ client = nil
229
337
 
230
- admin_user_visible_interfaces = []
231
- admin_user_visible_interfaces[0] = {:id => 1}
338
+ OSCRuby::Connect.delete(client)
232
339
 
233
- end_user_visible_interfaces = []
234
- end_user_visible_interfaces[0] = {:id => 1}
340
+ end.to raise_error("Client must have some configuration set; please create an instance of OSCRuby::Client with configuration settings")
235
341
 
236
- new_prod = []
237
- new_prod[0] = {:names => names,
238
- :parent => parent,
239
- :adminVisibleInterfaces => admin_user_visible_interfaces,
240
- :endUserVisibleInterfaces => end_user_visible_interfaces}
342
+ end
241
343
 
242
- test = OSCRuby::Connect.post(client,'serviceProducts',new_prod[0])
344
+ it 'should raise an error if the resource_url is not specified' do
243
345
 
244
- expect(test).to be_an(Net::HTTPResponse)
346
+ expect do
347
+
348
+ OSCRuby::Connect.delete(client)
349
+
350
+ end.to raise_error("There is no URL resource provided; please specify a URL resource that you would like to send a POST or PATCH request to")
245
351
 
246
- expect(test.code).to eq("201")
352
+ end
353
+
354
+ it 'it should produce a Net::HTTPResponse, should produce a 200 code' do
247
355
 
248
- expect(test.body).to be_an(String)
356
+ test = OSCRuby::Connect.delete(client,"serviceProducts/#{product_test_updated_id}")
249
357
 
250
- expect{JSON.parse(test.body)}.not_to raise_error
251
-
252
- end
358
+ expect(test).to be_an(Net::HTTPResponse)
253
359
 
360
+ expect(test.body).to eq("")
361
+
362
+ expect(test.code).to eq("200")
363
+
254
364
  end
255
365
 
256
366
  end
257
367
 
258
- # context '#patch'
259
-
260
-
261
- # end
262
368
  end
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.0.14
4
+ version: 0.1.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: 2016-12-22 00:00:00.000000000 Z
11
+ date: 2016-12-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,7 +52,7 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: 3.2.0
55
- description: An unofficial Ruby wrapper for the Oracle Cloud Services (fka RightNow
55
+ description: An unofficial Ruby ORM on top of the Oracle Cloud Services (fka RightNow
56
56
  Technologies) REST API
57
57
  email:
58
58
  - rajangdavis@gmail.com