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,118 +0,0 @@
1
- module OSCRuby
2
-
3
- class ProductCategoryShared < ServiceClass
4
-
5
- attr_accessor :names,:parent,:displayOrder,:adminVisibleInterfaces,:endUserVisibleInterfaces,:id,:lookupName,:createdTime,:updatedTime,:name
6
-
7
- def initialize(attributes = nil)
8
-
9
- @names = []
10
- @adminVisibleInterfaces = []
11
- @endUserVisibleInterfaces = []
12
-
13
- if attributes.nil?
14
-
15
- @parent = {}
16
- @displayOrder = 1
17
-
18
- else
19
-
20
- @id = attributes["id"]
21
- @lookupName = attributes["lookupName"]
22
- @createdTime = attributes["createdTime"]
23
- @updatedTime = attributes["updatedTime"]
24
- @displayOrder = attributes["displayOrder"]
25
- @name = attributes["name"]
26
- @parent = attributes["parent"]
27
-
28
- end
29
-
30
- end
31
-
32
- # Convenience Methods for making the CRUD operations nicer to use
33
-
34
- def set_attributes(response_body)
35
-
36
- self.id = response_body["id"]
37
-
38
- self.name = response_body["lookupName"]
39
-
40
- self.lookupName = response_body["lookupName"]
41
-
42
- self.displayOrder = response_body["displayOrder"]
43
-
44
- if !response_body["parent"].nil?
45
-
46
- self.parent = response_body["parent"]["links"][0]["href"].split('/').pop.to_i
47
-
48
- else
49
-
50
- self.parent = nil
51
-
52
- end
53
-
54
- end
55
-
56
- def update_attributes(updated_product)
57
-
58
- self.lookupName = updated_product.lookupName
59
-
60
- self.createdTime = updated_product.createdTime
61
-
62
- self.updatedTime = updated_product.updatedTime
63
-
64
- self.name = updated_product.name
65
-
66
- self.parent = updated_product.parent
67
-
68
- end
69
-
70
- def self.check_self(obj,is_update = false)
71
-
72
- class_name = self.to_s.split('::')[1]
73
-
74
- obj_attrs = ValidationsModule::extract_attributes(obj)
75
-
76
- obj_attrs = ValidationsModule::check_interfaces(obj_attrs)
77
-
78
- if is_update == true
79
-
80
- obj_attrs = remove_unused_new_attrs(obj_attrs)
81
-
82
- else
83
-
84
- obj_attrs = ValidationsModule::check_for_names(obj_attrs,class_name)
85
-
86
- obj_attrs = ValidationsModule::check_for_parents(obj_attrs)
87
-
88
- end
89
-
90
- obj_attrs
91
-
92
- end
93
-
94
- def self.remove_unused_new_attrs(obj_attrs)
95
-
96
- obj_attrs[0].delete('id')
97
-
98
- obj_attrs[0].delete('lookupName')
99
-
100
- obj_attrs[0].delete('createdTime')
101
-
102
- obj_attrs[0].delete('updatedTime')
103
-
104
- obj_attrs[0].delete('name')
105
-
106
- if !obj_attrs[0]['parent'].nil?
107
-
108
- obj_attrs[0].delete('parent')
109
-
110
- end
111
-
112
- obj_attrs
113
-
114
- end
115
-
116
- end
117
-
118
- end
@@ -1,6 +0,0 @@
1
- module OSCRuby
2
-
3
- class ServiceCategory < ProductCategoryShared
4
- end
5
-
6
- end
@@ -1,66 +0,0 @@
1
- require 'osc_ruby/client'
2
- require 'osc_ruby/modules/query_module'
3
- require 'osc_ruby/modules/validations_module'
4
- require 'osc_ruby/modules/class_factory_module'
5
- require 'json'
6
- require 'uri'
7
- require_relative '../../ext/string.rb'
8
-
9
- module OSCRuby
10
-
11
- class ServiceClass
12
-
13
- include QueryModule
14
- include ValidationsModule
15
- include ClassFactoryModule
16
-
17
- def self.url
18
-
19
- self.to_s.split('::')[1].camel_case_lower
20
-
21
- end
22
-
23
- def create(client,return_json = false)
24
-
25
- ClassFactoryModule.create(client,self,self.class.url,return_json)
26
-
27
- end
28
-
29
-
30
- def self.find(client,id = nil,return_json = false)
31
-
32
- ClassFactoryModule.find(client,id,url,return_json,self)
33
-
34
- end
35
-
36
-
37
- def self.all(client, return_json = false)
38
-
39
- ClassFactoryModule.all(client,url,return_json,self)
40
-
41
- end
42
-
43
-
44
- def self.where(client, query = '', return_json = false)
45
-
46
- ClassFactoryModule.where(client,query,url,return_json,self)
47
-
48
- end
49
-
50
-
51
- def update(client, return_json = false)
52
-
53
- ClassFactoryModule::update(client,self,self.class.url,return_json)
54
-
55
- end
56
-
57
-
58
- def destroy(client, return_json = false)
59
-
60
- ClassFactoryModule.destroy(client,self,self.class.url,return_json)
61
-
62
- end
63
-
64
- end
65
-
66
- end
@@ -1,6 +0,0 @@
1
- module OSCRuby
2
-
3
- class ServiceProduct < ProductCategoryShared
4
- end
5
-
6
- end
@@ -1,165 +0,0 @@
1
- require 'osc_ruby/connect'
2
- require 'osc_ruby/modules/validations_module'
3
- require 'json'
4
-
5
- module OSCRuby
6
-
7
- module ClassFactoryModule
8
-
9
- class << self
10
-
11
- def new_from_fetch(attributes,class_name,custom_or_nested = nil)
12
-
13
- ValidationsModule.check_attributes(attributes)
14
-
15
- class_name.new(attributes)
16
-
17
- end
18
-
19
- def create(client,obj,resource_uri,return_json)
20
-
21
- ValidationsModule::check_client(client)
22
-
23
- final_json = obj.class.check_self(obj)
24
-
25
- resource = URI.escape(resource_uri)
26
-
27
- response = QueryModule::create(client,resource,final_json)
28
-
29
- response_body = JSON.parse(response.body)
30
-
31
- if return_json == true
32
-
33
- puts response.body
34
-
35
- end
36
-
37
- if obj.class.respond_to? :set_attributes
38
- obj.class.new(response_body)
39
- else
40
- obj.set_attributes(response_body)
41
- end
42
-
43
- end
44
-
45
- def find(client,id,obj_query,return_json,class_name,custom_or_nested = nil)
46
-
47
- ValidationsModule::check_client(client)
48
-
49
- ValidationsModule::check_for_id(id)
50
-
51
- url = "queryResults/?query=select * from #{obj_query} where id = #{id}"
52
-
53
- resource = URI.escape(url)
54
-
55
- class_json = QueryModule::find(client,resource)
56
-
57
- if return_json == true
58
-
59
- class_json
60
-
61
- else
62
-
63
- class_json_final = JSON.parse(class_json)
64
-
65
- ClassFactoryModule::new_from_fetch(class_json_final[0],class_name,custom_or_nested = nil)
66
-
67
- end
68
-
69
- end
70
-
71
- def all(client,obj_query,return_json,class_name,custom_or_nested = nil)
72
-
73
- ValidationsModule::check_client(client)
74
-
75
- resource = URI.escape("queryResults/?query=select * from #{obj_query}")
76
-
77
- object_json = QueryModule::find(client,resource)
78
-
79
- ClassFactoryModule::instantiate_multiple_objects(return_json, object_json, class_name,custom_or_nested = nil)
80
-
81
- end
82
-
83
- def where(client,query,object_in_query,return_json,class_name,custom_or_nested = nil)
84
-
85
- ValidationsModule::check_client(client)
86
-
87
- ValidationsModule::check_query(query,'where')
88
-
89
- @query = URI.escape("queryResults/?query=select * from #{object_in_query} where #{query}")
90
-
91
- object_json = QueryModule::find(client,@query)
92
-
93
- ClassFactoryModule::instantiate_multiple_objects(return_json, object_json, class_name,custom_or_nested = nil)
94
-
95
- end
96
-
97
- def update(client,obj,resource_uri,return_json)
98
-
99
- ValidationsModule::check_client(client)
100
-
101
- ValidationsModule::check_object_for_id(obj,obj.class)
102
-
103
- final_json = obj.class.check_self(obj,true)
104
-
105
- resource = URI.escape("#{resource_uri}/#{obj.id}")
106
-
107
- response = QueryModule::update(client,resource,final_json)
108
-
109
- if response.code.to_i == 200 && return_json == false
110
-
111
- updated_obj = obj.class.find(client,obj.id)
112
-
113
- obj.update_attributes(updated_obj)
114
-
115
- elsif return_json == true
116
-
117
- response.body
118
-
119
- end
120
-
121
- end
122
-
123
- def destroy(client,obj,resource_uri,return_json)
124
-
125
- ValidationsModule::check_client(client)
126
-
127
- ValidationsModule::check_object_for_id(obj,obj.class)
128
-
129
- resource = URI.escape("/#{resource_uri}/#{obj.id}")
130
-
131
- response = QueryModule::destroy(client,resource)
132
-
133
- if response.code.to_i == 200 && return_json == false
134
-
135
- nil
136
-
137
- elsif return_json == true
138
-
139
- response.body
140
-
141
- end
142
-
143
- end
144
-
145
- def instantiate_multiple_objects(return_json, object_json, class_name,custom_or_nested = nil)
146
-
147
- if return_json == true
148
-
149
- object_json
150
-
151
- else
152
-
153
- object_json_final = JSON.parse(object_json)
154
-
155
- object_json_final.map { |attributes| ClassFactoryModule::new_from_fetch(attributes,class_name,custom_or_nested = nil) }
156
-
157
- end
158
-
159
- end
160
-
161
- end
162
-
163
- end
164
-
165
- end
@@ -1,10 +0,0 @@
1
- module OSCRuby
2
- module NestedResourceModule
3
- class << self
4
- def get_resource(rn_client,originator,resource)
5
- puts "#{originator.class} has an id of #{originator.id}"
6
- resource.where(rn_client,"id < 100")
7
- end
8
- end
9
- end
10
- end