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.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/leantesting.gemspec +1 -1
- data/lib/BaseClass/APIRequest.rb +154 -151
- data/lib/BaseClass/Entity.rb +25 -24
- data/lib/BaseClass/EntityHandler.rb +151 -149
- data/lib/BaseClass/EntityList.rb +163 -161
- data/lib/Entity/Bug/Bug.rb +10 -8
- data/lib/Entity/Bug/BugAttachment.rb +7 -5
- data/lib/Entity/Bug/BugComment.rb +7 -5
- data/lib/Entity/Platform/PlatformBrowser.rb +9 -7
- data/lib/Entity/Platform/PlatformBrowserVersion.rb +7 -5
- data/lib/Entity/Platform/PlatformDevice.rb +7 -5
- data/lib/Entity/Platform/PlatformOS.rb +9 -7
- data/lib/Entity/Platform/PlatformOSVersion.rb +7 -5
- data/lib/Entity/Platform/PlatformType.rb +9 -7
- data/lib/Entity/Project/Project.rb +24 -22
- data/lib/Entity/Project/ProjectBugScheme.rb +7 -5
- data/lib/Entity/Project/ProjectSection.rb +7 -5
- data/lib/Entity/Project/ProjectUser.rb +7 -5
- data/lib/Entity/Project/ProjectVersion.rb +7 -5
- data/lib/Entity/User/UserOrganization.rb +7 -5
- data/lib/Exception/BaseException/SDKException.rb +15 -13
- data/lib/Exception/SDKBadJSONResponseException.rb +13 -11
- data/lib/Exception/SDKDuplicateRequestException.rb +15 -13
- data/lib/Exception/SDKErrorResponseException.rb +12 -10
- data/lib/Exception/SDKIncompleteRequestException.rb +15 -13
- data/lib/Exception/SDKInvalidArgException.rb +13 -11
- data/lib/Exception/SDKMissingArgException.rb +13 -11
- data/lib/Exception/SDKUnexpectedResponseException.rb +13 -11
- data/lib/Exception/SDKUnsupportedRequestException.rb +15 -13
- data/lib/Handler/Attachment/AttachmentsHandler.rb +14 -12
- data/lib/Handler/Auth/OAuth2Handler.rb +102 -100
- data/lib/Handler/Bug/BugAttachmentsHandler.rb +44 -42
- data/lib/Handler/Bug/BugCommentsHandler.rb +16 -14
- data/lib/Handler/Bug/BugsHandler.rb +53 -51
- data/lib/Handler/Platform/PlatformBrowserVersionsHandler.rb +16 -14
- data/lib/Handler/Platform/PlatformBrowsersHandler.rb +18 -16
- data/lib/Handler/Platform/PlatformDevicesHandler.rb +9 -7
- data/lib/Handler/Platform/PlatformHandler.rb +20 -18
- data/lib/Handler/Platform/PlatformOSHandler.rb +18 -16
- data/lib/Handler/Platform/PlatformOSVersionsHandler.rb +16 -14
- data/lib/Handler/Platform/PlatformTypeDevicesHandler.rb +16 -14
- data/lib/Handler/Platform/PlatformTypesHandler.rb +17 -15
- data/lib/Handler/Project/ProjectBugReproducibilitySchemeHandler.rb +16 -14
- data/lib/Handler/Project/ProjectBugSeveritySchemeHandler.rb +16 -14
- data/lib/Handler/Project/ProjectBugStatusSchemeHandler.rb +16 -14
- data/lib/Handler/Project/ProjectBugTypeSchemeHandler.rb +16 -14
- data/lib/Handler/Project/ProjectBugsHandler.rb +55 -53
- data/lib/Handler/Project/ProjectSectionsHandler.rb +30 -28
- data/lib/Handler/Project/ProjectUsersHandler.rb +16 -14
- data/lib/Handler/Project/ProjectVersionsHandler.rb +30 -28
- data/lib/Handler/Project/ProjectsHandler.rb +34 -32
- data/lib/Handler/User/UserHandler.rb +12 -10
- data/lib/Handler/User/UserOrganizationsHandler.rb +12 -10
- data/tests/APIRequestTest.rb +33 -33
- data/tests/BaseClassesTest.rb +28 -28
- data/tests/ClientTest.rb +7 -7
- data/tests/EntitiesTest.rb +31 -31
- data/tests/EntityListTest.rb +13 -13
- data/tests/ExceptionsTest.rb +15 -15
- data/tests/HandlersRequestsTest.rb +37 -37
- data/tests/MockRequestsTest.rb +48 -48
- data/tests/OAuth2HandlerTest.rb +19 -19
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6af9018276f7f7bdef8db3bcdbd4762d365944ed
|
4
|
+
data.tar.gz: a40e97d7dd8fff881555db24963bb22c14b7bf26
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
data/lib/BaseClass/APIRequest.rb
CHANGED
@@ -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
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
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
|
-
|
46
|
-
|
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
|
-
|
49
|
-
|
50
|
-
@method = method
|
51
|
-
end
|
47
|
+
@opts = @default_ops.clone
|
48
|
+
self.updateOpts(opts)
|
52
49
|
|
53
|
-
|
54
|
-
|
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
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
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
|
-
|
75
|
-
|
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
|
-
|
89
|
+
callUrl = @opts['base_uri'] + @endpoint
|
86
90
|
|
87
|
-
|
91
|
+
if @origin.getCurrentToken.is_a? String
|
92
|
+
ch.headers['Authorization'] = 'Bearer ' + @origin.getCurrentToken
|
93
|
+
end
|
88
94
|
|
89
|
-
|
90
|
-
ch.headers['Authorization'] = 'Bearer ' + @origin.getCurrentToken
|
91
|
-
end
|
95
|
+
ch.url = callUrl
|
92
96
|
|
93
|
-
|
97
|
+
ch.header_in_body = false
|
94
98
|
|
95
|
-
|
99
|
+
case @method
|
100
|
+
when 'GET'
|
101
|
+
callUrl += '?' + Curl::postalize(@opts['params'])
|
102
|
+
ch.url = callUrl
|
96
103
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
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
|
-
|
103
|
-
|
104
|
-
|
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
|
-
|
109
|
-
|
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.
|
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.
|
121
|
-
|
130
|
+
curlData = ch.body_str
|
131
|
+
curlStatus = ch.status.to_i()
|
132
|
+
|
133
|
+
ch.close
|
134
|
+
ch = nil
|
122
135
|
|
123
|
-
|
124
|
-
|
125
|
-
|
136
|
+
{
|
137
|
+
'data' => curlData,
|
138
|
+
'status' => curlStatus
|
139
|
+
}
|
126
140
|
end
|
127
141
|
|
128
|
-
|
129
|
-
|
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
|
-
|
132
|
-
ch = nil
|
161
|
+
else
|
133
162
|
|
134
|
-
|
135
|
-
|
136
|
-
|
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
|
-
|
169
|
+
if @method == 'DELETE'
|
170
|
+
expectedHTTPStatus = 204
|
171
|
+
else
|
172
|
+
expectedHTTPStatus = 200
|
173
|
+
end
|
166
174
|
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
expectedHTTPStatus = 200
|
171
|
-
end
|
175
|
+
if curlStatus != expectedHTTPStatus
|
176
|
+
raise SDKErrorResponseException, curlStatus.to_s() + ' - ' + curlData
|
177
|
+
end
|
172
178
|
|
173
|
-
|
174
|
-
|
175
|
-
|
179
|
+
if @method == 'DELETE' # if DELETE request, expect no output
|
180
|
+
return true
|
181
|
+
end
|
176
182
|
|
177
|
-
|
178
|
-
|
179
|
-
|
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
|
-
|
182
|
-
|
183
|
-
|
184
|
-
raise SDKBadJSONResponseException, curlData
|
185
|
-
end
|
189
|
+
if jsonData.length.zero?
|
190
|
+
raise SDKUnexpectedResponseException, 'Empty object received'
|
191
|
+
end
|
186
192
|
|
187
|
-
|
188
|
-
raise SDKUnexpectedResponseException, 'Empty object received'
|
189
|
-
end
|
193
|
+
return jsonData
|
190
194
|
|
191
|
-
|
195
|
+
end
|
192
196
|
|
193
197
|
end
|
194
|
-
|
195
|
-
end
|
198
|
+
end
|
data/lib/BaseClass/Entity.rb
CHANGED
@@ -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
|
-
|
6
|
-
|
8
|
+
@origin = nil # Reference to originating Client instance
|
9
|
+
@data = nil # Internal entity object data
|
7
10
|
|
8
|
-
|
9
|
-
|
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
|
-
|
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
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
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
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
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
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
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
|
-
|
67
|
+
end
|
67
68
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
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
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
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
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
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
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
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
|
-
|
153
|
-
|
154
|
-
|
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
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
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
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
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
|
-
|
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
|