osc_ruby 1.2.1 → 1.2.2

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