AppManager
Welcome to the new gem of Hulkapps.com ! An API wrapper of Hulkapps.com's AppManager portal.
Installation
Step 1) Add following line to your application's Gemfile:
gem 'app_manager'
Step 2) 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
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' => 'plan_name', # 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
}
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
},
{
"uuid" => "9f18f95a-bfaf-11ec-9d64-0242ac120002",
"name" => "Features 2",
"slug" => "feature-2",
"description" => "Feature Description",
"value_type" => "boolean",
"format" => "percentage",
"display_order" => 2
},
{
"uuid" => "9f190a26-bfaf-11ec-9d64-0242ac120002",
"name" => "Features 3",
"slug" => "feature-3",
"description" => "Feature Description",
"value_type" => "string",
"format" => "string",
"display_order" => 3
},
{
"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
}
] #Required, Values type : integer, boolean, string, array
end
Please note: Your shops table must have 'plan_id' as int/bigint and 'trial_activated_at' as datetime otherwise add its migration. Sample example:
class AddPlanIdToShops < ActiveRecord::Migration[5.2]
def change
add_column :shops, :plan_id, :bigint
add_column :shops, :trial_activated_at, :datetime
end
end
and map these new fields in 'config.field_names' in above initializer file.
Step 3) 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'
Steps 4) 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
Steps 5) 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
Usage
Using above 5th step you can access following methods from your shop object.
@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.
As a helper:
Then, 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.
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.