Module: KindeSdk::Client::Entitlements
- Included in:
- KindeSdk::Client
- Defined in:
- lib/kinde_sdk/client/entitlements.rb
Instance Method Summary collapse
-
#get_entitlements(options = {}) ⇒ Array
Get all entitlements for the authenticated user Matches the JavaScript SDK API: getEntitlements(options?).
-
#has_billing_entitlements?(billing_entitlements, options = {}) ⇒ Boolean
(also: #hasBillingEntitlements)
Check if user has billing entitlements Matches the JavaScript SDK API: hasBillingEntitlements(params).
-
#has_entitlements?(entitlement_keys, options = {}) ⇒ Boolean
(also: #hasEntitlements)
Check if user has feature entitlements.
Instance Method Details
#get_entitlements(options = {}) ⇒ Array
Get all entitlements for the authenticated user Matches the JavaScript SDK API: getEntitlements(options?)
11 12 13 14 15 |
# File 'lib/kinde_sdk/client/entitlements.rb', line 11 def get_entitlements( = {}) # Entitlements are always fetched from API (they don't exist in tokens) # The options parameter is kept for consistency with other methods getAllEntitlements end |
#has_billing_entitlements?(billing_entitlements, options = {}) ⇒ Boolean Also known as: hasBillingEntitlements
Check if user has billing entitlements Matches the JavaScript SDK API: hasBillingEntitlements(params)
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/kinde_sdk/client/entitlements.rb', line 23 def has_billing_entitlements?(billing_entitlements, = {}) return true if billing_entitlements.nil? || billing_entitlements.empty? begin entitlements = get_entitlements() billing_entitlements_array = Array(billing_entitlements) # Extract price names from entitlements (billing entitlements use price_name) entitlement_price_names = entitlements.map do |ent| ent.respond_to?(:price_name) ? ent.price_name : ent['price_name'] end.compact billing_entitlements_array.all? { |price_name| entitlement_price_names.include?(price_name) } rescue StandardError => e log_error("Error checking billing entitlements: #{e.message}") false end end |
#has_entitlements?(entitlement_keys, options = {}) ⇒ Boolean Also known as: hasEntitlements
Check if user has feature entitlements
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/kinde_sdk/client/entitlements.rb', line 47 def has_entitlements?(entitlement_keys, = {}) return true if entitlement_keys.nil? || entitlement_keys.empty? begin entitlements = get_entitlements() entitlement_keys_array = Array(entitlement_keys) # Extract feature keys from entitlements entitlement_feature_keys = entitlements.map do |ent| ent.respond_to?(:feature_key) ? ent.feature_key : ent['feature_key'] end.compact entitlement_keys_array.all? { |key| entitlement_feature_keys.include?(key) } rescue StandardError => e log_error("Error checking entitlements: #{e.message}") false end end |