client
variable.id
for the following Objects:
You will also need to specify that the Kana Client (as setup in Setup) should be passed in so that a call can be successfully made.
The following KanaFeatureEntitlement
class specifies these as instance variables that are set upon initialization of the object:
user_id
should map to userId
and the feature_id
should map toid
.
You can add the following in the same initialize
method:
KanaFeatureEntitlement
class is now setup to be successfully instantiated and initialized - however, we still need to specify methods which will help you understand your users feature allowance.
These methods will use the data we have pulled from Kana, now set in the associated instance variables.
Method Name | Type | Description |
---|---|---|
can_use_feature? | Boolean | Returns if the user should be able to use the feature. Considers both access to the feature through plan subscription, plus the remaining amount of the feature that a user can use if the feature is consumable. Takes an integer argument of amount which specifies how much of the feature the user is trying to use. Defaults to 1 if none is provided. |
amount_remaining | Integer | Returns how much of the feature that the user has remaining before it’s been used. |
binary? | Boolean | Returns if the feature is binary or not. |
consumable? | Boolean | Returns if the feature is consumable or not. |
has_access? | Boolean | Returns if the user has access to the feature or not through their subscription. Does not consider the amounts used or remaining. |
budget | Integer | Returns how much of the feature a |
used | Integer | Returns how much of the feature has already been used. |
KanaFeatureEntitlement
object which we setup earlier. You’ll need to provide the arguments we defined previously for the initialize
method:
client
: The client needed to make the API Call that you would have initialized previously (more in Setup).
feature_id
: The id of the feature. You can grab this from Kana, or note it somewhere from when the feature was created in Kana.
user_id
: The id of the user. This can be taken from the pulled user.
user_entitlement
.
user_entitlement
to fetch the information we need.
FeatureEntitlementError
if user_entitlement.can_use_feature?
returns false
.
can_use_feature?
method. This represents the amount of the feature which is to be used. If the feature has a type of BINARY
, it’s not utilised. However, if it’s CONSUMABLE
, then we will check this amount against the amount which the user has remaining of this feature on their plan. More on this method was shown earlier in Add methods to query feature usage and allowance.