osc_ruby 0.1.13 → 0.2.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 +4 -4
- data/.gitignore +1 -0
- data/Gemfile +1 -7
- data/README.md +117 -108
- data/lib/osc_ruby.rb +2 -1
- data/lib/osc_ruby/answer.rb +169 -0
- data/lib/osc_ruby/class_factory_module.rb +163 -0
- data/lib/osc_ruby/client.rb +10 -1
- data/lib/osc_ruby/configuration.rb +3 -1
- data/lib/osc_ruby/connect.rb +15 -7
- data/lib/osc_ruby/query_module.rb +45 -38
- data/lib/osc_ruby/service_product.rb +41 -213
- data/lib/osc_ruby/validations_module.rb +94 -0
- data/lib/osc_ruby/version.rb +1 -1
- data/osc_ruby.gemspec +22 -16
- data/spec/core/answer_spec.rb +496 -0
- data/spec/core/client_spec.rb +49 -10
- data/spec/core/connect_spec.rb +28 -33
- data/spec/core/service_product_spec.rb +77 -69
- data/spec/core/spec_helper.rb +24 -1
- metadata +81 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0262af3d710018528271b39304094ca53663c9e2
|
4
|
+
data.tar.gz: 1c7000c6df53b2bc4dfa45a6e65ff0356f182246
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab15d881832e339d67857eec0129bb5416b79f8822c8f5d7fad3b0b4998db89d300da41337cbf311b0432edd23949ea8caa46b90cacf2e013e96b89e419ef77c
|
7
|
+
data.tar.gz: be2146f1137e001348c636dab826f08c8a3d4963e0da2392a52e993394ae8958085dc6d20ed3be68f9f5968428d6c017a1f5319ecee02d9b0e3e6b24a0b976dc
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -4,131 +4,166 @@
|
|
4
4
|
|
5
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
|
6
6
|
|
7
|
-
|
7
|
+
|
8
|
+
## Compatibility
|
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 as well as jruby version 1.7.19
|
12
|
+
|
13
|
+
The create, update, and destroy 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 November 2016. This is because I am using the ROQL queries to generate values for Common Objects
|
14
|
+
|
15
|
+
Currently supporting the following objects:
|
16
|
+
|
17
|
+
**ServiceProduct**
|
18
|
+
**Answer** (only new, create, and find methods supported as of 1/11)
|
19
|
+
|
20
|
+
At this time, subclasses such as ServiceProduct.CategoryLinks are not currently supported.
|
21
|
+
|
22
|
+
I am trying to build a few more classes and have a pretty solid testing suite and codebase before implementing this functionality.
|
23
|
+
|
24
|
+
## Installation
|
25
|
+
|
26
|
+
Add this line to your application's Gemfile:
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
gem 'osc_ruby'
|
30
|
+
```
|
31
|
+
|
32
|
+
And then execute:
|
33
|
+
|
34
|
+
$ bundle
|
35
|
+
|
36
|
+
Or install it yourself as:
|
37
|
+
|
38
|
+
$ gem install osc_ruby
|
39
|
+
|
40
|
+
|
41
|
+
## ServiceProduct Example
|
8
42
|
```ruby
|
9
|
-
# Configuration is as simple as requiring the gem
|
10
|
-
# and adding a config block (Completed 12/2016)
|
11
43
|
|
12
|
-
|
44
|
+
# Configuration is as simple as requiring the gem
|
45
|
+
# and adding a config block (Completed 12/2016)
|
13
46
|
|
14
|
-
|
15
|
-
config.username = ENV['OSC_ADMIN']
|
16
|
-
config.password = ENV['OSC_PASSWORD']
|
17
|
-
config.interface = ENV['OSC_TEST_SITE']
|
18
|
-
end
|
47
|
+
require 'osc_ruby'
|
19
48
|
|
49
|
+
rn_client = OSCRuby::Client.new do |config|
|
50
|
+
config.username = ENV['OSC_ADMIN']
|
51
|
+
config.password = ENV['OSC_PASSWORD']
|
52
|
+
config.interface = ENV['OSC_TEST_SITE']
|
53
|
+
end
|
20
54
|
|
21
|
-
# ServiceProduct Creation example (Completed 12/30/2016)
|
22
55
|
|
23
|
-
|
56
|
+
# ServiceProduct Creation example (Completed 12/30/2016)
|
24
57
|
|
25
|
-
|
58
|
+
new_product = OSCRuby::ServiceProduct.new
|
26
59
|
|
27
|
-
|
28
|
-
new_product.names[1] = {'labelText' => 'QTH45-test', 'language' => {'id' => 11}}
|
60
|
+
# use Ruby hashes to set field information
|
29
61
|
|
30
|
-
|
62
|
+
new_product.names[0] = {'labelText' => 'QTH45-test', 'language' => {'id' => 1}}
|
63
|
+
new_product.names[1] = {'labelText' => 'QTH45-test', 'language' => {'id' => 11}}
|
31
64
|
|
32
|
-
|
65
|
+
new_product.parent = {'id' => 102}
|
33
66
|
|
34
|
-
|
67
|
+
new_product.displayOrder = 4
|
35
68
|
|
36
|
-
|
69
|
+
new_product.adminVisibleInterfaces[0] = {'id' => 1}
|
37
70
|
|
38
|
-
|
71
|
+
new_product.endUserVisibleInterfaces[0] = {'id' => 1}
|
39
72
|
|
40
|
-
|
73
|
+
new_product.create(rn_client)
|
41
74
|
|
75
|
+
# callback with JSON details
|
42
76
|
|
43
77
|
|
44
78
|
|
45
|
-
# NOTE: Make sure that in a production environment
|
46
|
-
# that the following methods are wrapped in a begin/rescue block.
|
47
79
|
|
48
|
-
|
49
|
-
|
50
|
-
# this is to ensure that you
|
51
|
-
# handle your errors explicitly
|
52
|
-
# when writing scripts
|
80
|
+
# NOTE: Make sure that in a production environment
|
81
|
+
# that the following methods are wrapped in a begin/rescue block.
|
53
82
|
|
83
|
+
# If a null set is returned by your query
|
84
|
+
# an exception will be raised
|
85
|
+
# this is to ensure that you
|
86
|
+
# handle your errors explicitly
|
87
|
+
# when writing scripts
|
54
88
|
|
55
|
-
# ServiceProduct fetch example (Completed 12/28/2016)
|
56
89
|
|
57
|
-
|
90
|
+
# ServiceProduct fetch example (Completed 12/28/2016)
|
58
91
|
|
59
|
-
|
60
|
-
# => #<ServiceProduct:0x007fd0fa87e588>
|
92
|
+
product = OSCRuby::ServiceProduct.find(rn_client,100)
|
61
93
|
|
62
|
-
|
63
|
-
|
94
|
+
puts product
|
95
|
+
# => #<ServiceProduct:0x007fd0fa87e588>
|
64
96
|
|
65
|
-
|
66
|
-
|
97
|
+
puts product.name
|
98
|
+
# => QR404
|
67
99
|
|
68
|
-
|
100
|
+
puts product.displayOrder
|
101
|
+
# => 3
|
69
102
|
|
70
|
-
|
103
|
+
# ServiceProduct fetch all example (Completed 01/05/2017)
|
71
104
|
|
72
|
-
|
105
|
+
products = OSCRuby::ServiceProduct.all(rn_client)
|
73
106
|
|
74
|
-
|
107
|
+
products.each do |p|
|
75
108
|
|
76
|
-
|
109
|
+
puts p.name
|
77
110
|
|
78
|
-
|
79
|
-
# => DVR/NVR
|
80
|
-
# => QC Series
|
81
|
-
# => QR Series
|
82
|
-
# => QR404
|
83
|
-
# => QS Series
|
84
|
-
# => QT Series
|
111
|
+
end
|
85
112
|
|
113
|
+
# => Unsure
|
114
|
+
# => DVR/NVR
|
115
|
+
# => QC Series
|
116
|
+
# => QR Series
|
117
|
+
# => QR404
|
118
|
+
# => QS Series
|
119
|
+
# => QT Series
|
86
120
|
|
87
|
-
# ServiceProduct where example (Completed 01/05/2017)
|
88
121
|
|
89
|
-
|
90
|
-
# this is because when Ruby converts the queries into a URI
|
91
|
-
# the REST API does not like it when the queries are wrapped in single quotes ('')
|
92
|
-
# with strings escaped by double quotes
|
122
|
+
# ServiceProduct where example (Completed 01/05/2017)
|
93
123
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
124
|
+
# NOTE: Make sure to put your queries wrapped in doublequotes("")
|
125
|
+
# this is because when Ruby converts the queries into a URI
|
126
|
+
# the REST API does not like it when the queries are wrapped in single quotes ('')
|
127
|
+
# with strings escaped by double quotes
|
98
128
|
|
99
|
-
|
129
|
+
# For example
|
130
|
+
# "parent is null and lookupName!='Unsure'" => great!
|
131
|
+
# 'parent is null and lookupName!="Unsure"' => don't do this
|
132
|
+
# it will spit back an error from the REST API!
|
100
133
|
|
101
|
-
|
134
|
+
products_lvl_1 = OSCRuby::ServiceProduct.where(rn_client,"parent is null and lookupName!='Unsure'")
|
102
135
|
|
103
|
-
|
136
|
+
products_lvl_1.each do |p|
|
104
137
|
|
105
|
-
|
138
|
+
puts p.name
|
106
139
|
|
107
|
-
|
108
|
-
# => Cameras
|
109
|
-
# => Accessories
|
140
|
+
end
|
110
141
|
|
142
|
+
# => DVR/NVR
|
143
|
+
# => Cameras
|
144
|
+
# => Accessories
|
111
145
|
|
112
|
-
# ServiceProduct update example (Completed 01/05/2017)
|
113
146
|
|
114
|
-
|
147
|
+
# ServiceProduct update example (Completed 01/05/2017)
|
115
148
|
|
116
|
-
|
149
|
+
product_to_update = OSCRuby::ServiceProduct.find(rn_client,100)
|
117
150
|
|
118
|
-
|
151
|
+
product_to_update.names[0] = {'labelText' => 'name-updated', 'language' => {'id' => 1}}
|
119
152
|
|
120
|
-
|
153
|
+
product_to_update.update(rn_client)
|
121
154
|
|
155
|
+
# ServiceProduct updated
|
122
156
|
|
123
157
|
|
124
158
|
|
125
|
-
# ServiceProduct destroy example
|
126
159
|
|
127
|
-
|
160
|
+
# ServiceProduct destroy example (Completed 01/06/2017)
|
128
161
|
|
129
|
-
|
162
|
+
product_to_delete = OSCRuby::ServiceProduct.find(rn_client,100)
|
130
163
|
|
131
|
-
|
164
|
+
product_to_delete.destroy(rn_client)
|
165
|
+
|
166
|
+
# ServiceProduct destroyed
|
132
167
|
```
|
133
168
|
|
134
169
|
## To do list
|
@@ -169,54 +204,28 @@ An (under development) Ruby ORM for using Oracle Service Cloud influenced by the
|
|
169
204
|
|
170
205
|
- [x] Build a QueryModule Module with the following query methods to be shared between most if not all classes:
|
171
206
|
|
172
|
-
- [x] create
|
173
|
-
|
174
|
-
- [x] find
|
175
|
-
|
176
|
-
- [x] where
|
177
|
-
|
178
|
-
- [x] all
|
179
|
-
|
180
|
-
- [x] update
|
181
|
-
|
182
|
-
- [ ] destroy
|
207
|
+
- [x] create, find, where, all, update, destroy
|
183
208
|
|
184
209
|
- [x] QueryModule converts JSON response into a Ruby Hash => new instance of the object being queried
|
185
210
|
|
186
211
|
- [x] Create some validations for creating a ServiceProduct object
|
187
212
|
|
188
|
-
- [
|
213
|
+
- [x] Add in VCR and WebMock as dependencies
|
189
214
|
|
190
|
-
- [
|
215
|
+
- [x] Figure out how to record and stub responses for a good response and bad response
|
191
216
|
|
192
|
-
- [
|
217
|
+
- [x] Simulate these responses for ALL Connect HTTP methods
|
193
218
|
|
194
|
-
- [
|
219
|
+
- [x] Make OpenSSL::SSL::VERIFY_PEER the default with OpenSSL::SSL::VERIFY_NONE option set in the config class
|
195
220
|
|
196
|
-
- [
|
221
|
+
- [x] Make version default to 1.3 but an option to be set in the config class
|
197
222
|
|
198
|
-
- [ ]
|
223
|
+
- [ ] Allow for the prefer:exclude-null-properties header => update config and connect class, update tests
|
199
224
|
|
200
|
-
- [ ]
|
225
|
+
- [ ] Allow for Session Authorization => update config class and connect classes, update tests
|
201
226
|
|
202
|
-
- [ ]
|
227
|
+
- [ ] Figure out how to do RDoc/Yardoc documentation or best in class documentation for using this Ruby ORM
|
203
228
|
|
204
229
|
- [ ] Follow with next Classes (ServiceCategories, Answers, Incidents)
|
205
230
|
|
206
|
-
- [ ] Release MVP
|
207
|
-
|
208
|
-
## Installation
|
209
|
-
|
210
|
-
Add this line to your application's Gemfile:
|
211
|
-
|
212
|
-
```ruby
|
213
|
-
gem 'osc_ruby'
|
214
|
-
```
|
215
|
-
|
216
|
-
And then execute:
|
217
|
-
|
218
|
-
$ bundle
|
219
|
-
|
220
|
-
Or install it yourself as:
|
221
|
-
|
222
|
-
$ gem install osc_ruby
|
231
|
+
- [ ] Release MVP
|
data/lib/osc_ruby.rb
CHANGED
@@ -0,0 +1,169 @@
|
|
1
|
+
require 'osc_ruby/client'
|
2
|
+
require 'osc_ruby/query_module'
|
3
|
+
require 'osc_ruby/validations_module'
|
4
|
+
require 'osc_ruby/class_factory_module'
|
5
|
+
require 'json'
|
6
|
+
require 'uri'
|
7
|
+
|
8
|
+
module OSCRuby
|
9
|
+
|
10
|
+
class Answer
|
11
|
+
|
12
|
+
include QueryModule
|
13
|
+
include ValidationsModule
|
14
|
+
include ClassFactoryModule
|
15
|
+
|
16
|
+
attr_accessor :answerType, :language, :summary, :id, :lookupName, :createdTime, :updatedTime, :accessLevels, :name, :adminLastAccessTime, :expiresDate, :guidedAssistance, :keywords, :lastAccessTime, :lastNotificationTime, :nextNotificationTime, :originalReferenceNumber, :positionInList,
|
17
|
+
:publishOnDate, :question, :solution, :updatedByAccount, :uRL
|
18
|
+
|
19
|
+
def initialize(attributes = nil)
|
20
|
+
|
21
|
+
if attributes.nil?
|
22
|
+
|
23
|
+
@answerType = {}
|
24
|
+
@summary = "Answer summary text"
|
25
|
+
@language = {}
|
26
|
+
@question = nil
|
27
|
+
|
28
|
+
else
|
29
|
+
|
30
|
+
@id = attributes["id"]
|
31
|
+
@lookupName = attributes["lookupName"]
|
32
|
+
@createdTime = attributes["createdTime"]
|
33
|
+
@updatedTime = attributes["updatedTime"]
|
34
|
+
@accessLevels = attributes["accessLevels"]
|
35
|
+
@name = attributes["name"]
|
36
|
+
@adminLastAccessTime = attributes["adminLastAccessTime"]
|
37
|
+
@answerType = attributes["answerType"]
|
38
|
+
@expiresDate = attributes["expiresDate"]
|
39
|
+
@guidedAssistance = attributes["guidedAssistance"]
|
40
|
+
@keywords = attributes["keywords"]
|
41
|
+
@language = attributes["language"]
|
42
|
+
@lastAccessTime = attributes["lastAccessTime"]
|
43
|
+
@lastNotificationTime = attributes["lastNotificationTime"]
|
44
|
+
@nextNotificationTime = attributes["nextNotificationTime"]
|
45
|
+
@originalReferenceNumber = attributes["originalReferenceNumber"]
|
46
|
+
@positionInList = attributes["positionInList"]
|
47
|
+
@publishOnDate = attributes["publishOnDate"]
|
48
|
+
@question = attributes["question"]
|
49
|
+
@solution = attributes["solution"]
|
50
|
+
@summary = attributes["summary"]
|
51
|
+
@updatedByAccount = attributes["updatedByAccount"]
|
52
|
+
@uRL = attributes["uRL"]
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
def create(client,return_json = false)
|
59
|
+
|
60
|
+
ClassFactoryModule.create(client,self,"/answers",return_json)
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
|
65
|
+
def self.find(client,id = nil,return_json = false)
|
66
|
+
|
67
|
+
ClassFactoryModule.find(client,id,'answers',return_json,OSCRuby::Answer)
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
def self.all(client, return_json = false)
|
73
|
+
|
74
|
+
ClassFactoryModule.all(client,'answers',return_json,OSCRuby::Answer)
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
def self.where(client, query = '', return_json = false)
|
79
|
+
|
80
|
+
ClassFactoryModule.where(client,query,'answers',return_json,OSCRuby::Answer)
|
81
|
+
|
82
|
+
end
|
83
|
+
|
84
|
+
def update(client, return_json = false)
|
85
|
+
|
86
|
+
ClassFactoryModule::update(client,self,"answers",return_json)
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
def destroy(client, return_json = false)
|
91
|
+
|
92
|
+
ClassFactoryModule.destroy(client,self,'answers',return_json)
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
|
106
|
+
# Convenience Methods for making the CRUD operations nicer to use
|
107
|
+
|
108
|
+
def set_attributes(response_body)
|
109
|
+
self.id = response_body['id'].to_i
|
110
|
+
self.lookupName = response_body['lookupName'].to_i
|
111
|
+
self.createdTime = response_body['createdTime']
|
112
|
+
self.updatedTime = response_body['updatedTime']
|
113
|
+
self.accessLevels = response_body['accessLevels']
|
114
|
+
self.adminLastAccessTime = response_body['adminLastAccessTime']
|
115
|
+
self.answerType = response_body['answerType']
|
116
|
+
self.expiresDate = response_body['expiresDate']
|
117
|
+
self.guidedAssistance = response_body['guidedAssistance']
|
118
|
+
self.keywords = response_body['keywords']
|
119
|
+
self.language = response_body['language']
|
120
|
+
self.lastAccessTime = response_body['lastAccessTime']
|
121
|
+
self.lastNotificationTime = response_body['lastNotificationTime']
|
122
|
+
self.name = response_body['name'].to_i
|
123
|
+
self.nextNotificationTime = response_body['nextNotificationTime']
|
124
|
+
self.originalReferenceNumber = response_body['originalReferenceNumber']
|
125
|
+
self.positionInList = response_body['positionInList']
|
126
|
+
self.publishOnDate = response_body['publishOnDate']
|
127
|
+
self.question = response_body['question']
|
128
|
+
self.solution = response_body['solution']
|
129
|
+
self.summary = response_body['summary']
|
130
|
+
self.updatedByAccount = response_body['updatedByAccount']
|
131
|
+
self.uRL = response_body['uRL']
|
132
|
+
end
|
133
|
+
|
134
|
+
def self.check_self(obj,is_update = false)
|
135
|
+
|
136
|
+
obj_attrs = ValidationsModule::extract_attributes(obj)
|
137
|
+
|
138
|
+
if is_update == false
|
139
|
+
|
140
|
+
obj_attrs = check_for_language_and_type(obj_attrs)
|
141
|
+
|
142
|
+
end
|
143
|
+
|
144
|
+
obj_attrs
|
145
|
+
|
146
|
+
end
|
147
|
+
|
148
|
+
def self.check_for_language_and_type(obj_attrs)
|
149
|
+
|
150
|
+
if ValidationsModule::attr_hash_exists_and_is_type_of(obj_attrs,'language','id',Fixnum)
|
151
|
+
|
152
|
+
raise ArgumentError, 'Answer should at least the language, answerType, and summary set (new_answer.language = {"id" => 1}; new_answer.answerType = {"id" => 1}}; new_answer.summary = "This is the Answer Title")'
|
153
|
+
|
154
|
+
end
|
155
|
+
|
156
|
+
if ValidationsModule::attr_hash_exists_and_is_type_of(obj_attrs,'answerType','id',Fixnum) &&
|
157
|
+
ValidationsModule::attr_hash_exists_and_is_type_of(obj_attrs,'answerType','lookupName',String)
|
158
|
+
|
159
|
+
raise ArgumentError, 'Answer should at least the language, answerType, and summary set (new_answer.language = {"id" => 1}; new_answer.answerType = {"id" => 1}}; new_answer.summary = "This is the Answer Title")'
|
160
|
+
|
161
|
+
end
|
162
|
+
|
163
|
+
obj_attrs
|
164
|
+
|
165
|
+
end
|
166
|
+
|
167
|
+
end
|
168
|
+
|
169
|
+
end
|