Class: Warrant::PricingTier
- 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
-
.assign_to_tenant(tenant_id, pricing_tier_id, relation: "member", options: {}) ⇒ Warrant
Assign a pricing tier to a tenant.
-
.assign_to_user(user_id, pricing_tier_id, relation: "member", options: {}) ⇒ Warrant
Assign a pricing tier to a user.
-
.create(params = {}, options = {}) ⇒ PricingTier
Creates a pricing tier with the given parameters.
-
.delete(pricing_tier_id, options = {}) ⇒ nil
Deletes a pricing tier with given pricing tier id.
-
.get(pricing_tier_id, options = {}) ⇒ PricingTier
Get a pricing_tier with the given pricing_tier_id.
-
.list(filters = {}, options = {}) ⇒ Array<PricingTier>
Lists all pricing tiers for your organization.
-
.list_for_tenant(tenant_id, filters = {}, options = {}) ⇒ Array<PricingTier>
List pricing tiers for tenant.
-
.list_for_user(user_id, filters = {}, options = {}) ⇒ Array<PricingTier>
List pricing tiers for user.
-
.remove_from_tenant(tenant_id, pricing_tier_id, relation: "member", options: {}) ⇒ nil
Remove a pricing tier from a tenant.
-
.remove_from_user(user_id, pricing_tier_id, relation: "member", options: {}) ⇒ nil
Remove a pricing tier from a user.
-
.update(pricing_tier_id, meta, options = {}) ⇒ PricingTier
Updates a pricing tier with the given pricing_tier_id and params.
Instance Method Summary collapse
-
#assign_feature(feature_id, relation: "member", options: {}) ⇒ Feature
Assign a feature to a pricing tier.
-
#has_feature?(feature_id, relation: "member", options: {}) ⇒ Boolean
Check whether a pricing tier has a given feature.
-
#list_features(filters = {}, options = {}) ⇒ Array<Feature>
List features for a pricing tier.
-
#remove_feature(feature_id, relation: "member", options: {}) ⇒ nil
Remove a feature from a pricing tier.
-
#update(meta, options = {}) ⇒ PricingTier
Updates a pricing tier with the given params.
- #warrant_object_id ⇒ Object
- #warrant_object_type ⇒ Object
Methods inherited from Object
Class Method Details
.assign_to_tenant(tenant_id, pricing_tier_id, relation: "member", options: {}) ⇒ Warrant
Assign a pricing tier to a tenant
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, ) end |
.assign_to_user(user_id, pricing_tier_id, relation: "member", options: {}) ⇒ Warrant
Assign a pricing tier to a user
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, ) end |
.create(params = {}, options = {}) ⇒ PricingTier
Creates a pricing tier with the given parameters
30 31 32 33 |
# File 'lib/warrant/models/pricing_tier.rb', line 30 def self.create(params = {}, = {}) object = Object.create({ object_type: OBJECT_TYPE, object_id: params[:pricing_tier_id], meta: params[:meta] }, ) return PricingTier.new(object.object_id, object., object.created_at) end |
.delete(pricing_tier_id, options = {}) ⇒ nil
Deletes a pricing tier with given pricing tier id
48 49 50 |
# File 'lib/warrant/models/pricing_tier.rb', line 48 def self.delete(pricing_tier_id, = {}) return Object.delete(OBJECT_TYPE, pricing_tier_id, ) end |
.get(pricing_tier_id, options = {}) ⇒ PricingTier
Get a pricing_tier with the given pricing_tier_id
87 88 89 90 |
# File 'lib/warrant/models/pricing_tier.rb', line 87 def self.get(pricing_tier_id, = {}) object = Object.get(OBJECT_TYPE, pricing_tier_id, ) return PricingTier.new(object.object_id, object., object.created_at) end |
.list(filters = {}, options = {}) ⇒ Array<PricingTier>
Lists all pricing tiers for your organization
70 71 72 73 74 75 |
# File 'lib/warrant/models/pricing_tier.rb', line 70 def self.list(filters = {}, = {}) filters.merge({ object_type: "pricing-tier" }) list_response = Object.list(filters, ) pricing_tiers = list_response.results.map{ |object| PricingTier.new(object.object_id, object., 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
149 150 151 152 153 |
# File 'lib/warrant/models/pricing_tier.rb', line 149 def self.list_for_tenant(tenant_id, filters = {}, = {}) query_response = Warrant.query("select pricing-tier where tenant:#{tenant_id} is *", filters: filters, options: ) pricing_tiers = query_response.results.map{ |result| PricingTier.new(result.object_id, result.) } 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
207 208 209 210 211 |
# File 'lib/warrant/models/pricing_tier.rb', line 207 def self.list_for_user(user_id, filters = {}, = {}) query_response = Warrant.query("select pricing-tier where user:#{user_id} is *", filters: filters, options: ) pricing_tiers = query_response.results.map{ |result| PricingTier.new(result.object_id, result.) } 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
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, ) end |
.remove_from_user(user_id, pricing_tier_id, relation: "member", options: {}) ⇒ nil
Remove a pricing tier from a user
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, ) end |
.update(pricing_tier_id, meta, options = {}) ⇒ PricingTier
Updates a pricing tier with the given pricing_tier_id and params
107 108 109 110 |
# File 'lib/warrant/models/pricing_tier.rb', line 107 def self.update(pricing_tier_id, , = {}) object = Object.update(OBJECT_TYPE, pricing_tier_id, , ) return PricingTier.new(object.object_id, object., object.created_at) end |
Instance Method Details
#assign_feature(feature_id, relation: "member", options: {}) ⇒ Feature
Assign a feature to a pricing tier
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: ) end |
#has_feature?(feature_id, relation: "member", options: {}) ⇒ Boolean
Check whether a pricing tier has a given feature
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: [:context], debug: [:debug] }, ) end |
#list_features(filters = {}, options = {}) ⇒ Array<Feature>
List features for a pricing tier
264 265 266 |
# File 'lib/warrant/models/pricing_tier.rb', line 264 def list_features(filters = {}, = {}) return Feature.list_for_pricing_tier(pricing_tier_id, filters, ) end |
#remove_feature(feature_id, relation: "member", options: {}) ⇒ nil
Remove a feature from a pricing tier
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: ) end |
#update(meta, options = {}) ⇒ PricingTier
Updates a pricing tier with the given params
127 128 129 |
# File 'lib/warrant/models/pricing_tier.rb', line 127 def update(, = {}) return PricingTier.update(pricing_tier_id, ) end |
#warrant_object_id ⇒ Object
331 332 333 |
# File 'lib/warrant/models/pricing_tier.rb', line 331 def warrant_object_id pricing_tier_id end |
#warrant_object_type ⇒ Object
327 328 329 |
# File 'lib/warrant/models/pricing_tier.rb', line 327 def warrant_object_type "pricing-tier" end |