Class: Warrant::Feature

Inherits:
Object
  • Object
show all
Includes:
WarrantObject
Defined in:
lib/warrant/models/feature.rb

Constant Summary collapse

OBJECT_TYPE =
"feature"

Instance Attribute Summary

Attributes inherited from Object

#created_at, #meta, #object_id, #object_type

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Object

batch_create, batch_delete

Class Method Details

.assign_to_pricing_tier(pricing_tier_id, feature_id, relation: "member", options: {}) ⇒ Warrant

Assign a feature to a pricing tier



284
285
286
# File 'lib/warrant/models/feature.rb', line 284

def self.assign_to_pricing_tier(pricing_tier_id, feature_id, relation: "member", options: {})
    Warrant.create({ object_type: Feature::OBJECT_TYPE, object_id: feature_id }, relation, { object_type: PricingTier::OBJECT_TYPE, object_id: pricing_tier_id }, nil, options)
end

.assign_to_tenant(tenant_id, feature_id, relation: "member", options: {}) ⇒ Warrant

Assign a feature to a tenant



168
169
170
# File 'lib/warrant/models/feature.rb', line 168

def self.assign_to_tenant(tenant_id, feature_id, relation: "member", options: {})
    Warrant.create({ object_type: Feature::OBJECT_TYPE, object_id: feature_id }, relation, { object_type: Tenant::OBJECT_TYPE, object_id: tenant_id }, nil, options)
end

.assign_to_user(user_id, feature_id, relation: "member", options: {}) ⇒ Warrant

Assign a feature to a user



226
227
228
# File 'lib/warrant/models/feature.rb', line 226

def self.assign_to_user(user_id, feature_id, relation: "member", options: {})
    Warrant.create({ object_type: Feature::OBJECT_TYPE, object_id: feature_id }, relation, { object_type: User::OBJECT_TYPE, object_id: user_id }, nil, options)
end

.create(params = {}, options = {}) ⇒ Feature

Creates a feature with the given parameters

Examples:

Create a new Feature with the feature id "test-feature"

Warrant::Feature.create(feature_id: "test-feature")

Options Hash (params):

  • :feature_id (String) —

    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)

  • :meta (Hash) —

    A JSON object containing additional information about this feature (e.g. name/description) to be persisted to Warrant. (optional)

Raises:



30
31
32
33
# File 'lib/warrant/models/feature.rb', line 30

def self.create(params = {}, options = {})
    object = Object.create({ object_type: OBJECT_TYPE, object_id: params[:feature_id], meta: params[:meta] }, options)
    return Feature.new(object.object_id, object.meta, object.created_at)
end

.delete(feature_id, options = {}) ⇒ nil

Deletes a feature with given feature id

Examples:

Delete a Feature with the feature id "test-feature"

Warrant::Feature.delete("test-feature")

Raises:



48
49
50
# File 'lib/warrant/models/feature.rb', line 48

def self.delete(feature_id, options = {})
    return Object.delete(OBJECT_TYPE, feature_id, options)
end

.get(feature_id, options = {}) ⇒ Feature

Get a feature with the given feature_id



87
88
89
90
# File 'lib/warrant/models/feature.rb', line 87

def self.get(feature_id, options = {})
    object = Object.get(OBJECT_TYPE, feature_id, options)
    return Feature.new(object.object_id, object.meta, object.created_at)
end

.list(filters = {}, options = {}) ⇒ Array<Feature>

Lists all features for your organization

Examples:

List all features

Warrant::Feature.list()

Options Hash (filters):

  • :limit (Integer) —

    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)

  • :prev_cursor (String) —

    A cursor representing your place in a list of results. Requests containing prev_cursor will return the results immediately preceding the cursor. (optional)

  • :next_cursor (String) —

    A cursor representing your place in a list of results. Requests containing next_cursor will return the results immediately following the cursor. (optional)

  • :sort_by (String) —

    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)

  • :sort_order (String) —

    The order in which to sort the result by. Valid values are ASC and DESC. Defaults to ASC. (optional)

Options Hash (options):

  • :warrant_token (String) —

    A valid warrant token from a previous write operation or latest. Used to specify desired consistency for this read operation. (optional)

Raises:



70
71
72
73
74
75
# File 'lib/warrant/models/feature.rb', line 70

def self.list(filters = {}, options = {})
    filters.merge({ object_type: OBJECT_TYPE })
    list_response = Object.list(filters, options)
    features = list_response.results.map{ |object| Feature.new(object.object_id, object.meta, object.created_at)}
    return ListResponse.new(features, list_response.prev_cursor, list_response.next_cursor)
end

.list_for_pricing_tier(pricing_tier_id, filters = {}, options = {}) ⇒ Array<Feature>

List features for pricing tier

Options Hash (filters):

  • :object_type (String) —

    Only return objects with an objectType matching this value

  • :limit (Integer) —

    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)

  • :prev_cursor (String) —

    A cursor representing your place in a list of results. Requests containing prev_cursor will return the results immediately preceding the cursor. (optional)

  • :next_cursor (String) —

    A cursor representing your place in a list of results. Requests containing next_cursor will return the results immediately following the cursor. (optional)

  • :sort_by (String) —

    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)

  • :sort_order (String) —

    The order in which to sort the result by. Valid values are ASC and DESC. Defaults to ASC. (optional)

Options Hash (options):

  • :warrant_token (String) —

    A valid warrant token from a previous write operation or latest. Used to specify desired consistency for this read operation. (optional)

Raises:



265
266
267
268
269
# File 'lib/warrant/models/feature.rb', line 265

def self.list_for_pricing_tier(pricing_tier_id, filters = {}, options = {})
    query_response = Warrant.query("select feature where pricing-tier:#{pricing_tier_id} is *", filters: filters, options: options)
    features = query_response.results.map{ |result| Feature.new(result.object_id, result.meta) }
    return ListResponse.new(features, query_response.prev_cursor, query_response.next_cursor)
end

.list_for_tenant(tenant_id, filters = {}, options = {}) ⇒ Array<Feature>

List features for tenant

Options Hash (filters):

  • :object_type (String) —

    Only return objects with an objectType matching this value

  • :limit (Integer) —

    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)

  • :prev_cursor (String) —

    A cursor representing your place in a list of results. Requests containing prev_cursor will return the results immediately preceding the cursor. (optional)

  • :next_cursor (String) —

    A cursor representing your place in a list of results. Requests containing next_cursor will return the results immediately following the cursor. (optional)

  • :sort_by (String) —

    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)

  • :sort_order (String) —

    The order in which to sort the result by. Valid values are ASC and DESC. Defaults to ASC. (optional)

Options Hash (options):

  • :warrant_token (String) —

    A valid warrant token from a previous write operation or latest. Used to specify desired consistency for this read operation. (optional)

Raises:



149
150
151
152
153
# File 'lib/warrant/models/feature.rb', line 149

def self.list_for_tenant(tenant_id, filters = {}, options = {})
    query_response = Warrant.query("select feature where tenant:#{tenant_id} is *", filters: filters, options: options)
    features = query_response.results.map{ |result| Feature.new(result.object_id, result.meta) }
    return ListResponse.new(features, query_response.prev_cursor, query_response.next_cursor)
end

.list_for_user(user_id, filters = {}, options = {}) ⇒ Array<Feature>

List features for user

Options Hash (filters):

  • :object_type (String) —

    Only return objects with an objectType matching this value

  • :limit (Integer) —

    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)

  • :prev_cursor (String) —

    A cursor representing your place in a list of results. Requests containing prev_cursor will return the results immediately preceding the cursor. (optional)

  • :next_cursor (String) —

    A cursor representing your place in a list of results. Requests containing next_cursor will return the results immediately following the cursor. (optional)

  • :sort_by (String) —

    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)

  • :sort_order (String) —

    The order in which to sort the result by. Valid values are ASC and DESC. Defaults to ASC. (optional)

Options Hash (options):

  • :warrant_token (String) —

    A valid warrant token from a previous write operation or latest. Used to specify desired consistency for this read operation. (optional)

Raises:



207
208
209
210
211
# File 'lib/warrant/models/feature.rb', line 207

def self.list_for_user(user_id, filters = {}, options = {})
    query_response = Warrant.query("select feature where user:#{user_id} is *", filters: filters, options: options)
    features = query_response.results.map{ |result| Feature.new(result.object_id, result.meta) }
    return ListResponse.new(features, query_response.prev_cursor, query_response.next_cursor)
end

.remove_from_pricing_tier(pricing_tier_id, feature_id, relation: "member", options: {}) ⇒ nil

Remove a feature from a pricing tier



301
302
303
# File 'lib/warrant/models/feature.rb', line 301

def self.remove_from_pricing_tier(pricing_tier_id, feature_id, relation: "member", options: {})
    Warrant.delete({ object_type: Feature::OBJECT_TYPE, object_id: feature_id }, relation, { object_type: PricingTier::OBJECT_TYPE, object_id: pricing_tier_id }, nil, options)
end

.remove_from_tenant(tenant_id, feature_id, relation: "member", options: {}) ⇒ nil

Remove a feature from a tenant



185
186
187
# File 'lib/warrant/models/feature.rb', line 185

def self.remove_from_tenant(tenant_id, feature_id, relation: "member", options: {})
    Warrant.delete({ object_type: Feature::OBJECT_TYPE, object_id: feature_id }, relation, { object_type: Tenant::OBJECT_TYPE, object_id: tenant_id }, nil, options)
end

.remove_from_user(user_id, feature_id, relation: "member", options: {}) ⇒ nil

Remove a feature from a user



243
244
245
# File 'lib/warrant/models/feature.rb', line 243

def self.remove_from_user(user_id, feature_id, relation: "member", options: {})
    Warrant.delete({ object_type: Feature::OBJECT_TYPE, object_id: feature_id }, relation, { object_type: User::OBJECT_TYPE, object_id: user_id }, nil, options)
end

.update(feature_id, meta, options = {}) ⇒ Feature

Updates a feature with the given feature_id and params

Examples:

Update feature "test-feature"'s name

Warrant::Feature.update("test-feature", { name: "Test Feature" })

Raises:



107
108
109
110
# File 'lib/warrant/models/feature.rb', line 107

def self.update(feature_id, meta, options = {})
    object = Object.update(OBJECT_TYPE, feature_id, meta, options)
    return Feature.new(object.object_id, object.meta, object.created_at)
end

Instance Method Details

#update(meta, options = {}) ⇒ Feature

Updates a feature with the given params

Examples:

Update feature "test-feature"'s name

feature = Warrant::Feature.get("test-feature")
feature.update({ name: "Test Feature" })

Raises:



127
128
129
# File 'lib/warrant/models/feature.rb', line 127

def update(meta, options = {})
    return Feature.update(feature_id, meta)
end

#warrant_object_id ⇒ Object



309
310
311
# File 'lib/warrant/models/feature.rb', line 309

def warrant_object_id
    feature_id
end

#warrant_object_type ⇒ Object



305
306
307
# File 'lib/warrant/models/feature.rb', line 305

def warrant_object_type
    "feature"
end