Module: AppManager::Model
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/app_manager/model.rb
Instance Method Summary collapse
- #get_feature(slug) ⇒ Object
- #get_remaining_days ⇒ Object
- #has_feature(slug) ⇒ Object
- #has_plan ⇒ Object
- #plan_features ⇒ Object
Instance Method Details
#get_feature(slug) ⇒ Object
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/app_manager/model.rb', line 52 def get_feature(slug) plan_features = self.plan_features features = plan_features.select{|x| x['slug'].to_s == slug } if features.any? feature = features.first return casted_value(feature['value'],feature['value_type']) else nil end end |
#get_remaining_days ⇒ Object
63 64 65 66 67 68 69 70 71 |
# File 'lib/app_manager/model.rb', line 63 def get_remaining_days shop_domain = self[AppManager.configuration.shopify_domain_field] trial_activated_at_field = AppManager.configuration.field_names['trial_activated_at'] trial_activated_at_val = self[trial_activated_at_field] plan_field = AppManager.configuration.field_names['plan_id'] plan_id = self[plan_field] plan_obj = AppManager::Client.new shop_domain ? plan_obj.get_remaining_days(shop_domain,trial_activated_at_val,plan_id) : 0 end |
#has_feature(slug) ⇒ Object
47 48 49 |
# File 'lib/app_manager/model.rb', line 47 def has_feature(slug) self.plan_features.select{|x| x['slug'].to_s == slug }.size > 0 end |
#has_plan ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/app_manager/model.rb', line 7 def has_plan if !self[AppManager.configuration.plan_id_or_name_field] return false; end plan_id = self.plan_id if !plan_id Rails.logger.info "Plan id found nil or not set" return false; end remaining_days = self.get_remaining_days if remaining_days > 0 return true end shopify_fields = @field_names = AppManager.configuration.field_names plan_obj = AppManager::Client.new active_charge = plan_obj.get_charge(shopify_fields['name']) rescue nil return active_charge ? true : false end |
#plan_features ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/app_manager/model.rb', line 28 def plan_features plan_id = self.plan_id if !plan_id raise "Plan id not found" end plan_obj = AppManager::Client.new plans = plan_obj.get_plan(plan_id) if plans && plans['features'].blank? return [] end features_by_plan = plans['features'].map { |h| h.slice('value', 'feature_id') } all_features = AppManager.configuration.plan_features feature_plan_ids = features_by_plan.map{|c| c['feature_id']} pf = all_features.select{|x| feature_plan_ids.include?(x['uuid'])}.each{|g| g["value"] = features_by_plan.find{|e| e['feature_id'] == g['uuid']}['value'] } return pf end |