Class: Warrant::PricingTier

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

Constant Summary collapse

OBJECT_TYPE =
"pricing-tier"

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_tenant(tenant_id, pricing_tier_id, relation: "member", options: {}) ⇒ Warrant

Assign a pricing tier to a tenant

Parameters:

  • tenant_id (String)

    The tenant_id of the tenant you want to assign a pricing tier to.

  • pricing_tier_id (String)

    The pricing_tier_id of the pricing tier you want to assign to a tenant.

  • relation (String) (defaults to: "member")

    The relation for this pricing tier to tenant association. The relation must be valid as per the pricing tier object type definition.

Returns:

  • (Warrant)

    warrant assigning pricing tier to tenant

Raises:



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

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

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

Assign a pricing tier to a user

Parameters:

  • user_id (String)

    The user_id of the user you want to assign a pricing tier to.

  • pricing_tier_id (String)

    The pricing_tier_id of the pricing tier you want to assign to a user.

  • relation (String) (defaults to: "member")

    The relation for this pricing tier to user association. The relation must be valid as per the pricing tier object type definition.

Returns:

  • (Warrant)

    warrant assigning pricing tier to user

Raises:



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

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

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

Creates a pricing tier with the given parameters

Examples:

Create a new PricingTier with the pricing tier id “test-pricing-tier”

Warrant::PricingTier.create(pricing_tier_id: "test-pricing-tier")

Parameters:

  • params (Hash) (defaults to: {})

    a customizable set of options

Options Hash (params):

  • :pricing (String)

    tier_id User defined string identifier for this pricing tier. If not provided, Warrant will create an id for the pricing tier 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 pricing tier. Note that pricingTierIds in Warrant must be composed of alphanumeric chars, ‘-’, and/or ‘_’. (optional)

  • :meta (Hash)

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

Returns:

Raises:



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

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

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

Deletes a pricing tier with given pricing tier id

Examples:

Delete a PricingTier with the pricing tier id “test-pricing-tier”

Warrant::PricingTier.delete("test-pricing-tier")

Parameters:

  • pricing_tier_id (String)

    The pricing_tier_id of the pricing tier to delete.

Returns:

  • (nil)

    if delete was successful

Raises:



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

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

.get(pricing_tier_id, options = {}) ⇒ PricingTier

Get a pricing_tier with the given pricing_tier_id

Parameters:

  • pricing_tier_id (String)

    The pricing_tier_id of the pricing tier to retrieve.

Returns:

Raises:



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

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

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

Lists all pricing tiers for your organization

Examples:

List all pricing tiers

Warrant::PricingTier.list()

Parameters:

  • filters (Hash) (defaults to: {})

    Filters to apply to result set

  • options (Hash) (defaults to: {})

    Options to apply on a per-request basis

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)

Returns:

  • (Array<PricingTier>)

    all pricing tiers for your organization

Raises:



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

def self.list(filters = {}, options = {})
    filters.merge({ object_type: "pricing-tier" })
    list_response = Object.list(filters, options)
    pricing_tiers = list_response.results.map{ |object| PricingTier.new(object.object_id, object.meta, object.created_at)}
    return ListResponse.new(pricing_tiers, list_response.prev_cursor, list_response.next_cursor)
end

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

List pricing tiers for tenant

Parameters:

  • tenant_id (String)

    The tenant_id of the tenant to list pricing tiers for.

  • filters (Hash) (defaults to: {})

    Filters to apply to result set

  • options (Hash) (defaults to: {})

    Options to apply on a per-request basis

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)

Returns:

  • (Array<PricingTier>)

    assigned pricing tiers for the tenant

Raises:



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

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

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

List pricing tiers for user

Parameters:

  • user_id (String)

    The user_id of the user to list pricing tiers for.

  • filters (Hash) (defaults to: {})

    Filters to apply to result set

  • options (Hash) (defaults to: {})

    Options to apply on a per-request basis

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)

Returns:

  • (Array<PricingTier>)

    assigned pricing tiers for the user

Raises:



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

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

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

Remove a pricing tier from a tenant

Parameters:

  • tenant_id (String)

    The tenant_id of the tenant you want to remove a pricing tier from.

  • pricing_tier_id (String)

    The pricing_tier_id of the pricing tier you want to remove from a tenant.

  • relation (String) (defaults to: "member")

    The relation for this pricing tier to tenant association. The relation must be valid as per the pricing tier object type definition.

Returns:

  • (nil)

    if remove was successful

Raises:



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

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

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

Remove a pricing tier from a user

Parameters:

  • user_id (String)

    The user_id of the user you want to remove a pricing tier from.

  • pricing_tier_id (String)

    The pricing_tier_id of the pricing tier you want to remove from a user.

  • relation (String) (defaults to: "member")

    The relation for this pricing tier to user association. The relation must be valid as per the pricing tier object type definition.

Returns:

  • (nil)

    if remove was successful

Raises:



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

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

.update(pricing_tier_id, meta, options = {}) ⇒ PricingTier

Updates a pricing tier with the given pricing_tier_id and params

Examples:

Update pricing tier “test-pricing-tier”‘s name

Warrant::PricingTier.update("test-pricing-tier", { name: "Test Tier" })

Parameters:

  • pricing_tier_id (String)

    The pricing_tier_id of the pricing tier to be updated.

  • meta (Hash)

    A JSON object containing additional information about this pricing tier (e.g. name/description, etc.) to be persisted to Warrant.

Returns:

Raises:



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

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

Instance Method Details

#assign_feature(feature_id, relation: "member", options: {}) ⇒ Feature

Assign a feature to a pricing tier

Parameters:

  • feature_id (String)

    The feature_id of the feature you want to assign to the pricing tier.

  • relation (String) (defaults to: "member")

    The relation for this feature to pricing tier association. The relation must be valid as per the feature object type definition.

Returns:

Raises:



280
281
282
# File 'lib/warrant/models/pricing_tier.rb', line 280

def assign_feature(feature_id, relation: "member", options: {})
    return Feature.assign_to_pricing_tier(pricing_tier_id, feature_id, relation: relation, options: options)
end

#has_feature?(feature_id, relation: "member", options: {}) ⇒ Boolean

Check whether a pricing tier has a given feature

Parameters:

  • feature_id (String)

    The feature_id of the feature to check whether the pricing tier has access to.

  • relation (String) (defaults to: "member")

    The relation for this feature to pricing tier association. The relation must be valid as per the feature object type definition.

  • options (Hash) (defaults to: {})

    Options to apply on a per-request basis

Options Hash (options:):

  • :context (Hash)

    Object containing key-value pairs that specifies the context the warrant should be checked in. (optional)

  • :debug (Boolean)

    Boolean flag indicating whether or not to return debug information for this access check. Defaults to false. (optional)

Returns:

  • (Boolean)

    whether or not the pricing tier has the given feature

Raises:



314
315
316
317
318
319
320
321
322
323
324
325
# File 'lib/warrant/models/pricing_tier.rb', line 314

def has_feature?(feature_id, relation: "member", options: {})
    return Warrant.has_feature?({
        feature_id: feature_id,
        relation: relation,
        subject: {
            object_type: "pricing-tier",
            object_id: pricing_tier_id
        },
        context: options[:context],
        debug: options[:debug]
    }, options)
end

#list_features(filters = {}, options = {}) ⇒ Array<Feature>

List features for a pricing tier

Parameters:

  • filters (Hash) (defaults to: {})

    Filters to apply to result set

  • options (Hash) (defaults to: {})

    Options to apply on a per-request basis

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)

Returns:

  • (Array<Feature>)

    assigned features for the pricing tier

Raises:



264
265
266
# File 'lib/warrant/models/pricing_tier.rb', line 264

def list_features(filters = {}, options = {})
    return Feature.list_for_pricing_tier(pricing_tier_id, filters, options)
end

#remove_feature(feature_id, relation: "member", options: {}) ⇒ nil

Remove a feature from a pricing tier

Parameters:

  • feature_id (String)

    The feature_id of the feature you want to assign from the pricing tier.

  • relation (String) (defaults to: "member")

    The relation for this feature to pricing tier association. The relation must be valid as per the feature object type definition.

Returns:

  • (nil)

    if remove was successful

Raises:



296
297
298
# File 'lib/warrant/models/pricing_tier.rb', line 296

def remove_feature(feature_id, relation: "member", options: {})
    return Feature.remove_from_pricing_tier(pricing_tier_id, feature_id, relation: relation, options: options)
end

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

Updates a pricing tier with the given params

Examples:

Update pricing tier “test-pricing-tier”‘s name

pricing_tier = Warrant::PricingTier.get("test-pricing-tier")
pricing_tier.update({ name: "Test Tier" })

Parameters:

  • meta (Hash)

    A JSON object containing additional information about this pricing tier (e.g. name/description, etc.) to be persisted to Warrant.

Returns:

Raises:



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

def update(meta, options = {})
    return PricingTier.update(pricing_tier_id, meta)
end

#warrant_object_idObject



331
332
333
# File 'lib/warrant/models/pricing_tier.rb', line 331

def warrant_object_id
    pricing_tier_id
end

#warrant_object_typeObject



327
328
329
# File 'lib/warrant/models/pricing_tier.rb', line 327

def warrant_object_type
    "pricing-tier"
end