osc_ruby 0.7.1 → 1.0.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.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +25 -25
  3. data/.gitignore +15 -15
  4. data/.rspec +1 -1
  5. data/.rubocop.yml +1156 -1156
  6. data/.travis.yml +9 -9
  7. data/Gemfile +3 -3
  8. data/License.txt +21 -0
  9. data/README.md +95 -242
  10. data/Rakefile +2 -2
  11. data/lib/ext/string.rb +18 -18
  12. data/lib/osc_ruby/classes/query_results.rb +40 -60
  13. data/lib/osc_ruby/client.rb +40 -40
  14. data/lib/osc_ruby/configuration.rb +14 -13
  15. data/lib/osc_ruby/connect.rb +218 -209
  16. data/lib/osc_ruby/modules/normalize_module.rb +121 -121
  17. data/lib/osc_ruby/modules/query_module.rb +69 -69
  18. data/lib/osc_ruby/modules/validations_module.rb +168 -168
  19. data/lib/osc_ruby/version.rb +2 -2
  20. data/lib/osc_ruby.rb +4 -10
  21. data/osc_ruby.gemspec +28 -29
  22. data/spec/core/client_spec.rb +96 -96
  23. data/spec/core/configuration_spec.rb +4 -4
  24. data/spec/core/connect_spec.rb +366 -364
  25. data/spec/core/query_results_spec.rb +107 -133
  26. data/spec/core/spec_helper.rb +25 -25
  27. data/tasks/rspec.rake +2 -2
  28. metadata +23 -22
  29. data/LICENSE.txt +0 -22
  30. data/lib/osc_ruby/classes/account.rb +0 -75
  31. data/lib/osc_ruby/classes/answer.rb +0 -117
  32. data/lib/osc_ruby/classes/incident.rb +0 -13
  33. data/lib/osc_ruby/classes/product_category_shared.rb +0 -118
  34. data/lib/osc_ruby/classes/service_category.rb +0 -6
  35. data/lib/osc_ruby/classes/service_class.rb +0 -66
  36. data/lib/osc_ruby/classes/service_product.rb +0 -6
  37. data/lib/osc_ruby/modules/class_factory_module.rb +0 -165
  38. data/lib/osc_ruby/modules/nested_resource_module.rb +0 -10
  39. data/spec/core/account_spec.rb +0 -497
  40. data/spec/core/answer_spec.rb +0 -545
  41. data/spec/core/service_category_spec.rb +0 -445
  42. data/spec/core/service_product_spec.rb +0 -443
@@ -1,70 +1,70 @@
1
- require 'osc_ruby/connect'
2
- require 'osc_ruby/modules/validations_module'
3
- require 'osc_ruby/modules/normalize_module'
4
- require_relative '../../ext/string.rb'
5
-
6
- module OSCRuby
7
-
8
- module QueryModule
9
-
10
- class << self
11
-
12
- include ValidationsModule, NormalizeModule
13
-
14
- def find(rn_client,resource)
15
-
16
- obj_to_find = OSCRuby::Connect.get(rn_client,resource)
17
-
18
- if obj_to_find.code.to_i == 200 || obj_to_find.code.to_i == 201
19
-
20
- ValidationsModule::check_obj_for_errors(obj_to_find)
21
-
22
- NormalizeModule::normalize(obj_to_find,resource)
23
- else
24
-
25
- obj_to_find.body
26
-
27
- end
28
-
29
- end
30
-
31
- def nested_find(rn_client,resource)
32
-
33
- obj_to_find = OSCRuby::Connect.get(rn_client,resource)
34
-
35
- if obj_to_find.code.to_i == 200 || obj_to_find.code.to_i == 201
36
-
37
- ValidationsModule::check_obj_for_errors(obj_to_find)
38
-
39
- NormalizeModule::nested_normalize(obj_to_find,resource)
40
- else
41
-
42
- obj_to_find.body
43
-
44
- end
45
-
46
- end
47
-
48
- def create(rn_client,resource,json_content)
49
-
50
- OSCRuby::Connect.post_or_patch(rn_client,resource,json_content)
51
-
52
- end
53
-
54
- def update(rn_client,resource,json_content)
55
-
56
- OSCRuby::Connect.post_or_patch(rn_client,resource,json_content,true)
57
-
58
- end
59
-
60
- def destroy(rn_client,resource)
61
-
62
- OSCRuby::Connect.delete(rn_client,resource)
63
-
64
- end
65
-
66
- end
67
-
68
- end
69
-
1
+ require 'osc_ruby/connect'
2
+ require 'osc_ruby/modules/validations_module'
3
+ require 'osc_ruby/modules/normalize_module'
4
+ require_relative '../../ext/string.rb'
5
+
6
+ module OSCRuby
7
+
8
+ module QueryModule
9
+
10
+ class << self
11
+
12
+ include ValidationsModule, NormalizeModule
13
+
14
+ def find(rn_client,resource)
15
+
16
+ obj_to_find = OSCRuby::Connect.get(rn_client,resource)
17
+
18
+ if obj_to_find.code.to_i == 200 || obj_to_find.code.to_i == 201
19
+
20
+ ValidationsModule::check_obj_for_errors(obj_to_find)
21
+
22
+ NormalizeModule::normalize(obj_to_find,resource)
23
+ else
24
+
25
+ obj_to_find.body
26
+
27
+ end
28
+
29
+ end
30
+
31
+ def nested_find(rn_client,resource)
32
+
33
+ obj_to_find = OSCRuby::Connect.get(rn_client,resource)
34
+
35
+ if obj_to_find.code.to_i == 200 || obj_to_find.code.to_i == 201
36
+
37
+ ValidationsModule::check_obj_for_errors(obj_to_find)
38
+
39
+ NormalizeModule::nested_normalize(obj_to_find,resource)
40
+ else
41
+
42
+ obj_to_find.body
43
+
44
+ end
45
+
46
+ end
47
+
48
+ def create(rn_client,resource,json_content)
49
+
50
+ OSCRuby::Connect.post_or_patch(rn_client,resource,json_content)
51
+
52
+ end
53
+
54
+ def update(rn_client,resource,json_content)
55
+
56
+ OSCRuby::Connect.post_or_patch(rn_client,resource,json_content,true)
57
+
58
+ end
59
+
60
+ def destroy(rn_client,resource)
61
+
62
+ OSCRuby::Connect.delete(rn_client,resource)
63
+
64
+ end
65
+
66
+ end
67
+
68
+ end
69
+
70
70
  end
@@ -1,169 +1,169 @@
1
- require 'osc_ruby/connect'
2
- require 'json'
3
-
4
- module OSCRuby
5
-
6
- module ValidationsModule
7
-
8
- class << self
9
-
10
- def extract_attributes(obj)
11
-
12
- empty_arr = [{}]
13
-
14
- obj_vars = obj.instance_variables
15
-
16
- obj_vars.each do |var|
17
-
18
- # Make sure to get rid of the empty ID
19
- # otherwise everything gets all screwed up
20
-
21
- if var.to_s != '@id'
22
-
23
- obj_attr = var.to_s.delete("@")
24
-
25
- obj_attr_val = obj.instance_variable_get(var)
26
-
27
- empty_arr[0][obj_attr] = obj_attr_val
28
-
29
- end
30
-
31
- end
32
-
33
- empty_arr
34
-
35
- end
36
-
37
- def check_for_id(id)
38
-
39
- if id.nil? == true
40
-
41
- raise ArgumentError, 'ID cannot be nil'
42
-
43
- elsif id.class != Fixnum
44
-
45
- raise ArgumentError, 'ID must be an integer'
46
-
47
- end
48
-
49
- end
50
-
51
- def check_object_for_id(obj,class_name)
52
-
53
- if obj.id.nil?
54
-
55
- raise ArgumentError, "#{class_name} must have a valid ID set"
56
-
57
- end
58
-
59
- end
60
-
61
- def check_attributes(attributes)
62
-
63
- if attributes.class != Hash
64
-
65
- puts attributes
66
-
67
- raise ArgumentError, "Attributes must be a hash; please use the appropriate data structure"
68
-
69
- end
70
-
71
- end
72
-
73
- def check_query(query,method_name = "where")
74
-
75
- if query.empty?
76
-
77
- raise ArgumentError, "A query must be specified when using the '#{method_name}' method"
78
-
79
- end
80
-
81
- end
82
-
83
- def check_attributes_request(attributes_request,class_name)
84
-
85
- if attributes_request.empty?
86
-
87
- raise ArgumentError, "The attributes you are requesting for the #{class_name} object must be specified when using the 'select' method"
88
-
89
- end
90
-
91
- end
92
-
93
- def check_client(client)
94
-
95
- if client.class != OSCRuby::Client || client.nil?
96
-
97
- raise ArgumentError, "Client must have some configuration set; please create an instance of OSCRuby::Client with configuration settings"
98
-
99
- end
100
-
101
- end
102
-
103
- def attr_hash_exists_and_is_type_of(obj,key,val,class_of_value)
104
-
105
- return obj[0][key][val].nil? || obj[0][key][val].class != class_of_value
106
-
107
- end
108
-
109
- def check_for_names(obj_attrs,class_name)
110
-
111
- if obj_attrs[0]['names'].count == 0 || obj_attrs[0]['names'][0]['labelText'].nil? || obj_attrs[0]['names'][0]['language'].nil?
112
-
113
- raise ArgumentError, "#{class_name} should at least have one name set"
114
-
115
- end
116
-
117
- obj_attrs
118
-
119
- end
120
-
121
- def check_for_parents(obj_attrs)
122
-
123
- if !obj_attrs[0]['parent'].nil? && obj_attrs[0]['parent'].is_a?(Hash) && !obj_attrs[0]['parent'].key?('id') && !obj_attrs[0]['parent'].key?('lookupName')
124
-
125
- obj_attrs[0].delete('parent')
126
-
127
- end
128
-
129
- obj_attrs
130
-
131
- end
132
-
133
- def check_interfaces(empty_arr)
134
-
135
- if empty_arr[0]['adminVisibleInterfaces'].empty?
136
-
137
- empty_arr[0].delete('adminVisibleInterfaces')
138
-
139
- end
140
-
141
- if empty_arr[0]['endUserVisibleInterfaces'].empty?
142
-
143
- empty_arr[0].delete('endUserVisibleInterfaces')
144
-
145
- end
146
-
147
- empty_arr
148
-
149
- end
150
-
151
- def check_obj_for_errors(obj_to_check)
152
-
153
- json_obj = JSON.parse(obj_to_check.body)
154
-
155
- if !json_obj.nil? && json_obj['items'][0]['rows'].count == 0
156
-
157
- puts obj_to_check.body
158
-
159
- raise ArgumentError, 'There were no objects matching your query; please try again.'
160
-
161
- end
162
-
163
- end
164
-
165
- end
166
-
167
- end
168
-
1
+ require 'osc_ruby/connect'
2
+ require 'json'
3
+
4
+ module OSCRuby
5
+
6
+ module ValidationsModule
7
+
8
+ class << self
9
+
10
+ def extract_attributes(obj)
11
+
12
+ empty_arr = [{}]
13
+
14
+ obj_vars = obj.instance_variables
15
+
16
+ obj_vars.each do |var|
17
+
18
+ # Make sure to get rid of the empty ID
19
+ # otherwise everything gets all screwed up
20
+
21
+ if var.to_s != '@id'
22
+
23
+ obj_attr = var.to_s.delete("@")
24
+
25
+ obj_attr_val = obj.instance_variable_get(var)
26
+
27
+ empty_arr[0][obj_attr] = obj_attr_val
28
+
29
+ end
30
+
31
+ end
32
+
33
+ empty_arr
34
+
35
+ end
36
+
37
+ def check_for_id(id)
38
+
39
+ if id.nil? == true
40
+
41
+ raise ArgumentError, 'ID cannot be nil'
42
+
43
+ elsif id.class != Fixnum
44
+
45
+ raise ArgumentError, 'ID must be an integer'
46
+
47
+ end
48
+
49
+ end
50
+
51
+ def check_object_for_id(obj,class_name)
52
+
53
+ if obj.id.nil?
54
+
55
+ raise ArgumentError, "#{class_name} must have a valid ID set"
56
+
57
+ end
58
+
59
+ end
60
+
61
+ def check_attributes(attributes)
62
+
63
+ if attributes.class != Hash
64
+
65
+ puts attributes
66
+
67
+ raise ArgumentError, "Attributes must be a hash; please use the appropriate data structure"
68
+
69
+ end
70
+
71
+ end
72
+
73
+ def check_query(query,method_name = "where")
74
+
75
+ if query.empty?
76
+
77
+ raise ArgumentError, "A query must be specified when using the '#{method_name}' method"
78
+
79
+ end
80
+
81
+ end
82
+
83
+ def check_attributes_request(attributes_request,class_name)
84
+
85
+ if attributes_request.empty?
86
+
87
+ raise ArgumentError, "The attributes you are requesting for the #{class_name} object must be specified when using the 'select' method"
88
+
89
+ end
90
+
91
+ end
92
+
93
+ def check_client(client)
94
+
95
+ if client.class != OSCRuby::Client || client.nil?
96
+
97
+ raise ArgumentError, "Client must have some configuration set; please create an instance of OSCRuby::Client with configuration settings"
98
+
99
+ end
100
+
101
+ end
102
+
103
+ def attr_hash_exists_and_is_type_of(obj,key,val,class_of_value)
104
+
105
+ return obj[0][key][val].nil? || obj[0][key][val].class != class_of_value
106
+
107
+ end
108
+
109
+ def check_for_names(obj_attrs,class_name)
110
+
111
+ if obj_attrs[0]['names'].count == 0 || obj_attrs[0]['names'][0]['labelText'].nil? || obj_attrs[0]['names'][0]['language'].nil?
112
+
113
+ raise ArgumentError, "#{class_name} should at least have one name set"
114
+
115
+ end
116
+
117
+ obj_attrs
118
+
119
+ end
120
+
121
+ def check_for_parents(obj_attrs)
122
+
123
+ if !obj_attrs[0]['parent'].nil? && obj_attrs[0]['parent'].is_a?(Hash) && !obj_attrs[0]['parent'].key?('id') && !obj_attrs[0]['parent'].key?('lookupName')
124
+
125
+ obj_attrs[0].delete('parent')
126
+
127
+ end
128
+
129
+ obj_attrs
130
+
131
+ end
132
+
133
+ def check_interfaces(empty_arr)
134
+
135
+ if empty_arr[0]['adminVisibleInterfaces'].empty?
136
+
137
+ empty_arr[0].delete('adminVisibleInterfaces')
138
+
139
+ end
140
+
141
+ if empty_arr[0]['endUserVisibleInterfaces'].empty?
142
+
143
+ empty_arr[0].delete('endUserVisibleInterfaces')
144
+
145
+ end
146
+
147
+ empty_arr
148
+
149
+ end
150
+
151
+ def check_obj_for_errors(obj_to_check)
152
+
153
+ json_obj = JSON.parse(obj_to_check.body)
154
+
155
+ if !json_obj.nil? && json_obj['items'][0]['rows'].count == 0
156
+
157
+ puts obj_to_check.body
158
+
159
+ raise ArgumentError, 'There were no objects matching your query; please try again.'
160
+
161
+ end
162
+
163
+ end
164
+
165
+ end
166
+
167
+ end
168
+
169
169
  end
@@ -1,3 +1,3 @@
1
- module OSCRuby
2
- VERSION = "0.7.1"
1
+ module OSCRuby
2
+ VERSION = "1.0.2"
3
3
  end
data/lib/osc_ruby.rb CHANGED
@@ -1,11 +1,5 @@
1
- module OSCRuby; end
2
-
3
- require 'osc_ruby/client'
4
- require 'osc_ruby/connect'
5
- require 'osc_ruby/classes/service_class'
6
- require 'osc_ruby/classes/product_category_shared'
7
- require 'osc_ruby/classes/service_product'
8
- require 'osc_ruby/classes/service_category'
9
- require 'osc_ruby/classes/answer'
10
- require 'osc_ruby/classes/account'
1
+ module OSCRuby; end
2
+
3
+ require 'osc_ruby/client'
4
+ require 'osc_ruby/connect'
11
5
  require 'osc_ruby/classes/query_results'
data/osc_ruby.gemspec CHANGED
@@ -1,30 +1,29 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'osc_ruby/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = "osc_ruby"
8
- spec.version = OSCRuby::VERSION
9
- spec.authors = ["Rajan Davis"]
10
- spec.email = ["rajangdavis@gmail.com"]
11
- spec.summary = %q{Making the best of opensource and enterprise technology}
12
- spec.description = %q{An unofficial Ruby ORM on top of the Oracle Cloud Services (fka RightNow Technologies) REST API}
13
- spec.homepage = %q{https://github.com/rajangdavis/osc_ruby}
14
- spec.license = "MIT"
15
-
16
- spec.files = `git ls-files -z`.split("\x0")
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ["lib"]
20
-
21
- spec.add_development_dependency "simplecov"
22
- spec.add_development_dependency "codeclimate-test-reporter", "~> 1.0.0"
23
- spec.add_development_dependency "bundler"
24
- spec.add_development_dependency "rake", "~> 10.0"
25
- spec.add_development_dependency "rspec", "~> 3.2.0"
26
- spec.add_development_dependency "vcr", "~> 3.0.3"
27
- spec.add_development_dependency "fakeweb"
28
-
29
- spec.add_dependency 'yard'
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'osc_ruby/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "osc_ruby"
8
+ spec.version = OSCRuby::VERSION
9
+ spec.authors = ["Rajan Davis"]
10
+ spec.email = ["rajangdavis@gmail.com"]
11
+ spec.summary = %q{Making the best of opensource and enterprise technology}
12
+ spec.description = %q{An unofficial Ruby ORM on top of the Oracle Cloud Services (fka RightNow Technologies) REST API}
13
+ spec.homepage = %q{https://github.com/rajangdavis/osc_ruby}
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "simplecov"
22
+ spec.add_development_dependency "codeclimate-test-reporter", '~> 1.0', '>= 1.0.0'
23
+ spec.add_development_dependency "bundler"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency 'rspec', '~> 3.2', '>= 3.2.0'
26
+ spec.add_development_dependency 'vcr', '~> 3.0', '>= 3.0.3'
27
+ spec.add_development_dependency "fakeweb"
28
+ spec.add_development_dependency 'yard'
30
29
  end