AppManager

Welcome to the new gem of Hulkapps.com ! An API wrapper of Hulkapps.com's AppManager portal.

Installation

  • Add following line to your application's Gemfile:
gem 'app_manager'
  • Execute following in terminal:
    bundle install
    rails g app_manager:install

this install command will mount routes in your rails route and will create a config file at config/initializers/app_manager.rb

    rails db:migrate

Configuration

  • Set Shopify API version to 2022-04 as app_manager is best compatible with this version.

  • Please map new fields (which added by app manager migration) in 'config.field_names' in below initializer file which is generated by install command. Please note: this is important step.

  • Please update blank fields in initializer file. Please copy 'uuid' from this file and paste in the following file and make sure that is unique per feature. After copying put your 'app name' next to 'uuid' column in this file.

AppManager.configure do |config|
  config.enable_caching = false  # Optional, True to enable app-manager api response caching, default is enabled from gem
  config.expires_in = 1.days  # Optional, Example: 30.seconds, 5.minutes or 2.days  Default caching is for 1.days from gem 
  config.app_url = '' # App URL like https://volumediscount.hulkapps.dev/ or #https://5044-2409-4052-209a-69da-9d7-925a-9418-a9c3.ngrok.io
  config.shopify_api_key = '' # Shopify api key of app
  config.shopify_api_version = ''  # Must be 2022-04 or latest
  config.shopify_table_name = 'shops'  #  Table name which is generated by shopify mostly it is 'shops'
  config.shopify_domain_field = 'shopify_domain' #shopify domain field
  config.plan_id_or_name_field = 'plan_id'
  config.field_names = {
        'name' => 'shopify_domain', # demo-rahul-tiwari.myshopify.com
        'shopify_email' => 'email', # [email protected]
        'shopify_token' => 'shopify_token',
        'shopify_plan' => 'shopify_plan', # partner_test
        'plan_id' => 'plan_id', # 1. t
        'created_at' => 'created_at', # 2022-04-15 10:43:05
        'trial_activated_at' => 'trial_activated_at', # field name that stores trial start/activated date
        'grandfathered' => 'grandfathered' 
    }
  config.plan_features =  [
    {
        "uuid" => "b48a3a6c-c1fb-11ec-9d64-0242ac120002",
        "name" => "Features 1",
        "slug" => "feature-1",
        "description" => "Feature Description",
        "value_type" => "integer",
        "format" => "count",
        "display_order" => 1,
        "hidden_feature" => false,
        "group_order" => "1",
        "group" => "Group Name",
    },
    {
        "uuid" => "9f18f95a-bfaf-11ec-9d64-0242ac120002",
        "name" => "Features 2",
        "slug" => "feature-2",
        "description" => "Feature Description",
        "value_type" => "boolean",
        "format" => "percentage",
        "display_order" => 2,
        "hidden_feature" => false,
        "group_order" => "1",
        "group" => "Group Name",
    },
    {
        "uuid" => "9f190a26-bfaf-11ec-9d64-0242ac120002",
        "name" => "Features 3",
        "slug" => "feature-3",
        "description" => "Feature Description",
        "value_type" => "string",
        "format" => "string",
        "display_order" => 3,
        "hidden_feature" => false,
        "group_order" => "1",
        "group" => "Group Name",
    },
    {
        "uuid" => "9f191340-bfaf-11ec-9d64-0242ac12000",
        "name" => "Features 4",
        "slug" => "feature-4",
        "description" => "Feature Description",
        "value_type" => "array",
        "values" => [
            "val 1",
            "val 2"
        ],
        "format" => "string",
        "display_order" => 4,
        "hidden_feature" => false,
        "group_order" => "1",
        "group" => "Group Name",
    }
]  
end
#Required, Values type : integer, boolean, string, array #
#Format: percentage, count, string
  • You must have to set ENV variable with key 'APP_MANAGER_ACCESS_TOKEN' in your application.yml or .env file like this:
    APP_MANAGER_ACCESS_TOKEN: 'XXXXXXXXXXXXXXXXXXX'
    APP_MANAGER_API_URL: 'https://XXXXXXXX.com'
  • App Manager provides a rake task that must needs to include in your existing app cron for every 10 minutes. Like if you are using whenever gem then you MUST need to include following rake take in your 'schedule.rb' (created by whenever gem)
every 10.minutes do
  rake 'sync:local_app_manager'
end

Usage

  • App Manager provides a helper module which needs to include in your 'shop' model something like below
class Shop < ActiveRecord::Base
  include AppManager::Model
end

and then you can use follwing methods with your shop objects.

@shop.has_plan # return true or false

@shop.plan_features # return array of plan features of your shop's plan 

@shop.has_feature('feature-1') # provide slug of feature which you set in your 'config.plan_features' in config/initializers/app_manager.rb
#return true/false

@shop.get_feature('feature-3') #  provide slug of feature and this returns value of feature which is set in portal. 

@shop.get_remaining_days # return integer based on trial activated date.

@shop.get_plan # return current plan hash

@shop.get_charge # return current charge hash

Extras

  • To view the app_manager ruby gem is working in your rails app you can use rails console and initialize app_manager instance like with App Manager Portal access:
ob = AppManager::Client.new(ENV['APP_MANAGER_ACCESS_TOKEN'])

To get banners use this command:

ob.get_banners
  • For Vue UI Library in Rails Project:

Please make sure you have following line in your route file otherwise add this manually.

mount AppManager::Engine, at: "/"

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake test to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and the created tag, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/app_manager. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.

Code of Conduct

Everyone interacting in the AppManager project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.