osvc_ruby 1.5.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 +7 -0
- data/.codeclimate.yml +22 -0
- data/.gitignore +14 -0
- data/.rspec +2 -0
- data/.rubocop.yml +1156 -0
- data/.travis.yml +15 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +61 -0
- data/License.txt +21 -0
- data/README.md +633 -0
- data/Rakefile +4 -0
- data/lib/convenience_methods.rb +28 -0
- data/lib/ext/string.rb +19 -0
- data/lib/osvc_ruby/classes/analytics_report_results.rb +66 -0
- data/lib/osvc_ruby/classes/query_results.rb +41 -0
- data/lib/osvc_ruby/classes/query_results_set.rb +39 -0
- data/lib/osvc_ruby/client.rb +41 -0
- data/lib/osvc_ruby/configuration.rb +15 -0
- data/lib/osvc_ruby/connect.rb +226 -0
- data/lib/osvc_ruby/modules/normalize_module.rb +62 -0
- data/lib/osvc_ruby/modules/validations_module.rb +34 -0
- data/lib/osvc_ruby/version.rb +3 -0
- data/lib/osvc_ruby.rb +9 -0
- data/osvc_ruby.gemspec +28 -0
- data/spec/core/analytics_report_results_spec.rb +86 -0
- data/spec/core/client_spec.rb +97 -0
- data/spec/core/configuration_spec.rb +5 -0
- data/spec/core/connect_spec.rb +463 -0
- data/spec/core/query_results_set_spec.rb +107 -0
- data/spec/core/query_results_spec.rb +77 -0
- data/spec/core/spec_helper.rb +26 -0
- data/tasks/rspec.rake +3 -0
- metadata +199 -0
data/README.md
ADDED
@@ -0,0 +1,633 @@
|
|
1
|
+
# OSvCRuby
|
2
|
+
|
3
|
+
[](https://codeclimate.com/github/rajangdavis/osvc_ruby) [](https://codeclimate.com/github/rajangdavis/osvc_ruby/test_coverage) [](https://travis-ci.org/rajangdavis/osvc_ruby) [](https://badge.fury.io/rb/osvc_ruby) [](https://snyk.io/test/github/rajangdavis/osvc_ruby)
|
4
|
+
|
5
|
+
An (under development) Ruby library for using the [Oracle Service Cloud REST API](https://docs.oracle.com/cloud/latest/servicecs_gs/CXSVC/) influenced by the [ConnectPHP API](http://documentation.custhelp.com/euf/assets/devdocs/november2016/Connect_PHP/Default.htm) and ActiveRecord Gem
|
6
|
+
|
7
|
+
## Installing Ruby (for Windows)
|
8
|
+
[Try this link.](https://rubyinstaller.org/downloads/). I would highly recommend installing any version before 2.4 for Windows.
|
9
|
+
|
10
|
+
You will also need to install DevKit Tools which are located underneath the Ruby section
|
11
|
+
|
12
|
+
If you are using Windows 10, you can use your Linux Subsystem to work with Ruby; [here's instructions for how to do that.](https://www.digitalocean.com/community/tutorials/how-to-install-ruby-and-set-up-a-local-programming-environment-on-windows-10)
|
13
|
+
|
14
|
+
If you get SSL Errors (you probably will), follow [this link for instructions on resolving SSL things that I know nothing about](https://stackoverflow.com/a/16134586/2548452).
|
15
|
+
|
16
|
+
## Compatibility
|
17
|
+
|
18
|
+
This gem was tested against Oracle Service Cloud November 2016 using Ruby version 2.1.2p95 (2014-05-08 revision 45877) [x86_64-darwin13.0] between December 2016 and June 2017.
|
19
|
+
|
20
|
+
It is now being tested against Oracle Service Cloud May 2017 using Ruby version 2.5.0p0 (2017-12-25 revision 61468) [i386-mingw32] using [TravisCI](https://travis-ci.org/rajangdavis/osvc_ruby) for continuous integration.
|
21
|
+
|
22
|
+
All of the HTTP methods should work on any version of Oracle Service Cloud since version May 2015; however, there maybe some issues with querying items on any version before May 2016. This is because ROQL queries were not exposed via the REST API until May 2016.
|
23
|
+
|
24
|
+
|
25
|
+
## Use Cases
|
26
|
+
You can use this Ruby Library for basic scripting and microservices. The main features that work to date are as follows:
|
27
|
+
|
28
|
+
1. [Simple configuration](#client-configuration)
|
29
|
+
2. Running ROQL queries [either 1 at a time](#oscrubyqueryresults-example) or [multiple queries in a set](#oscrubyqueryresultsset-example)
|
30
|
+
3. [Running Reports with filters](#oscrubyanalyticsreportsresults)
|
31
|
+
4. Convenience methods for Analytics filters and setting dates
|
32
|
+
1. ['arrf', an analytics report results filter](#arrf--analytics-report-results-filter)
|
33
|
+
2. ['dti', converts a date string to ISO8601 format](#dti--date-to-iso8601)
|
34
|
+
5. Basic CRUD Operations via HTTP Methods
|
35
|
+
1. [Create => Post](#create)
|
36
|
+
2. [Read => Get](#read)
|
37
|
+
3. [Update => Patch](#update)
|
38
|
+
4. [Destroy => Delete](#delete)
|
39
|
+
|
40
|
+
|
41
|
+
## Installation
|
42
|
+
|
43
|
+
Add this line to your application's Gemfile:
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
gem 'osvc_ruby'
|
47
|
+
```
|
48
|
+
|
49
|
+
And then execute:
|
50
|
+
|
51
|
+
$ bundle
|
52
|
+
|
53
|
+
Or install it yourself as:
|
54
|
+
|
55
|
+
$ gem install osvc_ruby
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
|
62
|
+
## Client Configuration
|
63
|
+
|
64
|
+
An OSvCRuby::Client object lets the library know which credentials and interface to use for interacting with the Oracle Service Cloud REST API.
|
65
|
+
This is helpful if you need to interact with multiple interfaces or set different headers for different objects.
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
|
69
|
+
# Configuration is as simple as requiring the gem
|
70
|
+
# and writing a Ruby block
|
71
|
+
|
72
|
+
require 'osvc_ruby'
|
73
|
+
|
74
|
+
rn_client = OSvCRuby::Client.new do |c|
|
75
|
+
c.username = ENV['OSC_ADMIN'] # => These are interface credentials
|
76
|
+
c.password = ENV['OSC_PASSWORD'] # => store these in environmental
|
77
|
+
c.interface = ENV['OSC_SITE'] # => variables in your .bash_profile
|
78
|
+
|
79
|
+
### optional configuration
|
80
|
+
# Turns off SSL verification; don't use in production
|
81
|
+
c.no_ssl_verify = true # => Defaults to false.
|
82
|
+
|
83
|
+
# Sets the version of the REST API to use
|
84
|
+
c.version = 'v1.4' # => Defaults to 'v1.3'.
|
85
|
+
|
86
|
+
# Let's you supress business rules
|
87
|
+
c.suppress_rules = true # => Defaults to false.
|
88
|
+
|
89
|
+
# Use 'rightnowdemo' namespace instead of 'custhelp'
|
90
|
+
c.demo_site = true # => Defaults to false.
|
91
|
+
|
92
|
+
end
|
93
|
+
```
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
## OSvCRuby::QueryResults example
|
100
|
+
|
101
|
+
This is for running one ROQL query. Whatever is allowed by the REST API (limits and sorting) is allowed with this library.
|
102
|
+
|
103
|
+
OSvCRuby::QueryResults only has one function: 'query', which takes an OSvCRuby::Client object and string query (example below).
|
104
|
+
|
105
|
+
```ruby
|
106
|
+
# NOTE: Make sure to put your queries WRAPPED in doublequotes("")
|
107
|
+
# this is because when Ruby converts the queries into a URI
|
108
|
+
# the REST API does not like it when the queries are WRAPPED in single quotes ('')
|
109
|
+
|
110
|
+
# For example
|
111
|
+
# "parent is null and lookupName!='Unsure'" => great!
|
112
|
+
# 'parent is null and lookupName!="Unsure"' => don't do this
|
113
|
+
# it will spit back an error from the REST API!
|
114
|
+
|
115
|
+
require 'osvc_ruby'
|
116
|
+
|
117
|
+
rn_client = OSvCRuby::Client.new do |c|
|
118
|
+
c.username = ENV['OSC_ADMIN']
|
119
|
+
c.password = ENV['OSC_PASSWORD']
|
120
|
+
c.interface = ENV['OSC_SITE']
|
121
|
+
end
|
122
|
+
|
123
|
+
q = OSvCRuby::QueryResults.new
|
124
|
+
|
125
|
+
query = "select * from answers where ID = 1557"
|
126
|
+
|
127
|
+
results = q.query(rn_client,query) # => will return an array of results
|
128
|
+
|
129
|
+
puts results[0] # => "{'id':1557,'name':...}"
|
130
|
+
|
131
|
+
```
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
## OSvCRuby::QueryResultsSet example
|
144
|
+
|
145
|
+
This is for running multiple queries and assigning the results of each query to a key for further manipulation.
|
146
|
+
|
147
|
+
OSvCRuby::QueryResultsSet only has one function: 'query_set', which takes an OSvCRuby::Client object and multiple query hashes (example below).
|
148
|
+
|
149
|
+
```ruby
|
150
|
+
# NOTE: Make sure to put your queries WRAPPED in doublequotes("")
|
151
|
+
# Pass in each query into a hash
|
152
|
+
# set query: to the query you want to execute
|
153
|
+
# set key: to the value you want the results to of the query to be referenced to
|
154
|
+
|
155
|
+
require 'osvc_ruby'
|
156
|
+
|
157
|
+
rn_client = OSvCRuby::Client.new do |c|
|
158
|
+
c.username = ENV['OSC_ADMIN']
|
159
|
+
c.password = ENV['OSC_PASSWORD']
|
160
|
+
c.interface = ENV['OSC_SITE']
|
161
|
+
end
|
162
|
+
|
163
|
+
mq = OSvCRuby::QueryResultsSet.new
|
164
|
+
r = mq.query_set(rn_client,
|
165
|
+
{query:"DESCRIBE ANSWERS", key: "answerSchema"},
|
166
|
+
{query:"SELECT * FROM ANSWERS LIMIT 1", key: "answers"},
|
167
|
+
{query:"DESCRIBE SERVICECATEGORIES", key: "categoriesSchema"},
|
168
|
+
{query:"SELECT * FROM SERVICECATEGORIES", key:"categories"},
|
169
|
+
{query:"DESCRIBE SERVICEPRODUCTS", key: "productsSchema"},
|
170
|
+
{query:"SELECT * FROM SERVICEPRODUCTS", key:"products"})
|
171
|
+
|
172
|
+
puts JSON.pretty_generate(r.answerSchema)
|
173
|
+
|
174
|
+
# Results for "DESCRIBE ANSWERS"
|
175
|
+
#
|
176
|
+
# [
|
177
|
+
# {
|
178
|
+
# "Name": "id",
|
179
|
+
# "Type": "Integer",
|
180
|
+
# "Path": ""
|
181
|
+
# },
|
182
|
+
# {
|
183
|
+
# "Name": "lookupName",
|
184
|
+
# "Type": "String",
|
185
|
+
# "Path": ""
|
186
|
+
# },
|
187
|
+
# {
|
188
|
+
# "Name": "createdTime",
|
189
|
+
# "Type": "String",
|
190
|
+
# "Path": ""
|
191
|
+
# }
|
192
|
+
# ... everything else including customfields and objects...
|
193
|
+
#]
|
194
|
+
|
195
|
+
puts JSON.pretty_generate(r.answers)
|
196
|
+
|
197
|
+
# Results for "SELECT * FROM ANSWERS LIMIT 1"
|
198
|
+
#
|
199
|
+
# [
|
200
|
+
# {
|
201
|
+
# "id": 1,
|
202
|
+
# "lookupName": 1,
|
203
|
+
# "createdTime": "2016-03-04T18:25:50Z",
|
204
|
+
# "updatedTime": "2016-09-12T17:12:14Z",
|
205
|
+
# "accessLevels": 1,
|
206
|
+
# "adminLastAccessTime": "2016-03-04T18:25:50Z",
|
207
|
+
# "answerType": 1,
|
208
|
+
# "expiresDate": null,
|
209
|
+
# "guidedAssistance": null,
|
210
|
+
# "keywords": null,
|
211
|
+
# "language": 1,
|
212
|
+
# "lastAccessTime": "2016-03-04T18:25:50Z",
|
213
|
+
# "lastNotificationTime": null,
|
214
|
+
# "name": 1,
|
215
|
+
# "nextNotificationTime": null,
|
216
|
+
# "originalReferenceNumber": null,
|
217
|
+
# "positionInList": 1,
|
218
|
+
# "publishOnDate": null,
|
219
|
+
# "question": null,
|
220
|
+
# "solution": "<HTML SOLUTION WITH INLINE CSS>",
|
221
|
+
# "summary": "SPRING IS ALMOST HERE!",
|
222
|
+
# "updatedByAccount": 16,
|
223
|
+
# "uRL": null
|
224
|
+
# }
|
225
|
+
#]
|
226
|
+
|
227
|
+
puts JSON.pretty_generate(r.categoriesSchema)
|
228
|
+
|
229
|
+
# Results for "DESCRIBE SERVICECATEGORIES"
|
230
|
+
#
|
231
|
+
#[
|
232
|
+
#... skipping the first few ...
|
233
|
+
# {
|
234
|
+
# "Name": "adminVisibleInterfaces",
|
235
|
+
# "Type": "SubTable",
|
236
|
+
# "Path": "serviceCategories.adminVisibleInterfaces"
|
237
|
+
# },
|
238
|
+
# {
|
239
|
+
# "Name": "descriptions",
|
240
|
+
# "Type": "SubTable",
|
241
|
+
# "Path": "serviceCategories.descriptions"
|
242
|
+
# },
|
243
|
+
# {
|
244
|
+
# "Name": "displayOrder",
|
245
|
+
# "Type": "Integer",
|
246
|
+
# "Path": ""
|
247
|
+
# },
|
248
|
+
# {
|
249
|
+
# "Name": "endUserVisibleInterfaces",
|
250
|
+
# "Type": "SubTable",
|
251
|
+
# "Path": "serviceCategories.endUserVisibleInterfaces"
|
252
|
+
# },
|
253
|
+
# ... everything else include parents and children ...
|
254
|
+
#]
|
255
|
+
|
256
|
+
puts JSON.pretty_generate(r.categories)
|
257
|
+
|
258
|
+
# Results for "SELECT * FROM SERVICECATEGORIES"
|
259
|
+
#
|
260
|
+
# [
|
261
|
+
# {
|
262
|
+
# "id": 3,
|
263
|
+
# "lookupName": "Manuals",
|
264
|
+
# "createdTime": null,
|
265
|
+
# "updatedTime": null,
|
266
|
+
# "displayOrder": 3,
|
267
|
+
# "name": "Manuals",
|
268
|
+
# "parent": 60
|
269
|
+
# },
|
270
|
+
# {
|
271
|
+
# "id": 4,
|
272
|
+
# "lookupName": "Installations",
|
273
|
+
# "createdTime": null,
|
274
|
+
# "updatedTime": null,
|
275
|
+
# "displayOrder": 4,
|
276
|
+
# "name": "Installations",
|
277
|
+
# "parent": 60
|
278
|
+
# },
|
279
|
+
# {
|
280
|
+
# "id": 5,
|
281
|
+
# "lookupName": "Downloads",
|
282
|
+
# "createdTime": null,
|
283
|
+
# "updatedTime": null,
|
284
|
+
# "displayOrder": 2,
|
285
|
+
# "name": "Downloads",
|
286
|
+
# "parent": 60
|
287
|
+
# },
|
288
|
+
# ... you should get the idea by now ...
|
289
|
+
#]
|
290
|
+
|
291
|
+
### Both of these are similar to the above
|
292
|
+
puts JSON.pretty_generate(r.productsSchema) # => Results for "DESCRIBE SERVICEPRODUCTS"
|
293
|
+
puts JSON.pretty_generate(r.products) # => Results for "SELECT * FROM SERVICEPRODUCTS"
|
294
|
+
|
295
|
+
```
|
296
|
+
|
297
|
+
|
298
|
+
|
299
|
+
|
300
|
+
|
301
|
+
|
302
|
+
|
303
|
+
## OSvCRuby::AnalyticsReportsResults
|
304
|
+
|
305
|
+
You can create a new instance either by the report 'id' or 'lookupName'.
|
306
|
+
|
307
|
+
OSvCRuby::AnalyticsReportsResults only has one function: 'run', which takes an OSvCRuby::Client object.
|
308
|
+
|
309
|
+
OSvCRuby::AnalyticsReportsResults have the following properties: 'id', 'lookupName', and 'filters'. More on filters and supported datetime methods are below this OSvCRuby::AnalyticsReportsResults example script.
|
310
|
+
|
311
|
+
```ruby
|
312
|
+
require 'osvc_ruby'
|
313
|
+
|
314
|
+
rn_client = OSvCRuby::Client.new do |c|
|
315
|
+
c.username = ENV['OSC_ADMIN']
|
316
|
+
c.password = ENV['OSC_PASSWORD']
|
317
|
+
c.interface = ENV['OSC_SITE']
|
318
|
+
end
|
319
|
+
|
320
|
+
last_updated = OSvCRuby::AnalyticsReportResults.new(lookupName: "Last Updated By Status")
|
321
|
+
|
322
|
+
puts last_updated.run(rn_client)
|
323
|
+
|
324
|
+
#{"Status"=>"Unresolved", "Incidents"=>704, "Average Time Since Last Response"=>"39029690.149123"}
|
325
|
+
#{"Status"=>"Updated", "Incidents"=>461, "Average Time Since Last Response"=>"39267070.331683"}
|
326
|
+
|
327
|
+
```
|
328
|
+
|
329
|
+
|
330
|
+
|
331
|
+
|
332
|
+
|
333
|
+
|
334
|
+
|
335
|
+
|
336
|
+
|
337
|
+
|
338
|
+
## Convenience Methods
|
339
|
+
|
340
|
+
### 'arrf' => analytics report results filter
|
341
|
+
|
342
|
+
'arrf' lets you set filters for an OSvCRuby::AnalyticsReportsResults Object.
|
343
|
+
|
344
|
+
You can set the following keys:
|
345
|
+
1. name => The filter name
|
346
|
+
2. prompt => The prompt for this filter
|
347
|
+
|
348
|
+
These are under development, but these should work if you treat them like the the data-type they are as mentioned in the REST API:
|
349
|
+
|
350
|
+
3. [attributes](https://docs.oracle.com/cloud/latest/servicecs_gs/CXSVC/op-services-rest-connect-v1.4-analyticsReportResults-post.html#request-definitions-namedIDs-analyticsReports-filters-attributes)
|
351
|
+
4. [dataType](https://docs.oracle.com/cloud/latest/servicecs_gs/CXSVC/op-services-rest-connect-v1.4-analyticsReportResults-post.html#request-definitions-namedIDs-analyticsReports-filters-dataType)
|
352
|
+
5. [operator](https://docs.oracle.com/cloud/latest/servicecs_gs/CXSVC/op-services-rest-connect-v1.4-analyticsReportResults-post.html#request-definitions-namedIDs-analyticsReports-filters-operator)
|
353
|
+
6. [values](https://docs.oracle.com/cloud/latest/servicecs_gs/CXSVC/op-services-rest-connect-v1.4-analyticsReportResults-post.html#request-namedIDs-definitions-analyticsReports-filters-values)
|
354
|
+
|
355
|
+
```ruby
|
356
|
+
require 'osvc_ruby'
|
357
|
+
|
358
|
+
rn_client = OSvCRuby::Client.new do |c|
|
359
|
+
c.username = ENV['OSC_ADMIN']
|
360
|
+
c.password = ENV['OSC_PASSWORD']
|
361
|
+
c.interface = ENV['OSC_SITE']
|
362
|
+
end
|
363
|
+
|
364
|
+
answers_search = OSvCRuby::AnalyticsReportResults.new(id: 176)
|
365
|
+
|
366
|
+
keywords = arrf(name: "search_ex", values: "Maestro")
|
367
|
+
answers_search.filters << keywords
|
368
|
+
|
369
|
+
# To add more filters, create another
|
370
|
+
# "arrf" filter structure
|
371
|
+
# and "shovel" it into
|
372
|
+
# the OSvCRuby::AnalyticsReportResults
|
373
|
+
# "filters" property
|
374
|
+
#
|
375
|
+
# date_created = arrf(name: "date_created", values: dti("August 7th, 2017"))
|
376
|
+
# answers_search.filters << date_created
|
377
|
+
|
378
|
+
|
379
|
+
answers = answers_search.run(rn_client)
|
380
|
+
|
381
|
+
answers.each do |answer|
|
382
|
+
puts answer['Summary']
|
383
|
+
end
|
384
|
+
|
385
|
+
# =>
|
386
|
+
|
387
|
+
# How do I get started with the Maestro Smart Thermostat App?
|
388
|
+
|
389
|
+
# Is my Wi-Fi router compatible with the Maestro Smart Thermostat?
|
390
|
+
|
391
|
+
# Will the Maestro Smart Thermostat work with my HVAC system?
|
392
|
+
|
393
|
+
# Maestro Smart Thermostat App
|
394
|
+
|
395
|
+
# Maestro Smart Thermostat Installation Guide
|
396
|
+
|
397
|
+
# Maestro Product Warranty
|
398
|
+
|
399
|
+
# ... and so on and so forth
|
400
|
+
```
|
401
|
+
|
402
|
+
|
403
|
+
|
404
|
+
|
405
|
+
|
406
|
+
|
407
|
+
|
408
|
+
### 'dti' => date to iso8601
|
409
|
+
|
410
|
+
dti lets you type in a date and get it in ISO8601 format. Explicit date formatting is best.
|
411
|
+
|
412
|
+
```ruby
|
413
|
+
|
414
|
+
dti("January 1st, 2014") # => 2014-01-01T00:00:00-08:00 # => 1200 AM, January First of 2014
|
415
|
+
|
416
|
+
dti("January 1st, 2014 11:59PM MDT") # => 2014-01-01T23:59:00-06:00 # => 11:59 PM Mountain Time, January First of 2014
|
417
|
+
|
418
|
+
dti("January 1st, 2014 23:59 PDT") # => 2014-01-01T23:59:00-07:00 # => 11:59 PM Pacific Time, January First of 2014
|
419
|
+
|
420
|
+
dti("January 1st") # => 2017-01-01T00:00:00-08:00 # => 12:00 AM, January First of this Year
|
421
|
+
|
422
|
+
```
|
423
|
+
|
424
|
+
|
425
|
+
Be careful! Sometimes the dates will not be what you expect; try to write dates as explicitly/predictably when possible.
|
426
|
+
|
427
|
+
|
428
|
+
```ruby
|
429
|
+
|
430
|
+
# EXAMPLES OF DATES NOT BEING WHAT YOU MIGHT EXPECT
|
431
|
+
|
432
|
+
#Full dates should be formatted as
|
433
|
+
# %d/%m/%y %h:%m tt
|
434
|
+
|
435
|
+
dti("01/02/14") # => 2001-02-14T00:00:00-08:00 # => 12:00 AM, February 14th, 2001
|
436
|
+
|
437
|
+
dti("01/02/2014") # => 2014-02-01T00:00:00-08:00 # => 12:00 AM, February 14th, 2014
|
438
|
+
|
439
|
+
dti("11:59PM January 1st, 2014 GMT") #=> 2017-08-01T23:59:00-07:00 #=> 11:59 PM, August 1st, 2017 Pacific Time (?)
|
440
|
+
|
441
|
+
```
|
442
|
+
|
443
|
+
|
444
|
+
|
445
|
+
|
446
|
+
|
447
|
+
|
448
|
+
|
449
|
+
|
450
|
+
|
451
|
+
## Basic CRUD operations
|
452
|
+
|
453
|
+
### CREATE
|
454
|
+
```ruby
|
455
|
+
#### OSvCRuby::Connect.post( <client>, <url>, <json_data> )
|
456
|
+
#### returns a NetHTTPRequest object
|
457
|
+
|
458
|
+
# Here's how you could create a new ServiceProduct object
|
459
|
+
# using Ruby variables, hashes(sort of like JSON), and arrays to set field information
|
460
|
+
|
461
|
+
require 'osvc_ruby'
|
462
|
+
|
463
|
+
rn_client = OSvCRuby::Client.new do |c|
|
464
|
+
c.username = ENV['OSC_ADMIN']
|
465
|
+
c.password = ENV['OSC_PASSWORD']
|
466
|
+
c.interface = ENV['OSC_SITE']
|
467
|
+
end
|
468
|
+
|
469
|
+
new_product = {}
|
470
|
+
new_product['names'] = []
|
471
|
+
new_product['names'][0] = {'labelText' => 'NEW_PRODUCT', 'language' => {'id' => 1}}
|
472
|
+
new_product['displayOrder'] = 4
|
473
|
+
|
474
|
+
new_product['adminVisibleInterfaces'] = []
|
475
|
+
new_product['adminVisibleInterfaces'][0] = {'id' => 1}
|
476
|
+
new_product['endUserVisibleInterfaces'] = []
|
477
|
+
new_product['endUserVisibleInterfaces'][0] = {'id' => 1}
|
478
|
+
|
479
|
+
res = OSvCRuby::Connect.post(rn_client,'/serviceProducts',new_product)
|
480
|
+
|
481
|
+
puts res.code # => 201
|
482
|
+
|
483
|
+
puts res.body # => JSON body
|
484
|
+
|
485
|
+
# callback with JSON details
|
486
|
+
|
487
|
+
```
|
488
|
+
|
489
|
+
|
490
|
+
|
491
|
+
|
492
|
+
|
493
|
+
|
494
|
+
|
495
|
+
### READ
|
496
|
+
```ruby
|
497
|
+
#### OSvCRuby::Connect.get( <client>, optional (<url>/<id>/...<params>) )
|
498
|
+
#### returns a NetHTTPRequest object
|
499
|
+
# Here's how you could get a list of ServiceProducts
|
500
|
+
|
501
|
+
require 'osvc_ruby'
|
502
|
+
|
503
|
+
rn_client = OSvCRuby::Client.new do |c|
|
504
|
+
c.username = ENV['OSC_ADMIN']
|
505
|
+
c.password = ENV['OSC_PASSWORD']
|
506
|
+
c.interface = ENV['OSC_SITE']
|
507
|
+
end
|
508
|
+
|
509
|
+
res = OSvCRuby::Connect.get(rn_client,'/serviceProducts?limit=3')
|
510
|
+
|
511
|
+
puts JSON.pretty_generate(res.body)
|
512
|
+
|
513
|
+
#{
|
514
|
+
# "items": [
|
515
|
+
# {
|
516
|
+
# "id": 2,
|
517
|
+
# "lookupName": "Maestro Smart Thermostat",
|
518
|
+
# "links": [
|
519
|
+
# {
|
520
|
+
# "rel": "canonical",
|
521
|
+
# "href": "https://<OSC_SITE>.rightnowdemo.com/services/rest/connect/v1.3/serviceProducts/2"
|
522
|
+
# }
|
523
|
+
# ]
|
524
|
+
# },
|
525
|
+
# {
|
526
|
+
# "id": 6,
|
527
|
+
# "lookupName": "Home Security",
|
528
|
+
# "links": [
|
529
|
+
# {
|
530
|
+
# "rel": "canonical",
|
531
|
+
# "href": "https://<OSC_SITE>.rightnowdemo.com/services/rest/connect/v1.3/serviceProducts/6"
|
532
|
+
# }
|
533
|
+
# ]
|
534
|
+
# },
|
535
|
+
# {
|
536
|
+
# "id": 7,
|
537
|
+
# "lookupName": "Hubs",
|
538
|
+
# "links": [
|
539
|
+
# {
|
540
|
+
# "rel": "canonical",
|
541
|
+
# "href": "https://<OSC_SITE>.rightnowdemo.com/services/rest/connect/v1.3/serviceProducts/7"
|
542
|
+
# }
|
543
|
+
# ]
|
544
|
+
# }
|
545
|
+
# ],
|
546
|
+
# "hasMore": true,
|
547
|
+
#
|
548
|
+
# ... and everything else ...
|
549
|
+
#
|
550
|
+
#}
|
551
|
+
```
|
552
|
+
|
553
|
+
|
554
|
+
|
555
|
+
|
556
|
+
|
557
|
+
|
558
|
+
### UPDATE
|
559
|
+
```ruby
|
560
|
+
#### OSvCRuby::Connect.patch( <client>, <url>, <json_data> )
|
561
|
+
#### returns a NetHTTPRequest object
|
562
|
+
# Here's how you could update the previously created ServiceProduct object
|
563
|
+
# using Ruby variables, arrays, hashes,
|
564
|
+
# and symbols (read only string values, eg :example)
|
565
|
+
# to set field information
|
566
|
+
|
567
|
+
require 'osvc_ruby'
|
568
|
+
|
569
|
+
rn_client = OSvCRuby::Client.new do |c|
|
570
|
+
c.username = ENV['OSC_ADMIN']
|
571
|
+
c.password = ENV['OSC_PASSWORD']
|
572
|
+
c.interface = ENV['OSC_SITE']
|
573
|
+
end
|
574
|
+
|
575
|
+
|
576
|
+
names = []
|
577
|
+
|
578
|
+
names[0] = {:labelText => 'PRODUCT-TEST-updated', :language => {:id => 1}}
|
579
|
+
displayOrder = {:id => 4}
|
580
|
+
|
581
|
+
admin_user_visible_interfaces = []
|
582
|
+
admin_user_visible_interfaces[0] = {:id => 1}
|
583
|
+
|
584
|
+
end_user_visible_interfaces = []
|
585
|
+
end_user_visible_interfaces[0] = {:id => 1}
|
586
|
+
|
587
|
+
prod_info_to_change = []
|
588
|
+
prod_info_to_change[0] = {:names => names,
|
589
|
+
:adminVisibleInterfaces => admin_user_visible_interfaces,
|
590
|
+
:endUserVisibleInterfaces => end_user_visible_interfaces}
|
591
|
+
|
592
|
+
updated_product = OSvCRuby::Connect.patch(rn_client,"serviceProducts/56",prod_info_to_change[0])
|
593
|
+
|
594
|
+
puts updated_product.code # => "200"
|
595
|
+
|
596
|
+
puts updated_product.body # => "" if successful...
|
597
|
+
|
598
|
+
```
|
599
|
+
|
600
|
+
|
601
|
+
|
602
|
+
|
603
|
+
|
604
|
+
|
605
|
+
### DELETE
|
606
|
+
```ruby
|
607
|
+
#### OSvCRuby::Connect.delete( <client>, <url> )
|
608
|
+
#### returns a NetHTTPRequest object
|
609
|
+
# Here's how you could delete the previously updated ServiceProduct object
|
610
|
+
# using the OSvCRuby::QueryResults
|
611
|
+
# and OSvCRuby::Connect classes
|
612
|
+
|
613
|
+
require 'osvc_ruby'
|
614
|
+
|
615
|
+
rn_client = OSvCRuby::Client.new do |c|
|
616
|
+
c.username = ENV['OSC_ADMIN']
|
617
|
+
c.password = ENV['OSC_PASSWORD']
|
618
|
+
c.interface = ENV['OSC_SITE']
|
619
|
+
end
|
620
|
+
|
621
|
+
q = OSvCRuby::QueryResults.new
|
622
|
+
query = "select id from serviceproducts where lookupname = 'PRODUCT-TEST-updated';"
|
623
|
+
|
624
|
+
product_test_updated = q.query(rn_client,resource) # => returns array of results
|
625
|
+
|
626
|
+
test = OSvCRuby::Connect.delete(rn_client,"serviceProducts/#{product_test_updated[0]['id']}")
|
627
|
+
|
628
|
+
puts updated_product.code # => "200"
|
629
|
+
|
630
|
+
puts updated_product.body # => "" if successful...
|
631
|
+
|
632
|
+
|
633
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'time'
|
2
|
+
|
3
|
+
# Add this in eventually...
|
4
|
+
$time_zone = ''
|
5
|
+
|
6
|
+
def dti(date)
|
7
|
+
begin
|
8
|
+
Time.parse(date +' '+$time_zone).iso8601
|
9
|
+
rescue => e
|
10
|
+
e.message
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def arrf(**args)
|
15
|
+
filter_attrs = [:attributes,:dataType,:name,:operator,:prompt,:values]
|
16
|
+
filter_hash = {}
|
17
|
+
|
18
|
+
filter_attrs.each do |attr|
|
19
|
+
|
20
|
+
filter_hash[attr] = args[attr] unless args[attr].nil?
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
filter_hash
|
25
|
+
end
|
26
|
+
|
27
|
+
# alias_method :dti, :date_to_iso
|
28
|
+
# alias_method :arrf, :array_report_results_filter
|
data/lib/ext/string.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
class String
|
2
|
+
def is_i?
|
3
|
+
/\A[-+]?\d+\z/ === self
|
4
|
+
end
|
5
|
+
|
6
|
+
def camel_case_lower
|
7
|
+
@class_to_array = self.split('')
|
8
|
+
@class_name_length = @class_to_array.length - 1
|
9
|
+
@output = @class_to_array.each_with_index do |letter,i|
|
10
|
+
if i ==0
|
11
|
+
letter.downcase!
|
12
|
+
elsif i == @class_name_length
|
13
|
+
letter.gsub!(/y/,'ie')
|
14
|
+
end
|
15
|
+
end.join
|
16
|
+
|
17
|
+
@output + 's'
|
18
|
+
end
|
19
|
+
end
|