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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3886686a1a45880611a4e06689c3c4ae573a3f30
4
- data.tar.gz: 276a472588a6495a688103ac8756184c03b60904
3
+ metadata.gz: 0262af3d710018528271b39304094ca53663c9e2
4
+ data.tar.gz: 1c7000c6df53b2bc4dfa45a6e65ff0356f182246
5
5
  SHA512:
6
- metadata.gz: f9cd46f98226b08627060983f4d16bd722a05048bb06f9c0bb135a16743c4e68c6e5dfc2a6538e703d8fee299158a7694b256388ab78ad309931684d7cd3103b
7
- data.tar.gz: a940df9e72dda18074ab014b1be6b490044bfe3a6aa141fe142e5a1af8206fc33fd5f69428b6a4d1dfd733d30d81ee59bf39b634a474d70d71d18db15815238c
6
+ metadata.gz: ab15d881832e339d67857eec0129bb5416b79f8822c8f5d7fad3b0b4998db89d300da41337cbf311b0432edd23949ea8caa46b90cacf2e013e96b89e419ef77c
7
+ data.tar.gz: be2146f1137e001348c636dab826f08c8a3d4963e0da2392a52e993394ae8958085dc6d20ed3be68f9f5968428d6c017a1f5319ecee02d9b0e3e6b24a0b976dc
data/.gitignore CHANGED
@@ -6,6 +6,7 @@
6
6
  /doc/
7
7
  /pkg/
8
8
  /spec/reports/
9
+ /spec/fixtures/
9
10
  /tmp/
10
11
  *.bundle
11
12
  *.so
data/Gemfile CHANGED
@@ -1,10 +1,4 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in osc_ruby.gemspec
4
- gemspec
5
-
6
- group :test do
7
- gem 'rspec'
8
- gem "simplecov"
9
- gem "codeclimate-test-reporter", "~> 1.0.0"
10
- end
4
+ gemspec
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
- ## Example (still coding this out, but trying to get this pretty simple)
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
- require 'osc_ruby'
44
+ # Configuration is as simple as requiring the gem
45
+ # and adding a config block (Completed 12/2016)
13
46
 
14
- rn_client = OSCRuby::Client.new do |config|
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
- new_product = OSCRuby::ServiceProduct.new
56
+ # ServiceProduct Creation example (Completed 12/30/2016)
24
57
 
25
- # use Ruby hashes to set field information
58
+ new_product = OSCRuby::ServiceProduct.new
26
59
 
27
- new_product.names[0] = {'labelText' => 'QTH45-test', 'language' => {'id' => 1}}
28
- new_product.names[1] = {'labelText' => 'QTH45-test', 'language' => {'id' => 11}}
60
+ # use Ruby hashes to set field information
29
61
 
30
- new_product.parent = {'id' => 102}
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
- new_product.displayOrder = 4
65
+ new_product.parent = {'id' => 102}
33
66
 
34
- new_product.adminVisibleInterfaces[0] = {'id' => 1}
67
+ new_product.displayOrder = 4
35
68
 
36
- new_product.endUserVisibleInterfaces[0] = {'id' => 1}
69
+ new_product.adminVisibleInterfaces[0] = {'id' => 1}
37
70
 
38
- new_product.create(rn_client)
71
+ new_product.endUserVisibleInterfaces[0] = {'id' => 1}
39
72
 
40
- # callback with JSON details
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
- # If a null set is returned by your query
49
- # an exception will be raised
50
- # this is to ensure that you
51
- # handle your errors explicitly
52
- # when writing scripts
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
- product = OSCRuby::ServiceProduct.find(rn_client,100)
90
+ # ServiceProduct fetch example (Completed 12/28/2016)
58
91
 
59
- puts product
60
- # => #<ServiceProduct:0x007fd0fa87e588>
92
+ product = OSCRuby::ServiceProduct.find(rn_client,100)
61
93
 
62
- puts product.name
63
- # => QR404
94
+ puts product
95
+ # => #<ServiceProduct:0x007fd0fa87e588>
64
96
 
65
- puts product.displayOrder
66
- # => 3
97
+ puts product.name
98
+ # => QR404
67
99
 
68
- # ServiceProduct fetch all example (Completed 01/05/2017)
100
+ puts product.displayOrder
101
+ # => 3
69
102
 
70
- products = OSCRuby::ServiceProduct.all(rn_client)
103
+ # ServiceProduct fetch all example (Completed 01/05/2017)
71
104
 
72
- products.each do |p|
105
+ products = OSCRuby::ServiceProduct.all(rn_client)
73
106
 
74
- puts p.name
107
+ products.each do |p|
75
108
 
76
- end
109
+ puts p.name
77
110
 
78
- # => Unsure
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
- # NOTE: Make sure to put your queries wrapped in doublequotes("")
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
- # For example
95
- # "parent is null and lookupName!='Unsure'" => great!
96
- # 'parent is null and lookupName!="Unsure"' => don't do this
97
- # it will spit back an error from the REST API!
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
- products_lvl_1 = OSCRuby::ServiceProduct.where(rn_client,"parent is null and lookupName!='Unsure'")
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
- products_lvl_1.each do |p|
134
+ products_lvl_1 = OSCRuby::ServiceProduct.where(rn_client,"parent is null and lookupName!='Unsure'")
102
135
 
103
- puts p.name
136
+ products_lvl_1.each do |p|
104
137
 
105
- end
138
+ puts p.name
106
139
 
107
- # => DVR/NVR
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
- product_to_update = OSCRuby::ServiceProduct.find(rn_client,100)
147
+ # ServiceProduct update example (Completed 01/05/2017)
115
148
 
116
- product_to_update.names[0] = {'labelText' => 'name-updated', 'language' => {'id' => 1}}
149
+ product_to_update = OSCRuby::ServiceProduct.find(rn_client,100)
117
150
 
118
- product_to_update.update(rn_client)
151
+ product_to_update.names[0] = {'labelText' => 'name-updated', 'language' => {'id' => 1}}
119
152
 
120
- # ServiceProduct updated
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
- product_to_delete = OSCRuby::ServiceProduct.find(rn_client,100)
160
+ # ServiceProduct destroy example (Completed 01/06/2017)
128
161
 
129
- product_to_delete.destroy(rn_client)
162
+ product_to_delete = OSCRuby::ServiceProduct.find(rn_client,100)
130
163
 
131
- # ServiceProduct destroyed
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
- - [ ] Make OpenSSL::SSL::VERIFY_PEER the default with OpenSSL::SSL::VERIFY_NONE option set in the config class
213
+ - [x] Add in VCR and WebMock as dependencies
189
214
 
190
- - [ ] Make version default to 1.3 but an option to be set in the config class
215
+ - [x] Figure out how to record and stub responses for a good response and bad response
191
216
 
192
- - [ ] Allow for the prefer:exclude-null-properties header => update config and connect class, update tests
217
+ - [x] Simulate these responses for ALL Connect HTTP methods
193
218
 
194
- - [ ] Allow for Session Authorization => update config class and connect classes, update tests
219
+ - [x] Make OpenSSL::SSL::VERIFY_PEER the default with OpenSSL::SSL::VERIFY_NONE option set in the config class
195
220
 
196
- - [ ] Figure out how to do RDoc/Yardoc documentation or best in class documentation for using this Ruby ORM
221
+ - [x] Make version default to 1.3 but an option to be set in the config class
197
222
 
198
- - [ ] Add in VCR and WebMock as dependencies
223
+ - [ ] Allow for the prefer:exclude-null-properties header => update config and connect class, update tests
199
224
 
200
- - [ ] Figure out how to record and stub responses for a good response and bad response
225
+ - [ ] Allow for Session Authorization => update config class and connect classes, update tests
201
226
 
202
- - [ ] Simulate these responses for ALL Connect HTTP methods
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
@@ -2,4 +2,5 @@ module OSCRuby; end
2
2
 
3
3
  require 'osc_ruby/client'
4
4
  require 'osc_ruby/connect'
5
- require 'osc_ruby/service_product'
5
+ require 'osc_ruby/service_product'
6
+ require 'osc_ruby/answer'
@@ -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