warrant 4.0.0 → 5.0.0

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.
@@ -1,24 +1,22 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Warrant
4
- class Tenant
4
+ class Tenant < Warrant::Object
5
5
  OBJECT_TYPE = "tenant"
6
6
 
7
7
  include Warrant::WarrantObject
8
8
 
9
- attr_reader :tenant_id, :name, :created_at
9
+ alias :tenant_id :object_id
10
10
 
11
11
  # @!visibility private
12
- def initialize(tenant_id, name, created_at)
13
- @tenant_id = tenant_id
14
- @name = name
15
- @created_at = created_at
12
+ def initialize(tenant_id, meta = {}, created_at = nil)
13
+ super(OBJECT_TYPE, tenant_id, meta, created_at)
16
14
  end
17
15
 
18
16
  # Creates a tenant with the given parameters
19
17
  #
20
18
  # @option params [String] :tenant_id User defined string identifier for this tenant. If not provided, Warrant will create an id for the tenant and return it. In this case, you should store the id in your system for future reference. Note that tenantIds in Warrant must be composed of alphanumeric chars and/or '-', '_', and '@'. (optional)
21
- # @option params [String] :name A displayable name for this tenant. (optional)
19
+ # @option params [Hash] :meta A JSON object containing additional information about this tenant (e.g. name/description, etc.) to be persisted to Warrant. (optional)
22
20
  #
23
21
  # @return [Tenant] created tenant
24
22
  #
@@ -31,23 +29,16 @@ module Warrant
31
29
  # @raise [Warrant::InvalidRequestError]
32
30
  # @raise [Warrant::NotFoundError]
33
31
  # @raise [Warrant::UnauthorizedError]
34
- def self.create(params = {})
35
- res = APIOperations.post(URI.parse("#{::Warrant.config.api_base}/v1/tenants"), Util.normalize_params(params))
36
-
37
- case res
38
- when Net::HTTPSuccess
39
- res_json = JSON.parse(res.body)
40
- Tenant.new(res_json['tenantId'], res_json['name'], res_json['createdAt'])
41
- else
42
- APIOperations.raise_error(res)
43
- end
32
+ def self.create(params = {}, options = {})
33
+ object = Object.create({ object_type: OBJECT_TYPE, object_id: params[:tenant_id], meta: params[:meta] }, options)
34
+ return Tenant.new(object.object_id, object.meta, object.created_at)
44
35
  end
45
36
 
46
37
  # Batch creates multiple tenants with given parameters
47
38
  #
48
- # @param [Array] Array of tenants to create.
49
- # * tenant_id User defined string identifier for this tenant. If not provided, Warrant will create an id for the tenant and return it. In this case, you should store the id in your system for future reference. Note that tenantIds in Warrant must be composed of alphanumeric chars and/or '-', '_', and '@'. (optional)
50
- # * name A displayable name for this tenant. (optional)
39
+ # @param [Array<Hash>] tenants Array of tenants to create.
40
+ # @option tenants [String] :tenant_id User defined string identifier for this tenant. If not provided, Warrant will create an id for the tenant and return it. In this case, you should store the id in your system for future reference. Note that tenantIds in Warrant must be composed of alphanumeric chars and/or '-', '_', and '@'. (optional)
41
+ # @option tenants [Hash] :meta A JSON object containing additional information about the tenant (e.g. name/description, etc.) to be persisted to Warrant. (optional)
51
42
  #
52
43
  # @return [Array<Tenant>] all created tenants
53
44
  #
@@ -60,21 +51,14 @@ module Warrant
60
51
  # @raise [Warrant::InvalidRequestError]
61
52
  # @raise [Warrant::NotFoundError]
62
53
  # @raise [Warrant::UnauthorizedError]
63
- def self.batch_create(tenants = [])
64
- res = APIOperations.post(URI.parse("#{::Warrant.config.api_base}/v1/tenants"), Util.normalize_params(tenants))
65
-
66
- case res
67
- when Net::HTTPSuccess
68
- tenants = JSON.parse(res.body)
69
- tenants.map{ |tenant| Tenant.new(tenant['tenantId'], tenant['name'], tenant['createdAt']) }
70
- else
71
- APIOperations.raise_error(res)
72
- end
54
+ def self.batch_create(tenants, options = {})
55
+ res = Object.batch_create(tenants.map{ |tenant| { object_type: OBJECT_TYPE, object_id: tenant[:tenant_id], meta: tenant[:meta] }}, options)
56
+ return res.map{ |obj| Tenant.new(obj.object_id, obj.meta, obj.created_at)}
73
57
  end
74
58
 
75
59
  # Deletes a tenant with given tenant id
76
60
  #
77
- # @param tenant_id [String] User defined string identifier for this tenant. If not provided, Warrant will create an id for the tenant and return it. In this case, you should store the id in your system for future reference. Note that tenantIds in Warrant must be composed of alphanumeric chars and/or '-', '_', and '@'.
61
+ # @param tenant_id [String] User defined string identifier for this tenant.
78
62
  #
79
63
  # @return [nil] if delete was successful
80
64
  #
@@ -84,27 +68,44 @@ module Warrant
84
68
  # @raise [Warrant::InternalError]
85
69
  # @raise [Warrant::NotFoundError]
86
70
  # @raise [Warrant::UnauthorizedError]
87
- def self.delete(tenant_id)
88
- res = APIOperations.delete(URI.parse("#{::Warrant.config.api_base}/v1/tenants/#{tenant_id}"))
71
+ def self.delete(tenant_id, options = {})
72
+ return Object.delete(OBJECT_TYPE, tenant_id, options)
73
+ end
89
74
 
90
- case res
91
- when Net::HTTPSuccess
92
- return
93
- else
94
- APIOperations.raise_error(res)
95
- end
75
+ # Batch deletes multiple tenants with given parameters
76
+ #
77
+ # @param [Array<Hash, Tenant>] tenants Array of tenants to delete.
78
+ # @option tenants [String] :tenant_id Customer defined string identifier for this tenant.
79
+ #
80
+ # @return [nil] if delete was successful
81
+ #
82
+ # @example Delete two tenants with ids "test-tenant-1" and "test-tenant-2"
83
+ # Warrant::Tenant.batch_delete([{ tenant_id: "test-tenant-1" }, { tenant_id: "test-tenant-2" }])
84
+ #
85
+ # @raise [Warrant::InternalError]
86
+ # @raise [Warrant::InvalidParameterError]
87
+ # @raise [Warrant::NotFoundError]
88
+ # @raise [Warrant::UnauthorizedError]
89
+ def self.batch_delete(tenants, options = {})
90
+ return Object.batch_delete(tenants.map{ |tenant|
91
+ if tenant.instance_of? Tenant
92
+ { object_type: OBJECT_TYPE, object_id: tenant.object_id }
93
+ else
94
+ { object_type: OBJECT_TYPE, object_id: tenant[:tenant_id] }
95
+ end
96
+ }, options)
96
97
  end
97
98
 
98
99
  # Lists all tenants for your organization
99
100
  #
100
- # @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)
101
- # @option filters [Integer] :limit A positive integer representing the max number of items to return in response. (optional)
102
- # @option filters [String] :beforeId A string representing a cursor value in the form of a tenantId. If provided, the results returned are immediately before the provided value. (optional)
103
- # @option filters [String] :beforeValue A string representing a cursor value in the form of the `sortBy` value. If provided, the results returned are immediately before the provided value. (optional)
104
- # @option filters [String] :afterId A string representing a cursor value in the form of a tenantId. If provided, the results returned are immediately after the provided value. (optional)
105
- # @option filters [String] :afterValue A string representing a cursor value in the form of the `sortBy` value. If provided, the results returned are immediately after the provided value. (optional)
106
- # @option filters [String] :sortBy A string representing the field to sort results by. Default value is tenantId. (optional)
107
- # @option filters [String] :sortOrder A string representing whether to sort results in ascending or descending order. Must be ASC or DESC. (optional)
101
+ # @param [Hash] filters Filters to apply to result set
102
+ # @param [Hash] options Options to apply on a per-request basis
103
+ # @option filters [Integer] :limit A positive integer representing the maximum number of items to return in the response. Must be less than or equal to 1000. Defaults to 25. (optional)
104
+ # @option filters [String] :prev_cursor A cursor representing your place in a list of results. Requests containing prev_cursor will return the results immediately preceding the cursor. (optional)
105
+ # @option filters [String] :next_cursor A cursor representing your place in a list of results. Requests containing next_cursor will return the results immediately following the cursor. (optional)
106
+ # @option filters [String] :sort_by The column to sort the result by. Unless otherwise specified, all list endpoints are sorted by their unique identifier by default. Supported values for objects are +object_type+, +object_id+, and +created_at+ (optional)
107
+ # @option filters [String] :sort_order The order in which to sort the result by. Valid values are +ASC+ and +DESC+. Defaults to +ASC+. (optional)
108
+ # @option options [String] :warrant_token A valid warrant token from a previous write operation or latest. Used to specify desired consistency for this read operation. (optional)
108
109
  #
109
110
  # @return [Array<Tenant>] all tenants for your organization
110
111
  #
@@ -114,16 +115,11 @@ module Warrant
114
115
  # @raise [Warrant::InternalError]
115
116
  # @raise [Warrant::InvalidParameterError]
116
117
  # @raise [Warrant::UnauthorizedError]
117
- def self.list(filters = {})
118
- res = APIOperations.get(URI.parse("#{::Warrant.config.api_base}/v1/tenants"), Util.normalize_params(filters))
119
-
120
- case res
121
- when Net::HTTPSuccess
122
- tenants = JSON.parse(res.body)
123
- tenants.map{ |tenant| Tenant.new(tenant['tenantId'], tenant['name'], tenant['createdAt']) }
124
- else
125
- APIOperations.raise_error(res)
126
- end
118
+ def self.list(filters = {}, options = {})
119
+ filters.merge({ object_type: "tenant" })
120
+ list_response = Object.list(filters, options)
121
+ tenants = list_response.results.map{ |object| Tenant.new(object.object_id, object.meta, object.created_at)}
122
+ return ListResponse.new(tenants, list_response.prev_cursor, list_response.next_cursor)
127
123
  end
128
124
 
129
125
  # Get a tenant with the given tenant_id
@@ -136,67 +132,53 @@ module Warrant
136
132
  # @raise [Warrant::InvalidParameterError]
137
133
  # @raise [Warrant::NotFoundError]
138
134
  # @raise [Warrant::UnauthorizedError]
139
- def self.get(tenant_id)
140
- res = APIOperations.get(URI.parse("#{::Warrant.config.api_base}/v1/tenants/#{tenant_id}"))
141
-
142
- case res
143
- when Net::HTTPSuccess
144
- tenant = JSON.parse(res.body)
145
- Tenant.new(tenant['tenantId'], tenant['name'], tenant['createdAt'])
146
- else
147
- APIOperations.raise_error(res)
148
- end
135
+ def self.get(tenant_id, options = {})
136
+ object = Object.get(OBJECT_TYPE, tenant_id, options)
137
+ return Tenant.new(object.object_id, object.meta, object.created_at)
149
138
  end
150
139
 
151
- # Updates a tenant with the given tenant_id and params
140
+ # Updates a tenant with the given tenant_id
152
141
  #
153
- # @param tenant_id [String] User defined string identifier for this tenant. If not provided, Warrant will create an id for the tenant and return it. In this case, you should store the id in your system for future reference. Note that tenantIds in Warrant must be composed of alphanumeric chars and/or '-', '_', and '@'.
154
- # @param [Hash] params attributes to update tenant with
155
- # @option params [String] :name A displayable name for this tenant. (optional)
142
+ # @param tenant_id [String] User defined string identifier for this tenant.
143
+ # @param meta [Hash] A JSON object containing additional information about this tenant (e.g. name/description, etc.) to be persisted to Warrant.
156
144
  #
157
145
  # @return [Tenant] updated tenant
158
146
  #
159
- # @example Update tenant "test-tenant"'s name
160
- # Warrant::Tenant.update("test-tenant", { name: "my-new-name@example.com" })
147
+ # @example Update tenant "test-tenant"'s email
148
+ # Warrant::Tenant.update("test-tenant", { email: "my-new-email@example.com" })
161
149
  #
162
150
  # @raise [Warrant::InternalError]
163
151
  # @raise [Warrant::InvalidParameterError]
164
152
  # @raise [Warrant::InvalidRequestError]
165
153
  # @raise [Warrant::NotFoundError]
166
154
  # @raise [Warrant::UnauthorizedError]
167
- def self.update(tenant_id, params = {})
168
- res = APIOperations.put(URI.parse("#{::Warrant.config.api_base}/v1/tenants/#{tenant_id}"), Util.normalize_params(params))
169
-
170
- case res
171
- when Net::HTTPSuccess
172
- res_json = JSON.parse(res.body)
173
- Tenant.new(res_json['tenantId'], res_json['name'], res_json['createdAt'])
174
- else
175
- APIOperations.raise_error(res)
176
- end
155
+ def self.update(tenant_id, meta, options = {})
156
+ object = Object.update(OBJECT_TYPE, tenant_id, meta, options)
157
+ return Tenant.new(object.object_id, object.meta, object.created_at)
177
158
  end
178
159
 
179
160
  # Updates the tenant with the given params
180
161
  #
181
- # @option params [String] :name A displayable name for this tenant. (optional)
162
+ # @param meta [Hash] A JSON object containing additional information about this tenant (e.g. name/description, etc.) to be persisted to Warrant.
182
163
  #
183
164
  # @return [Tenant] updated tenant
184
165
  #
185
166
  # @example Update tenant "test-tenant"'s name
186
167
  # tenant = Warrant::Tenant.get("test-tenant")
187
- # tenant.update(name: "my-new-name@example.com")
168
+ # tenant.update({ name: "my-new-name@example.com" })
188
169
  #
189
170
  # @raise [Warrant::InternalError]
190
171
  # @raise [Warrant::InvalidParameterError]
191
172
  # @raise [Warrant::NotFoundError]
192
173
  # @raise [Warrant::UnauthorizedError]
193
- def update(params = {})
194
- return Tenant.update(tenant_id, params)
174
+ def update(meta, options = {})
175
+ return Tenant.update(tenant_id, meta, options)
195
176
  end
196
177
 
197
178
  # Add a user to a tenant
198
179
  #
199
180
  # @param user_id [String] The user_id of the user you want to add to the tenant.
181
+ # @param relation [String] The relation for this tenant to user association. The relation must be valid as per the +tenant+ object type definition.
200
182
  #
201
183
  # @return [Warrant] warrant assigning user to the tenant
202
184
  #
@@ -205,13 +187,14 @@ module Warrant
205
187
  # @raise [Warrant::InvalidParameterError]
206
188
  # @raise [Warrant::NotFoundError]
207
189
  # @raise [Warrant::UnauthorizedError]
208
- def assign_user(user_id)
209
- return User.assign_to_tenant(tenant_id, user_id)
190
+ def assign_user(user_id, relation: "member", options: {})
191
+ return User.assign_to_tenant(tenant_id, user_id, relation: relation, options: options)
210
192
  end
211
193
 
212
194
  # Remove a user from a tenant
213
195
  #
214
196
  # @param user_id [String] The user_id of the user you want to remove from the tenant.
197
+ # @param relation [String] The relation for this tenant to user association. The relation must be valid as per the +tenant+ object type definition.
215
198
  #
216
199
  # @return [nil] if remove was successful
217
200
  #
@@ -219,37 +202,32 @@ module Warrant
219
202
  # @raise [Warrant::NotFoundError]
220
203
  # @raise [Warrant::UnauthorizedError]
221
204
  # @raise [Warrant::WarrantError]
222
- def remove_user(user_id)
223
- return User.remove_from_tenant(tenant_id, user_id)
205
+ def remove_user(user_id, relation: "member", options: {})
206
+ return User.remove_from_tenant(tenant_id, user_id, relation: relation, options: options)
224
207
  end
225
208
 
226
209
  # List all tenants for a user
227
210
  #
228
211
  # @param user_id [String] The user_id of the user from which to fetch tenants
229
- # @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)
230
- # @option filters [Integer] :limit A positive integer representing the max number of items to return in response. (optional)
231
- # @option filters [String] :beforeId A string representing a cursor value in the form of a tenantId. If provided, the results returned are immediately before the provided value. (optional)
232
- # @option filters [String] :beforeValue A string representing a cursor value in the form of the `sortBy` value. If provided, the results returned are immediately before the provided value. (optional)
233
- # @option filters [String] :afterId A string representing a cursor value in the form of a tenantId. If provided, the results returned are immediately after the provided value. (optional)
234
- # @option filters [String] :afterValue A string representing a cursor value in the form of the `sortBy` value. If provided, the results returned are immediately after the provided value. (optional)
235
- # @option filters [String] :sortBy A string representing the field to sort results by. Default value is tenantId. (optional)
236
- # @option filters [String] :sortOrder A string representing whether to sort results in ascending or descending order. Must be ASC or DESC. (optional)
212
+ # @param [Hash] filters Filters to apply to result set
213
+ # @param [Hash] options Options to apply on a per-request basis
214
+ # @option filters [String] :object_type Only return objects with an `objectType` matching this value
215
+ # @option filters [Integer] :limit A positive integer representing the maximum number of items to return in the response. Must be less than or equal to 1000. Defaults to 25. (optional)
216
+ # @option filters [String] :prev_cursor A cursor representing your place in a list of results. Requests containing prev_cursor will return the results immediately preceding the cursor. (optional)
217
+ # @option filters [String] :next_cursor A cursor representing your place in a list of results. Requests containing next_cursor will return the results immediately following the cursor. (optional)
218
+ # @option filters [String] :sort_by The column to sort the result by. Unless otherwise specified, all list endpoints are sorted by their unique identifier by default. Supported values for objects are +object_type+, +object_id+, and +created_at+ (optional)
219
+ # @option filters [String] :sort_order The order in which to sort the result by. Valid values are +ASC+ and +DESC+. Defaults to +ASC+. (optional)
220
+ # @option options [String] :warrant_token A valid warrant token from a previous write operation or latest. Used to specify desired consistency for this read operation. (optional)
237
221
  #
238
222
  # @return [Array<Tenant>] all tenants for the user
239
223
  #
240
224
  # @raise [Warrant::InternalError]
241
225
  # @raise [Warrant::InvalidParameterError]
242
226
  # @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}/tenants"), Util.normalize_params(filters))
245
-
246
- case res
247
- when Net::HTTPSuccess
248
- tenants = JSON.parse(res.body)
249
- tenants.map{ |tenant| Tenant.new(tenant['tenantId'], tenant['name'], tenant['createdAt']) }
250
- else
251
- APIOperations.raise_error(res)
252
- end
227
+ def self.list_for_user(user_id, filters = {}, options = {})
228
+ query_response = Warrant.query("select tenant where user:#{user_id} is *", filters: filters, options: options)
229
+ tenants = query_response.results.map{ |result| Tenant.new(result.object_id, result.meta) }
230
+ return ListResponse.new(tenants, query_response.prev_cursor, query_response.next_cursor)
253
231
  end
254
232
 
255
233
  # List all users for a tenant
@@ -260,27 +238,35 @@ module Warrant
260
238
  # @raise [Warrant::InvalidRequestError]
261
239
  # @raise [Warrant::UnauthorizedError]
262
240
  # @raise [Warrant::WarrantError]
263
- def list_users
264
- return User.list_for_tenant(tenant_id)
241
+ def list_users(filters = {}, options = {})
242
+ return User.list_for_tenant(tenant_id, filters, options)
265
243
  end
266
244
 
267
245
  # List pricing tiers for a tenant
268
246
  #
269
- # @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)
270
- # @option filters [Integer] :limit A positive integer representing the max number of items to return in response. (optional)
247
+ # @param [Hash] filters Filters to apply to result set
248
+ # @param [Hash] options Options to apply on a per-request basis
249
+ # @option filters [String] :object_type Only return objects with an `objectType` matching this value
250
+ # @option filters [Integer] :limit A positive integer representing the maximum number of items to return in the response. Must be less than or equal to 1000. Defaults to 25. (optional)
251
+ # @option filters [String] :prev_cursor A cursor representing your place in a list of results. Requests containing prev_cursor will return the results immediately preceding the cursor. (optional)
252
+ # @option filters [String] :next_cursor A cursor representing your place in a list of results. Requests containing next_cursor will return the results immediately following the cursor. (optional)
253
+ # @option filters [String] :sort_by The column to sort the result by. Unless otherwise specified, all list endpoints are sorted by their unique identifier by default. Supported values for objects are +object_type+, +object_id+, and +created_at+ (optional)
254
+ # @option filters [String] :sort_order The order in which to sort the result by. Valid values are +ASC+ and +DESC+. Defaults to +ASC+. (optional)
255
+ # @option options [String] :warrant_token A valid warrant token from a previous write operation or latest. Used to specify desired consistency for this read operation. (optional)
271
256
  #
272
257
  # @return [Array<Feature>] assigned pricing tiers for the tenant
273
258
  #
274
259
  # @raise [Warrant::InternalError]
275
260
  # @raise [Warrant::InvalidParameterError]
276
261
  # @raise [Warrant::UnauthorizedError]
277
- def list_pricing_tiers(filters = {})
278
- return PricingTier.list_for_tenant(tenant_id, filters)
262
+ def list_pricing_tiers(filters = {}, options = {})
263
+ return PricingTier.list_for_tenant(tenant_id, filters, options)
279
264
  end
280
265
 
281
266
  # Assign a pricing tier to a tenant
282
267
  #
283
268
  # @param pricing_tier_id [String] The pricing_tier_id of the pricing tier you want to assign to the tenant.
269
+ # @param relation [String] The relation for this pricing tier to tenant association. The relation must be valid as per the +pricing tier+ object type definition.
284
270
  #
285
271
  # @return [PricingTier] assigned pricing tier
286
272
  #
@@ -289,13 +275,14 @@ module Warrant
289
275
  # @raise [Warrant::InvalidParameterError]
290
276
  # @raise [Warrant::NotFoundError]
291
277
  # @raise [Warrant::UnauthorizedError]
292
- def assign_pricing_tier(pricing_tier_id)
293
- return PricingTier.assign_to_tenant(tenant_id, pricing_tier_id)
278
+ def assign_pricing_tier(pricing_tier_id, relation: "member", options: {})
279
+ return PricingTier.assign_to_tenant(tenant_id, pricing_tier_id, relation: relation, options: options)
294
280
  end
295
281
 
296
282
  # Remove a pricing_tier from a tenant
297
283
  #
298
284
  # @param pricing_tier_id [String] The pricing_tier_id of the pricing_tier you want to remove from the tenant.
285
+ # @param relation [String] The relation for this pricing tier to tenant association. The relation must be valid as per the +pricing tier+ object type definition.
299
286
  #
300
287
  # @return [nil] if remove was successful
301
288
  #
@@ -304,27 +291,35 @@ module Warrant
304
291
  # @raise [Warrant::NotFoundError]
305
292
  # @raise [Warrant::UnauthorizedError]
306
293
  # @raise [Warrant::WarrantError]
307
- def remove_pricing_tier(pricing_tier_id)
308
- return PricingTier.remove_from_tenant(tenant_id, pricing_tier_id)
294
+ def remove_pricing_tier(pricing_tier_id, relation: "member", options: {})
295
+ return PricingTier.remove_from_tenant(tenant_id, pricing_tier_id, relation: relation, options: options)
309
296
  end
310
297
 
311
298
  # List features for a tenant
312
299
  #
313
- # @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)
314
- # @option filters [Integer] :limit A positive integer representing the max number of items to return in response. (optional)
300
+ # @param [Hash] filters Filters to apply to result set
301
+ # @param [Hash] options Options to apply on a per-request basis
302
+ # @option filters [String] :object_type Only return objects with an `objectType` matching this value
303
+ # @option filters [Integer] :limit A positive integer representing the maximum number of items to return in the response. Must be less than or equal to 1000. Defaults to 25. (optional)
304
+ # @option filters [String] :prev_cursor A cursor representing your place in a list of results. Requests containing prev_cursor will return the results immediately preceding the cursor. (optional)
305
+ # @option filters [String] :next_cursor A cursor representing your place in a list of results. Requests containing next_cursor will return the results immediately following the cursor. (optional)
306
+ # @option filters [String] :sort_by The column to sort the result by. Unless otherwise specified, all list endpoints are sorted by their unique identifier by default. Supported values for objects are +object_type+, +object_id+, and +created_at+ (optional)
307
+ # @option filters [String] :sort_order The order in which to sort the result by. Valid values are +ASC+ and +DESC+. Defaults to +ASC+. (optional)
308
+ # @option options [String] :warrant_token A valid warrant token from a previous write operation or latest. Used to specify desired consistency for this read operation. (optional)
315
309
  #
316
310
  # @return [Array<Feature>] assigned features for the tenant
317
311
  #
318
312
  # @raise [Warrant::InternalError]
319
313
  # @raise [Warrant::InvalidParameterError]
320
314
  # @raise [Warrant::UnauthorizedError]
321
- def list_features(filters = {})
322
- return Feature.list_for_tenant(tenant_id, filters)
315
+ def list_features(filters = {}, options = {})
316
+ return Feature.list_for_tenant(tenant_id, filters, options)
323
317
  end
324
318
 
325
319
  # Assign a feature to a tenant
326
320
  #
327
321
  # @param feature_id [String] The feature_id of the feature you want to assign to the tenant.
322
+ # @param relation [String] The relation for this feature to tenant association. The relation must be valid as per the +feature+ object type definition.
328
323
  #
329
324
  # @return [Feature] assigned feature
330
325
  #
@@ -333,13 +328,14 @@ module Warrant
333
328
  # @raise [Warrant::InvalidParameterError]
334
329
  # @raise [Warrant::NotFoundError]
335
330
  # @raise [Warrant::UnauthorizedError]
336
- def assign_feature(feature_id)
337
- return Feature.assign_to_tenant(tenant_id, feature_id)
331
+ def assign_feature(feature_id, relation: "member", options: {})
332
+ return Feature.assign_to_tenant(tenant_id, feature_id, relation: relation, options: options)
338
333
  end
339
334
 
340
335
  # Remove a feature from a tenant
341
336
  #
342
337
  # @param feature_id [String] The feature_id of the feature you want to remove from the tenant.
338
+ # @param relation [String] The relation for this feature to tenant association. The relation must be valid as per the +feature+ object type definition.
343
339
  #
344
340
  # @return [nil] if remove was successful
345
341
  #
@@ -348,32 +344,34 @@ module Warrant
348
344
  # @raise [Warrant::NotFoundError]
349
345
  # @raise [Warrant::UnauthorizedError]
350
346
  # @raise [Warrant::WarrantError]
351
- def remove_feature(feature_id)
352
- return Feature.remove_from_tenant(tenant_id, feature_id)
347
+ def remove_feature(feature_id, relation: "member", options: {})
348
+ return Feature.remove_from_tenant(tenant_id, feature_id, relation: relation, options: options)
353
349
  end
354
350
 
355
351
  # Check whether a tenant has a given feature
356
352
  #
357
353
  # @param feature_id [String] The feature_id of the feature to check whether the tenant has access to.
354
+ # @param relation [String] The relation for this feature to tenant association. The relation must be valid as per the +feature+ object type definition.
358
355
  # @option options [Hash] :context Object containing key-value pairs that specifies the context the warrant should be checked in. (optional)
359
356
  # @option options [Boolean] :debug Boolean flag indicating whether or not to return debug information for this access check. Defaults to false. (optional)
360
357
  #
361
- # @ return [Boolean] whether or not the tenant has the given feature
358
+ # @return [Boolean] whether or not the tenant has the given feature
362
359
  #
363
360
  # @raise [Warrant::InternalError]
364
361
  # @raise [Warrant::InvalidParameterError]
365
362
  # @raise [Warrant::NotFoundError]
366
363
  # @raise [Warrant::UnauthorizedError]
367
- def has_feature?(feature_id, opts = {})
368
- return Warrant.has_feature?(
364
+ def has_feature?(feature_id, relation: "member", options: {})
365
+ return Warrant.has_feature?({
369
366
  feature_id: feature_id,
367
+ relation: relation,
370
368
  subject: {
371
369
  object_type: "tenant",
372
370
  object_id: tenant_id
373
371
  },
374
- context: opts[:context],
375
- debug: opts[:debug]
376
- )
372
+ context: options[:context],
373
+ debug: options[:debug]
374
+ }, options)
377
375
  end
378
376
 
379
377
  def warrant_object_type