warrant 4.0.0 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e1faca7fd1a9bdcb8ae4f6c4a6ac5bc68a138cca35d3eafcb888de554156f4c5
4
- data.tar.gz: 7bc91b0ebf6e9cf0dd442b19edc6b6f0514b3008cf89e4ddc448fd4def3bf12c
3
+ metadata.gz: e2f6af0b73e1d0ade950db2c0bce0e14176bb3f380914099ea5bb21382076ba0
4
+ data.tar.gz: 973470f3ac7c430e07258004d9e425d39ce338c7130ce9a23e694c49f6411286
5
5
  SHA512:
6
- metadata.gz: b849e8be7fc0105a11677ab6aa901221c45e8f70cc3e0baf2ff4b4c590816a841536aece028d9e1d386267d654192fd61f081991ddb39b3b7c93e0c672e93168
7
- data.tar.gz: 7f653279a31b8b96beb09f8e255ad19680bd3d2602c14a025b0a9e5820523264acb58568d6a6d85ccc265fc73b136040c22a5c1bff86e8bccfe6e9057382a83e
6
+ metadata.gz: 6d6a7b4e2b0a7a69a31ce8f04b6bb856edf7d4793795a237f3ba23a46cb3f9aab09caab3ab0511c005f7c018384d9c325987194e61956dfda0588274b7b74ce1
7
+ data.tar.gz: c488dc7bdc1d19775e793efe3eff35c785c870409e70c76c997f15473de93bb8b4f42f9203e4d807e0c5c7b90f641da286b2f4d067335664c441225522dc217a
@@ -4,49 +4,51 @@ module Warrant
4
4
  # @!visibility private
5
5
  class APIOperations
6
6
  class << self
7
- def post(uri, params = {})
7
+ def post(uri, params: {}, options: {})
8
8
  http = Net::HTTP.new(uri.host, uri.port)
9
9
  http.use_ssl = ::Warrant.config.use_ssl
10
10
  headers = {
11
11
  "User-Agent": "warrant-ruby/#{VERSION}"
12
12
  }
13
13
  headers["Authorization"] = "ApiKey #{::Warrant.config.api_key}" unless ::Warrant.config.api_key.empty?
14
+ headers["Warrant-Token"] = options[:warrant_token] if options.has_key?(:warrant_token)
14
15
  http.post(uri.path, params.to_json, headers)
15
16
  end
16
17
 
17
- def delete(uri, params = {})
18
+ def delete(uri, params: {}, options: {})
18
19
  http = Net::HTTP.new(uri.host, uri.port)
19
20
  http.use_ssl = ::Warrant.config.use_ssl
20
21
  request = Net::HTTP::Delete.new(uri.path)
21
22
  request["Authorization"] = "ApiKey #{::Warrant.config.api_key}" unless ::Warrant.config.api_key.empty?
22
23
  request["User-Agent"] = "warrant-ruby/#{VERSION}"
23
-
24
+ headers["Warrant-Token"] = options[:warrant_token] if options.has_key?(:warrant_token)
24
25
  http.request(request, params.to_json)
25
26
  end
26
27
 
27
- def get(uri, params = {})
28
+ def get(uri, params: {}, options: {})
28
29
  http = Net::HTTP.new(uri.host, uri.port)
29
30
  http.use_ssl = ::Warrant.config.use_ssl
30
31
  headers = {
31
32
  "User-Agent": "warrant-ruby/#{VERSION}"
32
33
  }
33
34
  headers["Authorization"] = "ApiKey #{::Warrant.config.api_key}" unless ::Warrant.config.api_key.empty?
35
+ headers["Warrant-Token"] = options[:warrant_token] if options.has_key?(:warrant_token)
34
36
 
35
37
  unless params.empty?
36
- normalized_params = Util.normalize_params(params.compact)
37
- uri.query = URI.encode_www_form(normalized_params)
38
+ uri.query = URI.encode_www_form(params)
38
39
  end
39
40
 
40
41
  http.get(uri, headers)
41
42
  end
42
43
 
43
- def put(uri, params = {})
44
+ def put(uri, params: {}, options: {})
44
45
  http = Net::HTTP.new(uri.host, uri.port)
45
46
  http.use_ssl = ::Warrant.config.use_ssl
46
47
  headers = {
47
48
  "User-Agent": "warrant-ruby/#{VERSION}"
48
49
  }
49
50
  headers["Authorization"] = "ApiKey #{::Warrant.config.api_key}" unless ::Warrant.config.api_key.empty?
51
+ headers["Warrant-Token"] = options[:warrant_token] if options.has_key?(:warrant_token)
50
52
  http.put(uri.path, params.to_json, headers)
51
53
  end
52
54
 
@@ -1,21 +1,22 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Warrant
4
- class Feature
4
+ class Feature < Warrant::Object
5
5
  OBJECT_TYPE = "feature"
6
6
 
7
7
  include Warrant::WarrantObject
8
8
 
9
- attr_reader :feature_id
9
+ alias :feature_id :object_id
10
10
 
11
11
  # @!visibility private
12
- def initialize(feature_id)
13
- @feature_id = feature_id
12
+ def initialize(feature_id, meta = {}, created_at = nil)
13
+ super(OBJECT_TYPE, feature_id, meta, created_at)
14
14
  end
15
15
 
16
16
  # Creates a feature with the given parameters
17
17
  #
18
- # @option params [String] :feature_id A string identifier for this new feature. The feature_id can only be composed of lower-case alphanumeric chars and/or '-' and '_'.
18
+ # @option params [String] :feature_id User defined string identifier for this feature. If not provided, Warrant will create an id for the feature and return it. In this case, you should store the id in your system as you will need to provide it for any authorization requests for that feature. Note that featureIds in Warrant must be composed of alphanumeric chars, '-', and/or '_'. (optional)
19
+ # @option params [Hash] :meta A JSON object containing additional information about this feature (e.g. name/description) to be persisted to Warrant. (optional)
19
20
  #
20
21
  # @return [Feature] created feature
21
22
  #
@@ -26,16 +27,9 @@ module Warrant
26
27
  # @raise [Warrant::InternalError]
27
28
  # @raise [Warrant::InvalidRequestError]
28
29
  # @raise [Warrant::UnauthorizedError]
29
- def self.create(params = {})
30
- res = APIOperations.post(URI.parse("#{::Warrant.config.api_base}/v1/features"), Util.normalize_params(params))
31
-
32
- case res
33
- when Net::HTTPSuccess
34
- res_json = JSON.parse(res.body)
35
- Feature.new(res_json['featureId'])
36
- else
37
- APIOperations.raise_error(res)
38
- end
30
+ def self.create(params = {}, options = {})
31
+ object = Object.create({ object_type: OBJECT_TYPE, object_id: params[:feature_id], meta: params[:meta] }, options)
32
+ return Feature.new(object.object_id, object.meta, object.created_at)
39
33
  end
40
34
 
41
35
  # Deletes a feature with given feature id
@@ -51,27 +45,20 @@ module Warrant
51
45
  # @raise [Warrant::InvalidParameterError]
52
46
  # @raise [Warrant::NotFoundError]
53
47
  # @raise [Warrant::UnauthorizedError]
54
- def self.delete(feature_id)
55
- res = APIOperations.delete(URI.parse("#{::Warrant.config.api_base}/v1/features/#{feature_id}"))
56
-
57
- case res
58
- when Net::HTTPSuccess
59
- return
60
- else
61
- APIOperations.raise_error(res)
62
- end
48
+ def self.delete(feature_id, options = {})
49
+ return Object.delete(OBJECT_TYPE, feature_id, options)
63
50
  end
64
51
 
65
52
  # Lists all features for your organization
66
53
  #
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
- # @option filters [String] :beforeId A string representing a cursor value in the form of a featureId. If provided, the results returned are immediately before the provided value. (optional)
70
- # @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)
71
- # @option filters [String] :afterId A string representing a cursor value in the form of a featureId. If provided, the results returned are immediately after the provided value. (optional)
72
- # @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)
73
- # @option filters [String] :sortBy A string representing the field to sort results by. Default value is featureId. (optional)
74
- # @option filters [String] :sortOrder A string representing whether to sort results in ascending or descending order. Must be ASC or DESC. (optional)
54
+ # @param [Hash] filters Filters to apply to result set
55
+ # @param [Hash] options Options to apply on a per-request basis
56
+ # @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)
57
+ # @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)
58
+ # @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)
59
+ # @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)
60
+ # @option filters [String] :sort_order The order in which to sort the result by. Valid values are +ASC+ and +DESC+. Defaults to +ASC+. (optional)
61
+ # @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)
75
62
  #
76
63
  # @return [Array<Feature>] all features for your organization
77
64
  #
@@ -80,16 +67,11 @@ module Warrant
80
67
  #
81
68
  # @raise [Warrant::InternalError]
82
69
  # @raise [Warrant::UnauthorizedError]
83
- def self.list(filters = {})
84
- res = APIOperations.get(URI.parse("#{::Warrant.config.api_base}/v1/features"), Util.normalize_params(filters))
85
-
86
- case res
87
- when Net::HTTPSuccess
88
- features = JSON.parse(res.body)
89
- features.map{ |feature| Feature.new(feature['featureId']) }
90
- else
91
- APIOperations.raise_error(res)
92
- end
70
+ def self.list(filters = {}, options = {})
71
+ filters.merge({ object_type: OBJECT_TYPE })
72
+ list_response = Object.list(filters, options)
73
+ features = list_response.results.map{ |object| Feature.new(object.object_id, object.meta, object.created_at)}
74
+ return ListResponse.new(features, list_response.prev_cursor, list_response.next_cursor)
93
75
  end
94
76
 
95
77
  # Get a feature with the given feature_id
@@ -102,45 +84,79 @@ module Warrant
102
84
  # @raise [Warrant::InvalidParameterError]
103
85
  # @raise [Warrant::NotFoundError]
104
86
  # @raise [Warrant::UnauthorizedError]
105
- def self.get(feature_id)
106
- res = APIOperations.get(URI.parse("#{::Warrant.config.api_base}/v1/features/#{feature_id}"))
87
+ def self.get(feature_id, options = {})
88
+ object = Object.get(OBJECT_TYPE, feature_id, options)
89
+ return Feature.new(object.object_id, object.meta, object.created_at)
90
+ end
107
91
 
108
- case res
109
- when Net::HTTPSuccess
110
- feature = JSON.parse(res.body)
111
- Feature.new(feature['featureId'])
112
- else
113
- APIOperations.raise_error(res)
114
- end
92
+ # Updates a feature with the given feature_id and params
93
+ #
94
+ # @param feature_id [String] The feature_id of the feature to be updated.
95
+ # @param meta [Hash] A JSON object containing additional information about this feature (e.g. name/description, etc.) to be persisted to Warrant.
96
+ #
97
+ # @return [Feature] updated feature
98
+ #
99
+ # @example Update feature "test-feature"'s name
100
+ # Warrant::Feature.update("test-feature", { name: "Test Feature" })
101
+ #
102
+ # @raise [Warrant::InternalError]
103
+ # @raise [Warrant::InvalidParameterError]
104
+ # @raise [Warrant::InvalidRequestError]
105
+ # @raise [Warrant::NotFoundError]
106
+ # @raise [Warrant::UnauthorizedError]
107
+ def self.update(feature_id, meta, options = {})
108
+ object = Object.update(OBJECT_TYPE, feature_id, meta, options)
109
+ return Feature.new(object.object_id, object.meta, object.created_at)
110
+ end
111
+
112
+ # Updates a feature with the given params
113
+ #
114
+ # @param meta [Hash] A JSON object containing additional information about this feature (e.g. name/description, etc.) to be persisted to Warrant.
115
+ #
116
+ # @return [Feature] updated feature
117
+ #
118
+ # @example Update feature "test-feature"'s name
119
+ # feature = Warrant::Feature.get("test-feature")
120
+ # feature.update({ name: "Test Feature" })
121
+ #
122
+ # @raise [Warrant::InternalError]
123
+ # @raise [Warrant::InvalidParameterError]
124
+ # @raise [Warrant::InvalidRequestError]
125
+ # @raise [Warrant::NotFoundError]
126
+ # @raise [Warrant::UnauthorizedError]
127
+ def update(meta, options = {})
128
+ return Feature.update(feature_id, meta)
115
129
  end
116
130
 
117
131
  # List features for tenant
118
132
  #
119
133
  # @param tenant_id [String] The tenant_id of the tenant to list features for.
120
- # @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)
121
- # @option filters [Integer] :limit A positive integer representing the max number of items to return in response. (optional)
134
+ # @param [Hash] filters Filters to apply to result set
135
+ # @param [Hash] options Options to apply on a per-request basis
136
+ # @option filters [String] :object_type Only return objects with an `objectType` matching this value
137
+ # @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)
138
+ # @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)
139
+ # @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)
140
+ # @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)
141
+ # @option filters [String] :sort_order The order in which to sort the result by. Valid values are +ASC+ and +DESC+. Defaults to +ASC+. (optional)
142
+ # @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)
122
143
  #
123
144
  # @return [Array<Feature>] assigned features for the tenant
124
145
  #
125
146
  # @raise [Warrant::InternalError]
126
147
  # @raise [Warrant::InvalidParameterError]
127
148
  # @raise [Warrant::UnauthorizedError]
128
- def self.list_for_tenant(tenant_id, filters = {})
129
- res = APIOperations.get(URI.parse("#{::Warrant.config.api_base}/v1/tenants/#{tenant_id}/features"), Util.normalize_params(filters))
130
-
131
- case res
132
- when Net::HTTPSuccess
133
- features = JSON.parse(res.body)
134
- features.map{ |feature| Feature.new(feature['featureId']) }
135
- else
136
- APIOperations.raise_error(res)
137
- end
149
+ def self.list_for_tenant(tenant_id, filters = {}, options = {})
150
+ query_response = Warrant.query("select feature where tenant:#{tenant_id} is *", filters: filters, options: options)
151
+ features = query_response.results.map{ |result| Feature.new(result.object_id, result.meta) }
152
+ return ListResponse.new(features, query_response.prev_cursor, query_response.next_cursor)
138
153
  end
139
154
 
140
155
  # Assign a feature to a tenant
141
156
  #
142
157
  # @param tenant_id [String] The tenant_id of the tenant you want to assign a feature to.
143
158
  # @param feature_id [String] The feature_id of the feature you want to assign to a tenant.
159
+ # @param relation [String] The relation for this feature to tenant association. The relation must be valid as per the +feature+ object type definition.
144
160
  #
145
161
  # @return [Warrant] warrant assigning feature to tenant
146
162
  #
@@ -149,14 +165,15 @@ module Warrant
149
165
  # @raise [Warrant::InvalidParameterError]
150
166
  # @raise [Warrant::NotFoundError]
151
167
  # @raise [Warrant::UnauthorizedError]
152
- def self.assign_to_tenant(tenant_id, feature_id)
153
- Warrant.create({ object_type: Feature::OBJECT_TYPE, object_id: feature_id }, "member", { object_type: Tenant::OBJECT_TYPE, object_id: tenant_id })
168
+ def self.assign_to_tenant(tenant_id, feature_id, relation: "member", options: {})
169
+ Warrant.create({ object_type: Feature::OBJECT_TYPE, object_id: feature_id }, relation, { object_type: Tenant::OBJECT_TYPE, object_id: tenant_id }, nil, options)
154
170
  end
155
171
 
156
172
  # Remove a feature from a tenant
157
173
  #
158
174
  # @param tenant_id [String] The tenant_id of the tenant you want to remove a feature from.
159
175
  # @param feature_id [String] The feature_id of the feature you want to remove from a tenant.
176
+ # @param relation [String] The relation for this feature to tenant association. The relation must be valid as per the +feature+ object type definition.
160
177
  #
161
178
  # @return [nil] if remove was successful
162
179
  #
@@ -165,37 +182,39 @@ module Warrant
165
182
  # @raise [Warrant::NotFoundError]
166
183
  # @raise [Warrant::UnauthorizedError]
167
184
  # @raise [Warrant::WarrantError]
168
- def self.remove_from_tenant(tenant_id, feature_id)
169
- Warrant.delete({ object_type: Feature::OBJECT_TYPE, object_id: feature_id }, "member", { object_type: Tenant::OBJECT_TYPE, object_id: tenant_id })
185
+ def self.remove_from_tenant(tenant_id, feature_id, relation: "member", options: {})
186
+ Warrant.delete({ object_type: Feature::OBJECT_TYPE, object_id: feature_id }, relation, { object_type: Tenant::OBJECT_TYPE, object_id: tenant_id }, nil, options)
170
187
  end
171
188
 
172
189
  # List features for user
173
190
  #
174
191
  # @param user_id [String] The user_id of the user to list features for.
175
- # @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)
176
- # @option filters [Integer] :limit A positive integer representing the max number of items to return in response. (optional)
192
+ # @param [Hash] filters Filters to apply to result set
193
+ # @param [Hash] options Options to apply on a per-request basis
194
+ # @option filters [String] :object_type Only return objects with an `objectType` matching this value
195
+ # @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)
196
+ # @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)
197
+ # @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)
198
+ # @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)
199
+ # @option filters [String] :sort_order The order in which to sort the result by. Valid values are +ASC+ and +DESC+. Defaults to +ASC+. (optional)
200
+ # @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)
177
201
  #
178
202
  # @return [Array<Feature>] assigned features for the user
179
203
  #
180
204
  # @raise [Warrant::InternalError]
181
205
  # @raise [Warrant::InvalidParameterError]
182
206
  # @raise [Warrant::UnauthorizedError]
183
- def self.list_for_user(user_id, filters = {})
184
- res = APIOperations.get(URI.parse("#{::Warrant.config.api_base}/v1/users/#{user_id}/features"), Util.normalize_params(filters))
185
-
186
- case res
187
- when Net::HTTPSuccess
188
- features = JSON.parse(res.body)
189
- features.map{ |feature| Feature.new(feature['featureId']) }
190
- else
191
- APIOperations.raise_error(res)
192
- end
207
+ def self.list_for_user(user_id, filters = {}, options = {})
208
+ query_response = Warrant.query("select feature where user:#{user_id} is *", filters: filters, options: options)
209
+ features = query_response.results.map{ |result| Feature.new(result.object_id, result.meta) }
210
+ return ListResponse.new(features, query_response.prev_cursor, query_response.next_cursor)
193
211
  end
194
212
 
195
213
  # Assign a feature to a user
196
214
  #
197
215
  # @param user_id [String] The user_id of the user you want to assign a feature to.
198
216
  # @param feature_id [String] The feature_id of the feature you want to assign to a user.
217
+ # @param relation [String] The relation for this feature to user association. The relation must be valid as per the +feature+ object type definition.
199
218
  #
200
219
  # @return [Warrant] warrant assigning feature to user
201
220
  #
@@ -204,14 +223,15 @@ module Warrant
204
223
  # @raise [Warrant::InvalidParameterError]
205
224
  # @raise [Warrant::NotFoundError]
206
225
  # @raise [Warrant::UnauthorizedError]
207
- def self.assign_to_user(user_id, feature_id)
208
- Warrant.create({ object_type: Feature::OBJECT_TYPE, object_id: feature_id }, "member", { object_type: User::OBJECT_TYPE, object_id: user_id })
226
+ def self.assign_to_user(user_id, feature_id, relation: "member", options: {})
227
+ Warrant.create({ object_type: Feature::OBJECT_TYPE, object_id: feature_id }, relation, { object_type: User::OBJECT_TYPE, object_id: user_id }, nil, options)
209
228
  end
210
229
 
211
230
  # Remove a feature from a user
212
231
  #
213
232
  # @param user_id [String] The user_id of the user you want to remove a feature from.
214
233
  # @param feature_id [String] The feature_id of the feature you want to remove from a user.
234
+ # @param relation [String] The relation for this feature to user association. The relation must be valid as per the +feature+ object type definition.
215
235
  #
216
236
  # @return [nil] if remove was successful
217
237
  #
@@ -220,37 +240,39 @@ module Warrant
220
240
  # @raise [Warrant::NotFoundError]
221
241
  # @raise [Warrant::UnauthorizedError]
222
242
  # @raise [Warrant::WarrantError]
223
- def self.remove_from_user(user_id, feature_id)
224
- Warrant.delete({ object_type: Feature::OBJECT_TYPE, object_id: feature_id }, "member", { object_type: User::OBJECT_TYPE, object_id: user_id })
243
+ def self.remove_from_user(user_id, feature_id, relation: "member", options: {})
244
+ Warrant.delete({ object_type: Feature::OBJECT_TYPE, object_id: feature_id }, relation, { object_type: User::OBJECT_TYPE, object_id: user_id }, nil, options)
225
245
  end
226
246
 
227
247
  # List features for pricing tier
228
248
  #
229
249
  # @param pricing_tier_id [String] The pricing_tier_id of the pricing tier to list features for.
230
- # @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)
231
- # @option filters [Integer] :limit A positive integer representing the max number of items to return in response. (optional)
250
+ # @param [Hash] filters Filters to apply to result set
251
+ # @param [Hash] options Options to apply on a per-request basis
252
+ # @option filters [String] :object_type Only return objects with an `objectType` matching this value
253
+ # @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)
254
+ # @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)
255
+ # @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)
256
+ # @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)
257
+ # @option filters [String] :sort_order The order in which to sort the result by. Valid values are +ASC+ and +DESC+. Defaults to +ASC+. (optional)
258
+ # @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)
232
259
  #
233
260
  # @return [Array<Feature>] assigned features for the pricing tier
234
261
  #
235
262
  # @raise [Warrant::InternalError]
236
263
  # @raise [Warrant::InvalidParameterError]
237
264
  # @raise [Warrant::UnauthorizedError]
238
- def self.list_for_pricing_tier(pricing_tier_id, filters = {})
239
- res = APIOperations.get(URI.parse("#{::Warrant.config.api_base}/v1/pricing-tiers/#{pricing_tier_id}/features"), Util.normalize_params(filters))
240
-
241
- case res
242
- when Net::HTTPSuccess
243
- features = JSON.parse(res.body)
244
- features.map{ |feature| Feature.new(feature['featureId']) }
245
- else
246
- APIOperations.raise_error(res)
247
- end
265
+ def self.list_for_pricing_tier(pricing_tier_id, filters = {}, options = {})
266
+ query_response = Warrant.query("select feature where pricing-tier:#{pricing_tier_id} is *", filters: filters, options: options)
267
+ features = query_response.results.map{ |result| Feature.new(result.object_id, result.meta) }
268
+ return ListResponse.new(features, query_response.prev_cursor, query_response.next_cursor)
248
269
  end
249
270
 
250
271
  # Assign a feature to a pricing tier
251
272
  #
252
273
  # @param pricing_tier_id [String] The pricing_tier_id of the pricing tier you want to assign a feature to.
253
274
  # @param feature_id [String] The feature_id of the feature you want to assign to a pricing tier.
275
+ # @param relation [String] The relation for this feature to pricing tier association. The relation must be valid as per the +feature+ object type definition.
254
276
  #
255
277
  # @return [Warrant] warrant assigning feature to pricing tier
256
278
  #
@@ -259,14 +281,15 @@ module Warrant
259
281
  # @raise [Warrant::InvalidParameterError]
260
282
  # @raise [Warrant::NotFoundError]
261
283
  # @raise [Warrant::UnauthorizedError]
262
- def self.assign_to_pricing_tier(pricing_tier_id, feature_id)
263
- Warrant.create({ object_type: Feature::OBJECT_TYPE, object_id: feature_id }, "member", { object_type: PricingTier::OBJECT_TYPE, object_id: pricing_tier_id })
284
+ def self.assign_to_pricing_tier(pricing_tier_id, feature_id, relation: "member", options: {})
285
+ Warrant.create({ object_type: Feature::OBJECT_TYPE, object_id: feature_id }, relation, { object_type: PricingTier::OBJECT_TYPE, object_id: pricing_tier_id }, nil, options)
264
286
  end
265
287
 
266
288
  # Remove a feature from a pricing tier
267
289
  #
268
290
  # @param pricing_tier_id [String] The pricing_tier_id of the pricing tier you want to remove a feature from.
269
291
  # @param feature_id [String] The feature_id of the feature you want to remove from a pricing tier.
292
+ # @param relation [String] The relation for this feature to pricing tier association. The relation must be valid as per the +feature+ object type definition.
270
293
  #
271
294
  # @return [nil] if remove was successful
272
295
  #
@@ -275,8 +298,8 @@ module Warrant
275
298
  # @raise [Warrant::NotFoundError]
276
299
  # @raise [Warrant::UnauthorizedError]
277
300
  # @raise [Warrant::WarrantError]
278
- def self.remove_from_pricing_tier(pricing_tier_id, feature_id)
279
- Warrant.delete({ object_type: Feature::OBJECT_TYPE, object_id: feature_id }, "member", { object_type: PricingTier::OBJECT_TYPE, object_id: pricing_tier_id })
301
+ def self.remove_from_pricing_tier(pricing_tier_id, feature_id, relation: "member", options: {})
302
+ Warrant.delete({ object_type: Feature::OBJECT_TYPE, object_id: feature_id }, relation, { object_type: PricingTier::OBJECT_TYPE, object_id: pricing_tier_id }, nil, options)
280
303
  end
281
304
 
282
305
  def warrant_object_type
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Warrant
4
+ class ListResponse
5
+ attr_reader :results, :prev_cursor, :next_cursor
6
+
7
+ # @!visibility private
8
+ def initialize(results, prev_cursor, next_cursor)
9
+ @results = results
10
+ @prev_cursor = prev_cursor
11
+ @next_cursor = next_cursor
12
+ end
13
+ end
14
+ end