warrant 1.2.0 → 2.0.0.rc1
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/Gemfile +4 -0
- data/lib/warrant/api_operations.rb +9 -3
- data/lib/warrant/errors.rb +2 -0
- data/lib/warrant/models/feature.rb +327 -0
- data/lib/warrant/models/permission.rb +140 -41
- data/lib/warrant/models/pricing_tier.rb +328 -0
- data/lib/warrant/models/role.rb +128 -37
- data/lib/warrant/models/session.rb +4 -5
- data/lib/warrant/models/tenant.rb +176 -35
- data/lib/warrant/models/user.rb +225 -98
- data/lib/warrant/models/warrant.rb +208 -61
- data/lib/warrant/util.rb +20 -19
- data/lib/warrant/version.rb +1 -1
- data/lib/warrant/warrant_configuration.rb +3 -3
- data/lib/warrant/warrant_object.rb +13 -0
- data/lib/warrant.rb +5 -1
- metadata +8 -5
@@ -2,16 +2,20 @@
|
|
2
2
|
|
3
3
|
module Warrant
|
4
4
|
class Permission
|
5
|
-
|
6
|
-
|
5
|
+
include Warrant::WarrantObject
|
6
|
+
|
7
|
+
attr_reader :permission_id, :name, :description
|
8
|
+
|
7
9
|
# @!visibility private
|
8
|
-
def initialize(permission_id)
|
10
|
+
def initialize(permission_id, name = nil, description = nil)
|
9
11
|
@permission_id = permission_id
|
12
|
+
@name = name
|
13
|
+
@description = description
|
10
14
|
end
|
11
15
|
|
12
16
|
# Creates a permission with the given parameters
|
13
17
|
#
|
14
|
-
# @option params [String] :permission_id A string identifier for this new permission. The permission_id can only be composed of lower-case alphanumeric chars and/or '-' and '_'.
|
18
|
+
# @option params [String] :permission_id A string identifier for this new permission. The permission_id can only be composed of lower-case alphanumeric chars and/or '-' and '_'.
|
15
19
|
#
|
16
20
|
# @return [Permission] created permission
|
17
21
|
#
|
@@ -20,19 +24,15 @@ module Warrant
|
|
20
24
|
#
|
21
25
|
# @raise [Warrant::DuplicateRecordError]
|
22
26
|
# @raise [Warrant::InternalError]
|
23
|
-
# @raise [Warrant::InvalidParameterError]
|
24
27
|
# @raise [Warrant::InvalidRequestError]
|
25
|
-
# @raise [Warrant::MissingRequiredParameterError]
|
26
|
-
# @raise [Warrant::NotFoundError]
|
27
28
|
# @raise [Warrant::UnauthorizedError]
|
28
|
-
# @raise [Warrant::WarrantError]
|
29
29
|
def self.create(params = {})
|
30
30
|
res = APIOperations.post(URI.parse("#{::Warrant.config.api_base}/v1/permissions"), Util.normalize_params(params))
|
31
31
|
|
32
32
|
case res
|
33
33
|
when Net::HTTPSuccess
|
34
34
|
res_json = JSON.parse(res.body)
|
35
|
-
Permission.new(res_json['permissionId'])
|
35
|
+
Permission.new(res_json['permissionId'], res_json['name'], res_json['description'])
|
36
36
|
else
|
37
37
|
APIOperations.raise_error(res)
|
38
38
|
end
|
@@ -40,7 +40,7 @@ module Warrant
|
|
40
40
|
|
41
41
|
# Deletes a permission with given permission id
|
42
42
|
#
|
43
|
-
# @param permission_id [String]
|
43
|
+
# @param permission_id [String] The permission_id of the permission to delete.
|
44
44
|
#
|
45
45
|
# @return [nil] if delete was successful
|
46
46
|
#
|
@@ -48,10 +48,9 @@ module Warrant
|
|
48
48
|
# Warrant::Permission.delete("test-permission")
|
49
49
|
#
|
50
50
|
# @raise [Warrant::InternalError]
|
51
|
-
# @raise [Warrant::
|
51
|
+
# @raise [Warrant::MissingRequiredParameterError]
|
52
52
|
# @raise [Warrant::NotFoundError]
|
53
53
|
# @raise [Warrant::UnauthorizedError]
|
54
|
-
# @raise [Warrant::WarrantError]
|
55
54
|
def self.delete(permission_id)
|
56
55
|
res = APIOperations.delete(URI.parse("#{::Warrant.config.api_base}/v1/permissions/#{permission_id}"))
|
57
56
|
|
@@ -65,50 +64,121 @@ module Warrant
|
|
65
64
|
|
66
65
|
# Lists all permissions for your organization
|
67
66
|
#
|
68
|
-
# @
|
67
|
+
# @option filters [Integer] :page A positive integer (starting with 1) representing the page of items to return in response. Used in conjunction with the limit param. (optional)
|
68
|
+
# @option filters [Integer] :limit A positive integer representing the max number of items to return in response. (optional)
|
69
|
+
#
|
70
|
+
# @return [Array<Permission>] all permissions for your organization
|
69
71
|
#
|
70
72
|
# @example List all permissions
|
71
73
|
# Warrant::Permission.list()
|
72
74
|
#
|
73
75
|
# @raise [Warrant::InternalError]
|
74
|
-
# @raise [Warrant::
|
75
|
-
# @raise [Warrant::NotFoundError]
|
76
|
+
# @raise [Warrant::InvalidParameterError]
|
76
77
|
# @raise [Warrant::UnauthorizedError]
|
77
|
-
# @raise [Warrant::WarrantError]
|
78
78
|
def self.list(filters = {})
|
79
|
-
res = APIOperations.get(URI.parse("#{::Warrant.config.api_base}/v1/permissions"))
|
79
|
+
res = APIOperations.get(URI.parse("#{::Warrant.config.api_base}/v1/permissions"), Util.normalize_params(filters))
|
80
80
|
|
81
81
|
case res
|
82
82
|
when Net::HTTPSuccess
|
83
83
|
permissions = JSON.parse(res.body)
|
84
|
-
permissions.map{ |permission| Permission.new(permission['permissionId']) }
|
84
|
+
permissions.map{ |permission| Permission.new(permission['permissionId'], permission['name'], permission['description']) }
|
85
85
|
else
|
86
86
|
APIOperations.raise_error(res)
|
87
|
-
end
|
87
|
+
end
|
88
88
|
end
|
89
89
|
|
90
90
|
# Get a permission with the given permission_id
|
91
91
|
#
|
92
|
-
# @param permission_id [String]
|
92
|
+
# @param permission_id [String] The permission_id of the permission to retrieve.
|
93
93
|
#
|
94
94
|
# @return [Permission] retrieved permission
|
95
95
|
#
|
96
96
|
# @raise [Warrant::InternalError]
|
97
|
-
# @raise [Warrant::
|
98
|
-
# @raise [Warrant::InvalidRequestError]
|
97
|
+
# @raise [Warrant::MissingRequiredParameterError]
|
99
98
|
# @raise [Warrant::NotFoundError]
|
100
99
|
# @raise [Warrant::UnauthorizedError]
|
101
|
-
# @raise [Warrant::WarrantError]
|
102
100
|
def self.get(permission_id)
|
103
101
|
res = APIOperations.get(URI.parse("#{::Warrant.config.api_base}/v1/permissions/#{permission_id}"))
|
104
102
|
|
105
103
|
case res
|
106
104
|
when Net::HTTPSuccess
|
107
105
|
permission = JSON.parse(res.body)
|
108
|
-
Permission.new(permission['permissionId'])
|
106
|
+
Permission.new(permission['permissionId'], permission['name'], permission['description'])
|
109
107
|
else
|
110
108
|
APIOperations.raise_error(res)
|
111
|
-
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
# Updates a permission with the given role_id and params
|
113
|
+
#
|
114
|
+
# @param permission_id [String] The permission_id of the permission to be updated.
|
115
|
+
# @param [Hash] params attributes to update user with
|
116
|
+
# @option params [String] :name Name for the permission. Designed to be used as a UI-friendly identifier. (optional)
|
117
|
+
# @option params [String] :description Description of the permission. Designed to be used as a UI-friendly identifier. (optional)
|
118
|
+
#
|
119
|
+
# @return [Permission] updated permission
|
120
|
+
#
|
121
|
+
# @example Update permission "test-permission"'s name
|
122
|
+
# Warrant::Permission.update("test-permission", { name: "Test Permission" })
|
123
|
+
#
|
124
|
+
# @raise [Warrant::InternalError]
|
125
|
+
# @raise [Warrant::InvalidParameterError]
|
126
|
+
# @raise [Warrant::InvalidRequestError]
|
127
|
+
# @raise [Warrant::NotFoundError]
|
128
|
+
# @raise [Warrant::UnauthorizedError]
|
129
|
+
def self.update(permission_id, params = {})
|
130
|
+
res = APIOperations.put(URI.parse("#{::Warrant.config.api_base}/v1/permissions/#{permission_id}"), Util.normalize_params(params))
|
131
|
+
|
132
|
+
case res
|
133
|
+
when Net::HTTPSuccess
|
134
|
+
res_json = JSON.parse(res.body)
|
135
|
+
Permission.new(res_json['permissionId'], res_json['name'], res_json['description'])
|
136
|
+
else
|
137
|
+
APIOperations.raise_error(res)
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
# Updates a permission with the given params
|
142
|
+
#
|
143
|
+
# @param [Hash] params attributes to update user with
|
144
|
+
# @option params [String] :name Name for the permission. Designed to be used as a UI-friendly identifier. (optional)
|
145
|
+
# @option params [String] :description Description of the permission. Designed to be used as a UI-friendly identifier. (optional)
|
146
|
+
#
|
147
|
+
# @return [Permission] updated permission
|
148
|
+
#
|
149
|
+
# @example Update permission "test-permission"'s name
|
150
|
+
# Warrant::Permission.update("test-permission", { name: "Test Permission" })
|
151
|
+
#
|
152
|
+
# @raise [Warrant::InternalError]
|
153
|
+
# @raise [Warrant::InvalidParameterError]
|
154
|
+
# @raise [Warrant::InvalidRequestError]
|
155
|
+
# @raise [Warrant::NotFoundError]
|
156
|
+
# @raise [Warrant::UnauthorizedError]
|
157
|
+
def update(params = {})
|
158
|
+
return Permission.update(permission_id, params)
|
159
|
+
end
|
160
|
+
|
161
|
+
# List permissions for a role
|
162
|
+
#
|
163
|
+
# @param role_id [String] The role_id of the role to list assigned permissions for.
|
164
|
+
# @option filters [Integer] :page A positive integer (starting with 1) representing the page of items to return in response. Used in conjunction with the limit param. (optional)
|
165
|
+
# @option filters [Integer] :limit A positive integer representing the max number of items to return in response. (optional)
|
166
|
+
#
|
167
|
+
# @return [Array<Permission>] all assigned permissions for the role
|
168
|
+
#
|
169
|
+
# @raise [Warrant::InternalError]
|
170
|
+
# @raise [Warrant::MissingRequiredParameterError]
|
171
|
+
# @raise [Warrant::UnauthorizedError]
|
172
|
+
def self.list_for_role(role_id, filters = {})
|
173
|
+
res = APIOperations.get(URI.parse("#{::Warrant.config.api_base}/v1/roles/#{role_id}/permissions"), Util.normalize_params(filters))
|
174
|
+
|
175
|
+
case res
|
176
|
+
when Net::HTTPSuccess
|
177
|
+
permissions = JSON.parse(res.body)
|
178
|
+
permissions.map{ |permission| Permission.new(permission['permissionId'], permission['name'], permission['description']) }
|
179
|
+
else
|
180
|
+
APIOperations.raise_error(res)
|
181
|
+
end
|
112
182
|
end
|
113
183
|
|
114
184
|
# Assign a permission to a role
|
@@ -118,33 +188,32 @@ module Warrant
|
|
118
188
|
#
|
119
189
|
# @return [Permission] assigned permission
|
120
190
|
#
|
191
|
+
# @raise [Warrant::DuplicateRecordError]
|
121
192
|
# @raise [Warrant::InternalError]
|
122
|
-
# @raise [Warrant::
|
193
|
+
# @raise [Warrant::InvalidParameterError]
|
123
194
|
# @raise [Warrant::MissingRequiredParameterError]
|
124
195
|
# @raise [Warrant::NotFoundError]
|
125
196
|
# @raise [Warrant::UnauthorizedError]
|
126
|
-
# @raise [Warrant::WarrantError]
|
127
197
|
def self.assign_to_role(role_id, permission_id)
|
128
198
|
res = APIOperations.post(URI.parse("#{::Warrant.config.api_base}/v1/roles/#{role_id}/permissions/#{permission_id}"))
|
129
199
|
|
130
200
|
case res
|
131
201
|
when Net::HTTPSuccess
|
132
202
|
permission = JSON.parse(res.body)
|
133
|
-
Permission.new(permission['permissionId'])
|
203
|
+
Permission.new(permission['permissionId'], permission['name'], permission['description'])
|
134
204
|
else
|
135
205
|
APIOperations.raise_error(res)
|
136
|
-
end
|
206
|
+
end
|
137
207
|
end
|
138
208
|
|
139
209
|
# Remove a permission from a role
|
140
210
|
#
|
141
|
-
# @param role_id [String] The role_id of the role you want to
|
142
|
-
# @param permission_id [String] The permission_id of the permission you want to
|
211
|
+
# @param role_id [String] The role_id of the role you want to remove a permission from.
|
212
|
+
# @param permission_id [String] The permission_id of the permission you want to remove from a role.
|
143
213
|
#
|
144
214
|
# @return [nil] if remove was successful
|
145
215
|
#
|
146
216
|
# @raise [Warrant::InternalError]
|
147
|
-
# @raise [Warrant::InvalidRequestError]
|
148
217
|
# @raise [Warrant::MissingRequiredParameterError]
|
149
218
|
# @raise [Warrant::NotFoundError]
|
150
219
|
# @raise [Warrant::UnauthorizedError]
|
@@ -157,7 +226,30 @@ module Warrant
|
|
157
226
|
return
|
158
227
|
else
|
159
228
|
APIOperations.raise_error(res)
|
160
|
-
end
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
# List permissions for a user
|
233
|
+
#
|
234
|
+
# @param user_id [String] The user_id of the user to list assigned permissions for.
|
235
|
+
# @option filters [Integer] :page A positive integer (starting with 1) representing the page of items to return in response. Used in conjunction with the limit param. (optional)
|
236
|
+
# @option filters [Integer] :limit A positive integer representing the max number of items to return in response. (optional)
|
237
|
+
#
|
238
|
+
# @return [Array<Permission>] all assigned permissions for the user
|
239
|
+
#
|
240
|
+
# @raise [Warrant::InternalError]
|
241
|
+
# @raise [Warrant::MissingRequiredParameterError]
|
242
|
+
# @raise [Warrant::UnauthorizedError]
|
243
|
+
def self.list_for_user(user_id, filters = {})
|
244
|
+
res = APIOperations.get(URI.parse("#{::Warrant.config.api_base}/v1/users/#{user_id}/permissions"), Util.normalize_params(filters))
|
245
|
+
|
246
|
+
case res
|
247
|
+
when Net::HTTPSuccess
|
248
|
+
permissions = JSON.parse(res.body)
|
249
|
+
permissions.map{ |permission| Permission.new(permission['permissionId'], permission['name'], permission['description']) }
|
250
|
+
else
|
251
|
+
APIOperations.raise_error(res)
|
252
|
+
end
|
161
253
|
end
|
162
254
|
|
163
255
|
# Assign a permission to a user
|
@@ -167,33 +259,32 @@ module Warrant
|
|
167
259
|
#
|
168
260
|
# @return [Permission] assigned permission
|
169
261
|
#
|
262
|
+
# @raise [Warrant::DuplicateRecordError]
|
170
263
|
# @raise [Warrant::InternalError]
|
171
|
-
# @raise [Warrant::
|
264
|
+
# @raise [Warrant::InvalidParameterError]
|
172
265
|
# @raise [Warrant::MissingRequiredParameterError]
|
173
266
|
# @raise [Warrant::NotFoundError]
|
174
267
|
# @raise [Warrant::UnauthorizedError]
|
175
|
-
# @raise [Warrant::WarrantError]
|
176
268
|
def self.assign_to_user(user_id, permission_id)
|
177
269
|
res = APIOperations.post(URI.parse("#{::Warrant.config.api_base}/v1/users/#{user_id}/permissions/#{permission_id}"))
|
178
270
|
|
179
271
|
case res
|
180
272
|
when Net::HTTPSuccess
|
181
273
|
permission = JSON.parse(res.body)
|
182
|
-
Permission.new(permission['permissionId'])
|
274
|
+
Permission.new(permission['permissionId'], permission['name'], permission['description'])
|
183
275
|
else
|
184
276
|
APIOperations.raise_error(res)
|
185
|
-
end
|
277
|
+
end
|
186
278
|
end
|
187
279
|
|
188
280
|
# Remove a permission from a user
|
189
281
|
#
|
190
|
-
# @param user_id [String] The user_id of the user you want to
|
191
|
-
# @param permission_id [String] The permission_id of the permission you want to
|
282
|
+
# @param user_id [String] The user_id of the user you want to remove a permission from.
|
283
|
+
# @param permission_id [String] The permission_id of the permission you want to remove from a user.
|
192
284
|
#
|
193
285
|
# @return [nil] if remove was successful
|
194
286
|
#
|
195
287
|
# @raise [Warrant::InternalError]
|
196
|
-
# @raise [Warrant::InvalidRequestError]
|
197
288
|
# @raise [Warrant::MissingRequiredParameterError]
|
198
289
|
# @raise [Warrant::NotFoundError]
|
199
290
|
# @raise [Warrant::UnauthorizedError]
|
@@ -206,7 +297,15 @@ module Warrant
|
|
206
297
|
return
|
207
298
|
else
|
208
299
|
APIOperations.raise_error(res)
|
209
|
-
end
|
300
|
+
end
|
301
|
+
end
|
302
|
+
|
303
|
+
def warrant_object_type
|
304
|
+
"permission"
|
305
|
+
end
|
306
|
+
|
307
|
+
def warrant_object_id
|
308
|
+
permission_id
|
210
309
|
end
|
211
310
|
end
|
212
311
|
end
|
@@ -0,0 +1,328 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Warrant
|
4
|
+
class PricingTier
|
5
|
+
include Warrant::WarrantObject
|
6
|
+
|
7
|
+
attr_reader :pricing_tier_id
|
8
|
+
|
9
|
+
# @!visibility private
|
10
|
+
def initialize(pricing_tier_id)
|
11
|
+
@pricing_tier_id = pricing_tier_id
|
12
|
+
end
|
13
|
+
|
14
|
+
# Creates a pricing tier with the given parameters
|
15
|
+
#
|
16
|
+
# @option params [String] :pricing_tier_id A string identifier for this new pricing tier. The pricing_tier_id can only be composed of lower-case alphanumeric chars and/or '-' and '_'.
|
17
|
+
#
|
18
|
+
# @return [PricingTier] created pricing tier
|
19
|
+
#
|
20
|
+
# @example Create a new PricingTier with the pricing tier id "test-pricing-tier"
|
21
|
+
# Warrant::PricingTier.create(pricing_tier_id: "test-pricing-tier")
|
22
|
+
#
|
23
|
+
# @raise [Warrant::DuplicateRecordError]
|
24
|
+
# @raise [Warrant::InternalError]
|
25
|
+
# @raise [Warrant::InvalidRequestError]
|
26
|
+
# @raise [Warrant::UnauthorizedError]
|
27
|
+
def self.create(params = {})
|
28
|
+
res = APIOperations.post(URI.parse("#{::Warrant.config.api_base}/v1/pricing-tiers"), Util.normalize_params(params))
|
29
|
+
|
30
|
+
case res
|
31
|
+
when Net::HTTPSuccess
|
32
|
+
res_json = JSON.parse(res.body)
|
33
|
+
PricingTier.new(res_json['pricingTierId'])
|
34
|
+
else
|
35
|
+
APIOperations.raise_error(res)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# Deletes a pricing tier with given pricing tier id
|
40
|
+
#
|
41
|
+
# @param pricing_tier_id [String] The pricing_tier_id of the pricing tier to delete.
|
42
|
+
#
|
43
|
+
# @return [nil] if delete was successful
|
44
|
+
#
|
45
|
+
# @example Delete a PricingTier with the pricing tier id "test-pricing-tier"
|
46
|
+
# Warrant::PricingTier.delete("test-pricing-tier")
|
47
|
+
#
|
48
|
+
# @raise [Warrant::InternalError]
|
49
|
+
# @raise [Warrant::InvalidParameterError]
|
50
|
+
# @raise [Warrant::NotFoundError]
|
51
|
+
# @raise [Warrant::UnauthorizedError]
|
52
|
+
def self.delete(pricing_tier_id)
|
53
|
+
res = APIOperations.delete(URI.parse("#{::Warrant.config.api_base}/v1/pricing-tiers/#{pricing_tier_id}"))
|
54
|
+
|
55
|
+
case res
|
56
|
+
when Net::HTTPSuccess
|
57
|
+
return
|
58
|
+
else
|
59
|
+
APIOperations.raise_error(res)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
# Lists all pricing tiers for your organization
|
64
|
+
#
|
65
|
+
# @option filters [Integer] :page A positive integer (starting with 1) representing the page of items to return in response. Used in conjunction with the limit param. (optional)
|
66
|
+
# @option filters [Integer] :limit A positive integer representing the max number of items to return in response. (optional)
|
67
|
+
#
|
68
|
+
# @return [Array<Feature>] all pricing tiers for your organization
|
69
|
+
#
|
70
|
+
# @example List all pricing tiers
|
71
|
+
# Warrant::PricingTier.list()
|
72
|
+
#
|
73
|
+
# @raise [Warrant::InternalError]
|
74
|
+
# @raise [Warrant::UnauthorizedError]
|
75
|
+
def self.list(filters = {})
|
76
|
+
res = APIOperations.get(URI.parse("#{::Warrant.config.api_base}/v1/pricing-tiers"), Util.normalize_params(filters))
|
77
|
+
|
78
|
+
case res
|
79
|
+
when Net::HTTPSuccess
|
80
|
+
pricing_tiers = JSON.parse(res.body)
|
81
|
+
pricing_tiers.map{ |pricing_tier| PricingTier.new(pricing_tier['pricingTierId']) }
|
82
|
+
else
|
83
|
+
APIOperations.raise_error(res)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
# Get a pricing_tier with the given pricing_tier_id
|
88
|
+
#
|
89
|
+
# @param pricing_tier_id [String] The pricing_tier_id of the pricing tier to retrieve.
|
90
|
+
#
|
91
|
+
# @return [PricingTier] retrieved pricing tier
|
92
|
+
#
|
93
|
+
# @raise [Warrant::InternalError]
|
94
|
+
# @raise [Warrant::InvalidParameterError]
|
95
|
+
# @raise [Warrant::NotFoundError]
|
96
|
+
# @raise [Warrant::UnauthorizedError]
|
97
|
+
def self.get(pricing_tier_id)
|
98
|
+
res = APIOperations.get(URI.parse("#{::Warrant.config.api_base}/v1/pricing-tiers/#{pricing_tier_id}"))
|
99
|
+
|
100
|
+
case res
|
101
|
+
when Net::HTTPSuccess
|
102
|
+
pricing_tier = JSON.parse(res.body)
|
103
|
+
PricingTier.new(pricing_tier['pricingTierId'])
|
104
|
+
else
|
105
|
+
APIOperations.raise_error(res)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
|
110
|
+
# List pricing tiers for tenant
|
111
|
+
#
|
112
|
+
# @param tenant_id [String] The tenant_id of the tenant to list pricing tiers for.
|
113
|
+
# @option filters [Integer] :page A positive integer (starting with 1) representing the page of items to return in response. Used in conjunction with the limit param. (optional)
|
114
|
+
# @option filters [Integer] :limit A positive integer representing the max number of items to return in response. (optional)
|
115
|
+
#
|
116
|
+
# @return [Array<PricingTier>] assigned pricing tiers for the tenant
|
117
|
+
#
|
118
|
+
# @raise [Warrant::InternalError]
|
119
|
+
# @raise [Warrant::InvalidParameterError]
|
120
|
+
# @raise [Warrant::UnauthorizedError]
|
121
|
+
def self.list_for_tenant(tenant_id, filters = {})
|
122
|
+
res = APIOperations.get(URI.parse("#{::Warrant.config.api_base}/v1/tenants/#{tenant_id}/pricing-tiers"), Util.normalize_params(filters))
|
123
|
+
|
124
|
+
case res
|
125
|
+
when Net::HTTPSuccess
|
126
|
+
pricing_tiers = JSON.parse(res.body)
|
127
|
+
pricing_tiers.map{ |pricing_tier| PricingTier.new(pricing_tier['pricingTierId']) }
|
128
|
+
else
|
129
|
+
APIOperations.raise_error(res)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
# Assign a pricing tier to a tenant
|
134
|
+
#
|
135
|
+
# @param tenant_id [String] The tenant_id of the tenant you want to assign a pricing tier to.
|
136
|
+
# @param pricing_tier_id [String] The pricing_tier_id of the pricing tier you want to assign to a tenant.
|
137
|
+
#
|
138
|
+
# @return [PricingTier] assigned pricing tier
|
139
|
+
#
|
140
|
+
# @raise [Warrant::DuplicateRecordError]
|
141
|
+
# @raise [Warrant::InternalError]
|
142
|
+
# @raise [Warrant::InvalidParameterError]
|
143
|
+
# @raise [Warrant::NotFoundError]
|
144
|
+
# @raise [Warrant::UnauthorizedError]
|
145
|
+
def self.assign_to_tenant(tenant_id, pricing_tier_id)
|
146
|
+
res = APIOperations.post(URI.parse("#{::Warrant.config.api_base}/v1/tenants/#{tenant_id}/pricing-tiers/#{pricing_tier_id}"))
|
147
|
+
|
148
|
+
case res
|
149
|
+
when Net::HTTPSuccess
|
150
|
+
pricing_tier = JSON.parse(res.body)
|
151
|
+
PricingTier.new(pricing_tier['pricingTierId'])
|
152
|
+
else
|
153
|
+
APIOperations.raise_error(res)
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
# Remove a pricing tier from a tenant
|
158
|
+
#
|
159
|
+
# @param tenant_id [String] The tenant_id of the tenant you want to remove a pricing tier from.
|
160
|
+
# @param pricing_tier_id [String] The pricing_tier_id of the pricing tier you want to remove from a tenant.
|
161
|
+
#
|
162
|
+
# @return [nil] if remove was successful
|
163
|
+
#
|
164
|
+
# @raise [Warrant::InternalError]
|
165
|
+
# @raise [Warrant::InvalidParameterError]
|
166
|
+
# @raise [Warrant::NotFoundError]
|
167
|
+
# @raise [Warrant::UnauthorizedError]
|
168
|
+
# @raise [Warrant::WarrantError]
|
169
|
+
def self.remove_from_tenant(tenant_id, pricing_tier_id)
|
170
|
+
res = APIOperations.delete(URI.parse("#{::Warrant.config.api_base}/v1/tenants/#{tenant_id}/pricing-tiers/#{pricing_tier_id}"))
|
171
|
+
|
172
|
+
case res
|
173
|
+
when Net::HTTPSuccess
|
174
|
+
return
|
175
|
+
else
|
176
|
+
APIOperations.raise_error(res)
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
# List pricing tiers for user
|
181
|
+
#
|
182
|
+
# @param user_id [String] The user_id of the user to list pricing tiers for.
|
183
|
+
# @option filters [Integer] :page A positive integer (starting with 1) representing the page of items to return in response. Used in conjunction with the limit param. (optional)
|
184
|
+
# @option filters [Integer] :limit A positive integer representing the max number of items to return in response. (optional)
|
185
|
+
#
|
186
|
+
# @return [Array<PricingTier>] assigned pricing tiers for the user
|
187
|
+
#
|
188
|
+
# @raise [Warrant::InternalError]
|
189
|
+
# @raise [Warrant::InvalidParameterError]
|
190
|
+
# @raise [Warrant::UnauthorizedError]
|
191
|
+
def self.list_for_user(user_id, filters = {})
|
192
|
+
res = APIOperations.get(URI.parse("#{::Warrant.config.api_base}/v1/users/#{user_id}/pricing-tiers"), Util.normalize_params(filters))
|
193
|
+
|
194
|
+
case res
|
195
|
+
when Net::HTTPSuccess
|
196
|
+
pricing_tiers = JSON.parse(res.body)
|
197
|
+
pricing_tiers.map{ |pricing_tier| PricingTier.new(pricing_tier['pricingTierId']) }
|
198
|
+
else
|
199
|
+
APIOperations.raise_error(res)
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
# Assign a pricing tier to a user
|
204
|
+
#
|
205
|
+
# @param user_id [String] The user_id of the user you want to assign a pricing tier to.
|
206
|
+
# @param pricing_tier_id [String] The pricing_tier_id of the pricing tier you want to assign to a user.
|
207
|
+
#
|
208
|
+
# @return [PricingTier] assigned pricing tier
|
209
|
+
#
|
210
|
+
# @raise [Warrant::DuplicateRecordError]
|
211
|
+
# @raise [Warrant::InternalError]
|
212
|
+
# @raise [Warrant::InvalidParameterError]
|
213
|
+
# @raise [Warrant::NotFoundError]
|
214
|
+
# @raise [Warrant::UnauthorizedError]
|
215
|
+
def self.assign_to_user(user_id, pricing_tier_id)
|
216
|
+
res = APIOperations.post(URI.parse("#{::Warrant.config.api_base}/v1/users/#{user_id}/pricing-tiers/#{pricing_tier_id}"))
|
217
|
+
|
218
|
+
case res
|
219
|
+
when Net::HTTPSuccess
|
220
|
+
pricing_tier = JSON.parse(res.body)
|
221
|
+
PricingTier.new(pricing_tier['pricingTierId'])
|
222
|
+
else
|
223
|
+
APIOperations.raise_error(res)
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
# Remove a pricing tier from a user
|
228
|
+
#
|
229
|
+
# @param user_id [String] The user_id of the user you want to remove a pricing tier from.
|
230
|
+
# @param pricing_tier_id [String] The pricing_tier_id of the pricing tier you want to remove from a user.
|
231
|
+
#
|
232
|
+
# @return [nil] if remove was successful
|
233
|
+
#
|
234
|
+
# @raise [Warrant::InternalError]
|
235
|
+
# @raise [Warrant::InvalidParameterError]
|
236
|
+
# @raise [Warrant::NotFoundError]
|
237
|
+
# @raise [Warrant::UnauthorizedError]
|
238
|
+
# @raise [Warrant::WarrantError]
|
239
|
+
def self.remove_from_user(user_id, pricing_tier_id)
|
240
|
+
res = APIOperations.delete(URI.parse("#{::Warrant.config.api_base}/v1/users/#{user_id}/pricing-tiers/#{pricing_tier_id}"))
|
241
|
+
|
242
|
+
case res
|
243
|
+
when Net::HTTPSuccess
|
244
|
+
return
|
245
|
+
else
|
246
|
+
APIOperations.raise_error(res)
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
# List features for a pricing tier
|
251
|
+
#
|
252
|
+
# @option filters [Integer] :page A positive integer (starting with 1) representing the page of items to return in response. Used in conjunction with the limit param. (optional)
|
253
|
+
# @option filters [Integer] :limit A positive integer representing the max number of items to return in response. (optional)
|
254
|
+
#
|
255
|
+
# @return [Array<Feature>] assigned features for the pricing tier
|
256
|
+
#
|
257
|
+
# @raise [Warrant::InternalError]
|
258
|
+
# @raise [Warrant::InvalidParameterError]
|
259
|
+
# @raise [Warrant::UnauthorizedError]
|
260
|
+
def list_features(filters = {})
|
261
|
+
return Feature.list_for_pricing_tier(pricing_tier_id, filters)
|
262
|
+
end
|
263
|
+
|
264
|
+
# Assign a feature to a pricing tier
|
265
|
+
#
|
266
|
+
# @param feature_id [String] The feature_id of the feature you want to assign to the pricing tier.
|
267
|
+
#
|
268
|
+
# @return [Feature] assigned feature
|
269
|
+
#
|
270
|
+
# @raise [Warrant::DuplicateRecordError]
|
271
|
+
# @raise [Warrant::InternalError]
|
272
|
+
# @raise [Warrant::InvalidParameterError]
|
273
|
+
# @raise [Warrant::NotFoundError]
|
274
|
+
# @raise [Warrant::UnauthorizedError]
|
275
|
+
def assign_feature(feature_id)
|
276
|
+
return Feature.assign_to_pricing_tier(pricing_tier_id, feature_id)
|
277
|
+
end
|
278
|
+
|
279
|
+
# Remove a feature from a pricing tier
|
280
|
+
#
|
281
|
+
# @param feature_id [String] The feature_id of the feature you want to assign from the pricing tier.
|
282
|
+
#
|
283
|
+
# @return [nil] if remove was successful
|
284
|
+
#
|
285
|
+
# @raise [Warrant::InternalError]
|
286
|
+
# @raise [Warrant::InvalidParameterError]
|
287
|
+
# @raise [Warrant::NotFoundError]
|
288
|
+
# @raise [Warrant::UnauthorizedError]
|
289
|
+
# @raise [Warrant::WarrantError]
|
290
|
+
def remove_feature(feature_id)
|
291
|
+
return Feature.remove_from_pricing_tier(pricing_tier_id, feature_id)
|
292
|
+
end
|
293
|
+
|
294
|
+
# Check whether a pricing tier has a given feature
|
295
|
+
#
|
296
|
+
# @param feature_id [String] The feature_id of the feature to check whether the pricing tier has access to.
|
297
|
+
# @option options [Hash] :context Object containing key-value pairs that specifies the context the warrant should be checked in. (optional)
|
298
|
+
# @option options [Boolean] :consistent_read Boolean flag indicating whether or not to enforce strict consistency for this access check. Defaults to false. (optional)
|
299
|
+
# @option options [Boolean] :debug Boolean flag indicating whether or not to return debug information for this access check. Defaults to false. (optional)
|
300
|
+
#
|
301
|
+
# @return [Boolean] whether or not the pricing tier has the given feature
|
302
|
+
#
|
303
|
+
# @raise [Warrant::InternalError]
|
304
|
+
# @raise [Warrant::InvalidParameterError]
|
305
|
+
# @raise [Warrant::NotFoundError]
|
306
|
+
# @raise [Warrant::UnauthorizedError]
|
307
|
+
def has_feature?(feature_id, opts = {})
|
308
|
+
return Warrant.has_feature?(
|
309
|
+
feature_id: feature_id,
|
310
|
+
subject: {
|
311
|
+
object_type: "pricing-tier",
|
312
|
+
object_id: pricing_tier_id
|
313
|
+
},
|
314
|
+
context: opts[:context],
|
315
|
+
consistent_read: opts[:consistent_read],
|
316
|
+
debug: opts[:debug]
|
317
|
+
)
|
318
|
+
end
|
319
|
+
|
320
|
+
def warrant_object_type
|
321
|
+
"pricing-tier"
|
322
|
+
end
|
323
|
+
|
324
|
+
def warrant_object_id
|
325
|
+
pricing_tier_id
|
326
|
+
end
|
327
|
+
end
|
328
|
+
end
|