leantesting 1.0.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 (65) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -2
  3. data/leantesting.gemspec +1 -1
  4. data/lib/BaseClass/APIRequest.rb +154 -151
  5. data/lib/BaseClass/Entity.rb +25 -24
  6. data/lib/BaseClass/EntityHandler.rb +151 -149
  7. data/lib/BaseClass/EntityList.rb +163 -161
  8. data/lib/Entity/Bug/Bug.rb +10 -8
  9. data/lib/Entity/Bug/BugAttachment.rb +7 -5
  10. data/lib/Entity/Bug/BugComment.rb +7 -5
  11. data/lib/Entity/Platform/PlatformBrowser.rb +9 -7
  12. data/lib/Entity/Platform/PlatformBrowserVersion.rb +7 -5
  13. data/lib/Entity/Platform/PlatformDevice.rb +7 -5
  14. data/lib/Entity/Platform/PlatformOS.rb +9 -7
  15. data/lib/Entity/Platform/PlatformOSVersion.rb +7 -5
  16. data/lib/Entity/Platform/PlatformType.rb +9 -7
  17. data/lib/Entity/Project/Project.rb +24 -22
  18. data/lib/Entity/Project/ProjectBugScheme.rb +7 -5
  19. data/lib/Entity/Project/ProjectSection.rb +7 -5
  20. data/lib/Entity/Project/ProjectUser.rb +7 -5
  21. data/lib/Entity/Project/ProjectVersion.rb +7 -5
  22. data/lib/Entity/User/UserOrganization.rb +7 -5
  23. data/lib/Exception/BaseException/SDKException.rb +15 -13
  24. data/lib/Exception/SDKBadJSONResponseException.rb +13 -11
  25. data/lib/Exception/SDKDuplicateRequestException.rb +15 -13
  26. data/lib/Exception/SDKErrorResponseException.rb +12 -10
  27. data/lib/Exception/SDKIncompleteRequestException.rb +15 -13
  28. data/lib/Exception/SDKInvalidArgException.rb +13 -11
  29. data/lib/Exception/SDKMissingArgException.rb +13 -11
  30. data/lib/Exception/SDKUnexpectedResponseException.rb +13 -11
  31. data/lib/Exception/SDKUnsupportedRequestException.rb +15 -13
  32. data/lib/Handler/Attachment/AttachmentsHandler.rb +14 -12
  33. data/lib/Handler/Auth/OAuth2Handler.rb +102 -100
  34. data/lib/Handler/Bug/BugAttachmentsHandler.rb +44 -42
  35. data/lib/Handler/Bug/BugCommentsHandler.rb +16 -14
  36. data/lib/Handler/Bug/BugsHandler.rb +53 -51
  37. data/lib/Handler/Platform/PlatformBrowserVersionsHandler.rb +16 -14
  38. data/lib/Handler/Platform/PlatformBrowsersHandler.rb +18 -16
  39. data/lib/Handler/Platform/PlatformDevicesHandler.rb +9 -7
  40. data/lib/Handler/Platform/PlatformHandler.rb +20 -18
  41. data/lib/Handler/Platform/PlatformOSHandler.rb +18 -16
  42. data/lib/Handler/Platform/PlatformOSVersionsHandler.rb +16 -14
  43. data/lib/Handler/Platform/PlatformTypeDevicesHandler.rb +16 -14
  44. data/lib/Handler/Platform/PlatformTypesHandler.rb +17 -15
  45. data/lib/Handler/Project/ProjectBugReproducibilitySchemeHandler.rb +16 -14
  46. data/lib/Handler/Project/ProjectBugSeveritySchemeHandler.rb +16 -14
  47. data/lib/Handler/Project/ProjectBugStatusSchemeHandler.rb +16 -14
  48. data/lib/Handler/Project/ProjectBugTypeSchemeHandler.rb +16 -14
  49. data/lib/Handler/Project/ProjectBugsHandler.rb +55 -53
  50. data/lib/Handler/Project/ProjectSectionsHandler.rb +30 -28
  51. data/lib/Handler/Project/ProjectUsersHandler.rb +16 -14
  52. data/lib/Handler/Project/ProjectVersionsHandler.rb +30 -28
  53. data/lib/Handler/Project/ProjectsHandler.rb +34 -32
  54. data/lib/Handler/User/UserHandler.rb +12 -10
  55. data/lib/Handler/User/UserOrganizationsHandler.rb +12 -10
  56. data/tests/APIRequestTest.rb +33 -33
  57. data/tests/BaseClassesTest.rb +28 -28
  58. data/tests/ClientTest.rb +7 -7
  59. data/tests/EntitiesTest.rb +31 -31
  60. data/tests/EntityListTest.rb +13 -13
  61. data/tests/ExceptionsTest.rb +15 -15
  62. data/tests/HandlersRequestsTest.rb +37 -37
  63. data/tests/MockRequestsTest.rb +48 -48
  64. data/tests/OAuth2HandlerTest.rb +19 -19
  65. metadata +2 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0650b9de0f50228ddda2c8821f73fd84f0901ebb
4
- data.tar.gz: 8377c2da73980950c3eee06b0d8f0ca7255196b7
3
+ metadata.gz: 6af9018276f7f7bdef8db3bcdbd4762d365944ed
4
+ data.tar.gz: a40e97d7dd8fff881555db24963bb22c14b7bf26
5
5
  SHA512:
6
- metadata.gz: b86cfbfd27603d0b002d0011bba8f09c7f620b2e61691cc89c4c6eb97dcfc801cb698ae5fc553fbb673e45cdc1382d6ceb70e41dead27abdd00ef9d518c746e7
7
- data.tar.gz: e63dbe3ff2aea21ef8a013d79dc4fe66375744d87d04f562baf7a1174e5d610446ce83dec7d09e8d9ae4d93424554db3de246be9034559486acd682e27026504
6
+ metadata.gz: 2021d0c2dbffa0179f4145e6f20ca1418b5d88abdf1e70fea7dde160564e543843d4ca70f9fa6f2dfd0848fc629059f21c36fb048d21f466450d4e98a831c60f
7
+ data.tar.gz: 265060dfd7d512d97983b0a82655bb3d11577f0ced7403e2a87089813c8c21d9f4a9c318e68f2398d49b5dfabf3f6826275aaf0fbc71d08e3190d77bbb69c857
data/README.md CHANGED
@@ -39,7 +39,7 @@ projects = leantesting.projects.all()
39
39
  bugs = leantesting.projects.find(123).bugs.all()
40
40
  ```
41
41
 
42
- ----
42
+ ## Methods
43
43
 
44
44
  - Get Current **Token**
45
45
  ```ruby
@@ -347,4 +347,4 @@ Install dependencies as mentioned above, then you can run the test suite:
347
347
 
348
348
  ```bash
349
349
  rake test
350
- ```
350
+ ```
data/leantesting.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'leantesting'
3
- s.version = '1.0.1'
3
+ s.version = '1.0.2'
4
4
  s.date = '2015-11-20'
5
5
  s.platform = Gem::Platform::RUBY
6
6
  s.summary = 'Lean Testing Ruby SDK'
@@ -3,193 +3,196 @@
3
3
  #
4
4
  # An APIRequest's parameters can be modified on demand and can be executed multiple times for the same instance.
5
5
  #
6
- class APIRequest
7
-
8
- #
9
- # Constructs API request definition.
10
- #
11
- # Arguments:
12
- # origin Client -- Originating client reference
13
- # endpoint String -- API endpoint
14
- # method String -- Method for cURL call - supports GET, POST, PUT or DELETE only
15
- # opts Hash -- (optional) Additional options to pass to request.
16
- # Request parameters (if any) must bep assed here.
17
- #
18
- # Exceptions:
19
- # SDKInvalidArgException if method is non-string.
20
- # SDKInvalidArgException if unsupported method is provided.
21
- # SDKInvalidArgException if endpoint is non-string.
22
- # SDKInvalidArgException if opts param is not a hash.
23
- #
24
- def initialize(origin, endpoint, method, opts = nil)
25
- @default_ops = { # Basic support for extended opts
26
- 'base_uri' => 'https://api.leantesting.com', # assumed default for API base
27
- 'form_data' => false, # sets content type to multipart/form-data if true
28
- 'params' => {} # params to be pased in request
29
- }
30
-
31
- if !opts
32
- opts = {}
33
- end
34
6
 
35
- if !method.is_a? String
36
- raise SDKInvalidArgException, '`method` must be a string'
37
- elsif !['GET', 'POST', 'PUT', 'DELETE'].include? method
38
- raise SDKInvalidArgException, 'unsupported ' + method + ' `method`'
39
- elsif !endpoint.is_a? String
40
- raise SDKInvalidArgException, '`endpoint` must be a string'
41
- elsif !opts.is_a? Hash
42
- raise SDKInvalidArgException, '`opts` must be a hash'
43
- end
7
+ module LeanTesting
8
+ class APIRequest
9
+
10
+ #
11
+ # Constructs API request definition.
12
+ #
13
+ # Arguments:
14
+ # origin Client -- Originating client reference
15
+ # endpoint String -- API endpoint
16
+ # method String -- Method for cURL call - supports GET, POST, PUT or DELETE only
17
+ # opts Hash -- (optional) Additional options to pass to request.
18
+ # Request parameters (if any) must bep assed here.
19
+ #
20
+ # Exceptions:
21
+ # SDKInvalidArgException if method is non-string.
22
+ # SDKInvalidArgException if unsupported method is provided.
23
+ # SDKInvalidArgException if endpoint is non-string.
24
+ # SDKInvalidArgException if opts param is not a hash.
25
+ #
26
+ def initialize(origin, endpoint, method, opts = nil)
27
+ @default_ops = { # Basic support for extended opts
28
+ 'base_uri' => 'https://api.leantesting.com', # assumed default for API base
29
+ 'form_data' => false, # sets content type to multipart/form-data if true
30
+ 'params' => {} # params to be pased in request
31
+ }
32
+
33
+ if !opts
34
+ opts = {}
35
+ end
44
36
 
45
- @opts = @default_ops.clone
46
- self.updateOpts(opts)
37
+ if !method.is_a? String
38
+ raise SDKInvalidArgException, '`method` must be a string'
39
+ elsif !['GET', 'POST', 'PUT', 'DELETE'].include? method
40
+ raise SDKInvalidArgException, 'unsupported ' + method + ' `method`'
41
+ elsif !endpoint.is_a? String
42
+ raise SDKInvalidArgException, '`endpoint` must be a string'
43
+ elsif !opts.is_a? Hash
44
+ raise SDKInvalidArgException, '`opts` must be a hash'
45
+ end
47
46
 
48
- @origin = origin
49
- @endpoint = endpoint
50
- @method = method
51
- end
47
+ @opts = @default_ops.clone
48
+ self.updateOpts(opts)
52
49
 
53
- #
54
- # Updates options list inside API request definition.
55
- #
56
- # Arguments:
57
- # opts Hash -- (optional) Additional options array to merge with previous option values
58
- #
59
- # Exceptions:
60
- # SDKInvalidArgException if opts param is not a hash.
61
- # SDKInvalidArgException if provided parameter list is non-hash parameter.
62
- #
63
- def updateOpts(opts = nil)
64
- if !opts
65
- opts = {}
50
+ @origin = origin
51
+ @endpoint = endpoint
52
+ @method = method
66
53
  end
67
54
 
68
- if !opts.is_a? Hash
69
- raise SDKInvalidArgException, '`opts` must be a hash'
70
- elsif opts.has_key? 'params' && !opts['params'].is_a?(Hash)
71
- raise SDKInvalidArgException '`opts[\'params\']` must be a hash'
55
+ #
56
+ # Updates options list inside API request definition.
57
+ #
58
+ # Arguments:
59
+ # opts Hash -- (optional) Additional options array to merge with previous option values
60
+ #
61
+ # Exceptions:
62
+ # SDKInvalidArgException if opts param is not a hash.
63
+ # SDKInvalidArgException if provided parameter list is non-hash parameter.
64
+ #
65
+ def updateOpts(opts = nil)
66
+ if !opts
67
+ opts = {}
68
+ end
69
+
70
+ if !opts.is_a? Hash
71
+ raise SDKInvalidArgException, '`opts` must be a hash'
72
+ elsif opts.has_key? 'params' && !opts['params'].is_a?(Hash)
73
+ raise SDKInvalidArgException '`opts[\'params\']` must be a hash'
74
+ end
75
+
76
+ @opts.merge!(opts)
72
77
  end
73
78
 
74
- @opts.merge!(opts)
75
- end
79
+ #
80
+ # Executes cURL call as per current API definition state.
81
+ #
82
+ # Returns:
83
+ # String -- Returns resulting data response from server (including errors and inconsistencies)
84
+ #
85
+ def call
76
86
 
77
- #
78
- # Executes cURL call as per current API definition state.
79
- #
80
- # Returns:
81
- # String -- Returns resulting data response from server (including errors and inconsistencies)
82
- #
83
- def call
87
+ ch = Curl::Easy.new
84
88
 
85
- ch = Curl::Easy.new
89
+ callUrl = @opts['base_uri'] + @endpoint
86
90
 
87
- callUrl = @opts['base_uri'] + @endpoint
91
+ if @origin.getCurrentToken.is_a? String
92
+ ch.headers['Authorization'] = 'Bearer ' + @origin.getCurrentToken
93
+ end
88
94
 
89
- if @origin.getCurrentToken.is_a? String
90
- ch.headers['Authorization'] = 'Bearer ' + @origin.getCurrentToken
91
- end
95
+ ch.url = callUrl
92
96
 
93
- ch.url = callUrl
97
+ ch.header_in_body = false
94
98
 
95
- ch.header_in_body = false
99
+ case @method
100
+ when 'GET'
101
+ callUrl += '?' + Curl::postalize(@opts['params'])
102
+ ch.url = callUrl
96
103
 
97
- case @method
98
- when 'GET'
99
- callUrl += '?' + Curl::postalize(@opts['params'])
100
- ch.url = callUrl
104
+ ch.http_get
105
+ when 'POST'
106
+ if @opts['form_data'] == true && (@opts.has_key? 'file_path')
107
+ ch.headers['Content-Type'] = 'multipart/form-data'
108
+ ch.multipart_form_post = true
101
109
 
102
- ch.http_get
103
- when 'POST'
104
- if @opts['form_data'] == true && (@opts.has_key? 'file_path')
105
- ch.headers['Content-Type'] = 'multipart/form-data'
106
- ch.multipart_form_post = true
110
+ ch.http_post(Curl::PostField.file('file', @opts['file_path']))
111
+ else
112
+ jsonData = JSON.generate(@opts['params'])
107
113
 
108
- ch.http_post(Curl::PostField.file('file', @opts['file_path']))
109
- else
114
+ ch.headers['Content-Type'] = 'application/json'
115
+ ch.headers['Content-Length'] = jsonData.length
116
+
117
+ ch.http_post(jsonData)
118
+ end
119
+ when 'PUT'
110
120
  jsonData = JSON.generate(@opts['params'])
111
121
 
112
122
  ch.headers['Content-Type'] = 'application/json'
113
123
  ch.headers['Content-Length'] = jsonData.length
114
124
 
115
- ch.http_post(jsonData)
125
+ ch.http_put(jsonData)
126
+ when 'DELETE'
127
+ ch.http_delete
116
128
  end
117
- when 'PUT'
118
- jsonData = JSON.generate(@opts['params'])
119
129
 
120
- ch.headers['Content-Type'] = 'application/json'
121
- ch.headers['Content-Length'] = jsonData.length
130
+ curlData = ch.body_str
131
+ curlStatus = ch.status.to_i()
132
+
133
+ ch.close
134
+ ch = nil
122
135
 
123
- ch.http_put(jsonData)
124
- when 'DELETE'
125
- ch.http_delete
136
+ {
137
+ 'data' => curlData,
138
+ 'status' => curlStatus
139
+ }
126
140
  end
127
141
 
128
- curlData = ch.body_str
129
- curlStatus = ch.status.to_i()
142
+ #
143
+ # Does cURL data interpretation
144
+ #
145
+ # Exceptions:
146
+ # SDKErrorResponseException if the remote response is an error.
147
+ # A server response is interpreted as an error if obtained status code differs from expected status code.
148
+ # Expected status codes are `200 OK` for GET/POST/PUT, `204 No Content` for DELETE.
149
+ # SDKBadJSONResponseException if the remote response contains erronated or invalid JSON contents
150
+ #
151
+ # Returns:
152
+ # Hash -- In case of successful request, a JSON decoded object is returned.
153
+ # Boolean -- If a DELETE request is issued, returns true if call is successful (exception otherwise).
154
+ #
155
+ def exec
156
+ if @origin.debugReturn && @origin.debugReturn.has_key?('data') && @origin.debugReturn.has_key?('status')
157
+
158
+ curlData = @origin.debugReturn['data']
159
+ curlStatus = @origin.debugReturn['status']
130
160
 
131
- ch.close
132
- ch = nil
161
+ else
133
162
 
134
- {
135
- 'data' => curlData,
136
- 'status' => curlStatus
137
- }
138
- end
163
+ callReturn = call
164
+ curlData = callReturn['data']
165
+ curlStatus = callReturn['status']
139
166
 
140
- #
141
- # Does cURL data interpretation
142
- #
143
- # Exceptions:
144
- # SDKErrorResponseException if the remote response is an error.
145
- # A server response is interpreted as an error if obtained status code differs from expected status code.
146
- # Expected status codes are `200 OK` for GET/POST/PUT, `204 No Content` for DELETE.
147
- # SDKBadJSONResponseException if the remote response contains erronated or invalid JSON contents
148
- #
149
- # Returns:
150
- # Hash -- In case of successful request, a JSON decoded object is returned.
151
- # Boolean -- If a DELETE request is issued, returns true if call is successful (exception otherwise).
152
- #
153
- def exec
154
- if @origin.debugReturn && @origin.debugReturn.has_key?('data') && @origin.debugReturn.has_key?('status')
155
-
156
- curlData = @origin.debugReturn['data']
157
- curlStatus = @origin.debugReturn['status']
158
-
159
- else
160
-
161
- callReturn = call
162
- curlData = callReturn['data']
163
- curlStatus = callReturn['status']
167
+ end
164
168
 
165
- end
169
+ if @method == 'DELETE'
170
+ expectedHTTPStatus = 204
171
+ else
172
+ expectedHTTPStatus = 200
173
+ end
166
174
 
167
- if @method == 'DELETE'
168
- expectedHTTPStatus = 204
169
- else
170
- expectedHTTPStatus = 200
171
- end
175
+ if curlStatus != expectedHTTPStatus
176
+ raise SDKErrorResponseException, curlStatus.to_s() + ' - ' + curlData
177
+ end
172
178
 
173
- if curlStatus != expectedHTTPStatus
174
- raise SDKErrorResponseException, curlStatus.to_s() + ' - ' + curlData
175
- end
179
+ if @method == 'DELETE' # if DELETE request, expect no output
180
+ return true
181
+ end
176
182
 
177
- if @method == 'DELETE' # if DELETE request, expect no output
178
- return true
179
- end
183
+ begin
184
+ jsonData = JSON.parse(curlData) # normally, expect JSON qualified output
185
+ rescue JSON::ParserError
186
+ raise SDKBadJSONResponseException, curlData
187
+ end
180
188
 
181
- begin
182
- jsonData = JSON.parse(curlData) # normally, expect JSON qualified output
183
- rescue JSON::ParserError
184
- raise SDKBadJSONResponseException, curlData
185
- end
189
+ if jsonData.length.zero?
190
+ raise SDKUnexpectedResponseException, 'Empty object received'
191
+ end
186
192
 
187
- if jsonData.length.zero?
188
- raise SDKUnexpectedResponseException, 'Empty object received'
189
- end
193
+ return jsonData
190
194
 
191
- return jsonData
195
+ end
192
196
 
193
197
  end
194
-
195
- end
198
+ end
@@ -1,33 +1,34 @@
1
1
  #
2
2
  # Represents a single Entity. All remote responses are decoded and parsed into one or more Entities.
3
3
  #
4
+ module LeanTesting
5
+ class Entity
6
+ attr_accessor :data
4
7
 
5
- class Entity
6
- attr_accessor :data
8
+ @origin = nil # Reference to originating Client instance
9
+ @data = nil # Internal entity object data
7
10
 
8
- @origin = nil # Reference to originating Client instance
9
- @data = nil # Internal entity object data
11
+ #
12
+ # Constructs an Entity instance
13
+ #
14
+ # Arguments:
15
+ # origin Client -- Original client instance reference
16
+ # data Hash -- Data to be contained in the new Entity. Must be non-empty.
17
+ #
18
+ # Exceptions:
19
+ # SDKInvalidArgException if provided data param is not a hash.
20
+ # SDKInvalidArgException if provided data param is empty. Entities cannot be empty.
21
+ #
22
+ def initialize(origin, data)
23
+ if !data.is_a? Hash
24
+ raise SDKInvalidArgException, '`data` must be a hash'
25
+ elsif data.length.zero?
26
+ raise SDKInvalidArgException, '`data` must be non-empty'
27
+ end
10
28
 
11
- #
12
- # Constructs an Entity instance
13
- #
14
- # Arguments:
15
- # origin Client -- Original client instance reference
16
- # data Hash -- Data to be contained in the new Entity. Must be non-empty.
17
- #
18
- # Exceptions:
19
- # SDKInvalidArgException if provided data param is not a hash.
20
- # SDKInvalidArgException if provided data param is empty. Entities cannot be empty.
21
- #
22
- def initialize(origin, data)
23
- if !data.is_a? Hash
24
- raise SDKInvalidArgException, '`data` must be a hash'
25
- elsif data.length.zero?
26
- raise SDKInvalidArgException, '`data` must be non-empty'
29
+ @origin = origin
30
+ @data = data
27
31
  end
28
32
 
29
- @origin = origin
30
- @data = data
31
33
  end
32
-
33
- end
34
+ end
@@ -8,176 +8,178 @@
8
8
  # delete(id) <=> `Delete an Entity`
9
9
  # update(id, fields) <=> `Update an Entity`
10
10
  #
11
- class EntityHandler
12
-
13
- #
14
- # Constructs an EntityHandler instance
15
- #
16
- # Keyword arguments:
17
- # origin Client -- Originating client reference
18
- #
19
- def initialize(origin)
20
- @origin = origin # Reference to originating Client instance
21
- end
22
-
23
- #
24
- # Function definition for creating a new entity. Base function checks for invalid parameters.
25
- #
26
- # Keyword arguments:
27
- # fields Hash -- Non-empty hash consisting of entity data to send for adding
28
- #
29
- # Exceptions:
30
- # SDKInvalidArgException if provided fields param is not a hash.
31
- # SDKInvalidArgException if provided fields param is empty.
32
- #
33
- def create(fields)
34
- if !fields.is_a? Hash
35
- raise SDKInvalidArgException, '`fields` must be a hash'
36
- elsif fields.length.zero?
37
- raise SDKInvalidArgException, '`fields` must be non-empty'
11
+ module LeanTesting
12
+ class EntityHandler
13
+
14
+ #
15
+ # Constructs an EntityHandler instance
16
+ #
17
+ # Keyword arguments:
18
+ # origin Client -- Originating client reference
19
+ #
20
+ def initialize(origin)
21
+ @origin = origin # Reference to originating Client instance
38
22
  end
39
- end
40
23
 
41
- #
42
- # Function definition for listing all entities. Base function checks for invalid parameters.
43
- #
44
- # Keyword arguments:
45
- # filters Hash -- (optional) Filters to apply to restrict listing. Currently supported: limit, page
46
- #
47
- # Exceptions:
48
- # SDKInvalidArgException if provided filters param is not a hash.
49
- # SDKInvalidArgException if invalid filter value found in filters hash.
50
- #
51
- def all(filters = nil)
52
- if !filters
53
- filters = {}
24
+ #
25
+ # Function definition for creating a new entity. Base function checks for invalid parameters.
26
+ #
27
+ # Keyword arguments:
28
+ # fields Hash -- Non-empty hash consisting of entity data to send for adding
29
+ #
30
+ # Exceptions:
31
+ # SDKInvalidArgException if provided fields param is not a hash.
32
+ # SDKInvalidArgException if provided fields param is empty.
33
+ #
34
+ def create(fields)
35
+ if !fields.is_a? Hash
36
+ raise SDKInvalidArgException, '`fields` must be a hash'
37
+ elsif fields.length.zero?
38
+ raise SDKInvalidArgException, '`fields` must be non-empty'
39
+ end
54
40
  end
55
41
 
56
- if !filters.is_a? Hash
57
- raise SDKInvalidArgException, '`filters` must be a hash'
58
- else
59
- filters.each do |k,|
60
- if !['include', 'limit', 'page'].include? k
61
- raise SDKInvalidArgException, 'unsupported ' + k + ' for `filters`'
42
+ #
43
+ # Function definition for listing all entities. Base function checks for invalid parameters.
44
+ #
45
+ # Keyword arguments:
46
+ # filters Hash -- (optional) Filters to apply to restrict listing. Currently supported: limit, page
47
+ #
48
+ # Exceptions:
49
+ # SDKInvalidArgException if provided filters param is not a hash.
50
+ # SDKInvalidArgException if invalid filter value found in filters hash.
51
+ #
52
+ def all(filters = nil)
53
+ if !filters
54
+ filters = {}
55
+ end
56
+
57
+ if !filters.is_a? Hash
58
+ raise SDKInvalidArgException, '`filters` must be a hash'
59
+ else
60
+ filters.each do |k,|
61
+ if !['include', 'limit', 'page'].include? k
62
+ raise SDKInvalidArgException, 'unsupported ' + k + ' for `filters`'
63
+ end
62
64
  end
63
65
  end
64
- end
65
66
 
66
- end
67
+ end
67
68
 
68
- #
69
- # Function definition for retrieving an existing entity. Base function checks for invalid parameters.
70
- #
71
- # Keyword arguments:
72
- # id Fixnum -- ID field to look for in the entity collection
73
- #
74
- # Exceptions:
75
- # SDKInvalidArgException if provided id param is not an integer.
76
- #
77
- def find(id)
78
- if !id.is_a? Fixnum
79
- raise SDKInvalidArgException, '`id` must be of type Fixnum'
69
+ #
70
+ # Function definition for retrieving an existing entity. Base function checks for invalid parameters.
71
+ #
72
+ # Keyword arguments:
73
+ # id Fixnum -- ID field to look for in the entity collection
74
+ #
75
+ # Exceptions:
76
+ # SDKInvalidArgException if provided id param is not an integer.
77
+ #
78
+ def find(id)
79
+ if !id.is_a? Fixnum
80
+ raise SDKInvalidArgException, '`id` must be of type Fixnum'
81
+ end
80
82
  end
81
- end
82
83
 
83
- #
84
- # Function definition for deleting an existing entity. Base function checks for invalid parameters.
85
- #
86
- # Keyword arguments:
87
- # id Fixnum -- ID field of entity to delete in the entity collection
88
- #
89
- # Exceptions:
90
- # SDKInvalidArgException if provided id param is not an integer.
91
- #
92
- def delete(id)
93
- if !id.is_a? Fixnum
94
- raise SDKInvalidArgException, '`id` must be of type Fixnum'
84
+ #
85
+ # Function definition for deleting an existing entity. Base function checks for invalid parameters.
86
+ #
87
+ # Keyword arguments:
88
+ # id Fixnum -- ID field of entity to delete in the entity collection
89
+ #
90
+ # Exceptions:
91
+ # SDKInvalidArgException if provided id param is not an integer.
92
+ #
93
+ def delete(id)
94
+ if !id.is_a? Fixnum
95
+ raise SDKInvalidArgException, '`id` must be of type Fixnum'
96
+ end
95
97
  end
96
- end
97
98
 
98
- #
99
- # Function definition for updating an existing entity. Base function checks for invalid parameters.
100
- #
101
- # Keyword arguments:
102
- # id Fixnum -- ID field of entity to update in the entity collection
103
- # fields Hash -- Non-empty dictionary consisting of entity data to send for update
104
- #
105
- # Exceptions:
106
- # SDKInvalidArgException if provided id param is not an integer.
107
- # SDKInvalidArgException if provided fields param is not a hash.
108
- # SDKInvalidArgException if provided fields param is empty.
109
- #
110
- def update(id, fields)
111
- if !id.is_a? Fixnum
112
- raise SDKInvalidArgException, '`id` must be of type Fixnum'
113
- elsif !fields.is_a? Hash
114
- raise SDKInvalidArgException, '`fields` must be a hash'
115
- elsif fields.length.zero?
116
- raise SDKInvalidArgException, '`fields` must be non-empty'
99
+ #
100
+ # Function definition for updating an existing entity. Base function checks for invalid parameters.
101
+ #
102
+ # Keyword arguments:
103
+ # id Fixnum -- ID field of entity to update in the entity collection
104
+ # fields Hash -- Non-empty dictionary consisting of entity data to send for update
105
+ #
106
+ # Exceptions:
107
+ # SDKInvalidArgException if provided id param is not an integer.
108
+ # SDKInvalidArgException if provided fields param is not a hash.
109
+ # SDKInvalidArgException if provided fields param is empty.
110
+ #
111
+ def update(id, fields)
112
+ if !id.is_a? Fixnum
113
+ raise SDKInvalidArgException, '`id` must be of type Fixnum'
114
+ elsif !fields.is_a? Hash
115
+ raise SDKInvalidArgException, '`fields` must be a hash'
116
+ elsif fields.length.zero?
117
+ raise SDKInvalidArgException, '`fields` must be non-empty'
118
+ end
117
119
  end
118
- end
119
120
 
120
- private
121
-
122
- #
123
- # Helper function that enforces a structure based on a supported table:
124
- # - Forces use of REQUIRED fields
125
- # - Detects duplicate fields
126
- # - Detects unsupported fields
127
- #
128
- # Keyword arguments:
129
- # obj Hash -- Hash to be enforced
130
- # supports Hash -- Support table consisting of REQUIRED and OPTIONAL keys to be used in enforcing
131
- #
132
- # Exceptions:
133
- # SDKUnsupportedRequestException if unsupported fields are found
134
- # SDKIncompleteRequestException if any required field is missing
135
- # SDKDuplicateRequestException if any duplicate field is found
136
- #
137
- def enforce(obj, supports)
138
- sall = [] # All supported keys
139
- sreq = [] # Mandatory supported keys
140
-
141
- socc = supports.clone # Key use occurances
142
-
143
- unsup = [] # Unsupported key list
144
- dupl = [] # Duplicate key list
145
- mreq = [] # Missing required keys
146
-
147
- supports.each do |sk, sv|
148
- if sv == true
149
- sreq.push(sk)
121
+ private
122
+
123
+ #
124
+ # Helper function that enforces a structure based on a supported table:
125
+ # - Forces use of REQUIRED fields
126
+ # - Detects duplicate fields
127
+ # - Detects unsupported fields
128
+ #
129
+ # Keyword arguments:
130
+ # obj Hash -- Hash to be enforced
131
+ # supports Hash -- Support table consisting of REQUIRED and OPTIONAL keys to be used in enforcing
132
+ #
133
+ # Exceptions:
134
+ # SDKUnsupportedRequestException if unsupported fields are found
135
+ # SDKIncompleteRequestException if any required field is missing
136
+ # SDKDuplicateRequestException if any duplicate field is found
137
+ #
138
+ def enforce(obj, supports)
139
+ sall = [] # All supported keys
140
+ sreq = [] # Mandatory supported keys
141
+
142
+ socc = supports.clone # Key use occurances
143
+
144
+ unsup = [] # Unsupported key list
145
+ dupl = [] # Duplicate key list
146
+ mreq = [] # Missing required keys
147
+
148
+ supports.each do |sk, sv|
149
+ if sv == true
150
+ sreq.push(sk)
151
+ end
152
+
153
+ sall.push(sk)
154
+ socc[sk] = 0
150
155
  end
151
156
 
152
- sall.push(sk)
153
- socc[sk] = 0
154
- end
157
+ obj.each do |k,|
158
+ if sall.include? k
159
+ socc[k] += 1
160
+ else
161
+ unsup.push(k)
162
+ end
163
+ end
155
164
 
156
- obj.each do |k,|
157
- if sall.include? k
158
- socc[k] += 1
159
- else
160
- unsup.push(k)
165
+ socc.each do |ok, ov|
166
+ if ov > 1
167
+ dupl.push(ok)
168
+ elsif ov == 0 && sreq.include?(ok)
169
+ mreq.push(ok)
170
+ end
161
171
  end
162
- end
163
172
 
164
- socc.each do |ok, ov|
165
- if ov > 1
166
- dupl.push(ok)
167
- elsif ov == 0 && sreq.include?(ok)
168
- mreq.push(ok)
173
+ if unsup.length.nonzero?
174
+ raise SDKUnsupportedRequestException, unsup
175
+ elsif mreq.length.nonzero?
176
+ raise SDKIncompleteRequestException, mreq
177
+ elsif dupl.length.nonzero?
178
+ raise SDKDuplicateRequestException, dupl
169
179
  end
170
- end
171
180
 
172
- if unsup.length.nonzero?
173
- raise SDKUnsupportedRequestException, unsup
174
- elsif mreq.length.nonzero?
175
- raise SDKIncompleteRequestException, mreq
176
- elsif dupl.length.nonzero?
177
- raise SDKDuplicateRequestException, dupl
181
+ true
178
182
  end
179
183
 
180
- true
181
184
  end
182
-
183
- end
185
+ end