app_manager 0.1.2 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +16 -1
- data/README.md +110 -1
- data/app/controllers/app_manager/application_controller.rb +7 -0
- data/app/controllers/app_manager/banners_controller.rb +7 -2
- data/app/controllers/app_manager/charges_controller.rb +122 -0
- data/app/controllers/app_manager/plans_controller.rb +157 -0
- data/app/controllers/concerns/app_manager/authenticate.rb +10 -0
- data/app_manager.gemspec +2 -2
- data/config/routes.rb +14 -1
- data/lib/app_manager/actions.rb +10 -0
- data/lib/app_manager/api_cache_handler.rb +67 -0
- data/lib/app_manager/client/banners.rb +1 -1
- data/lib/app_manager/client/connection.rb +37 -3
- data/lib/app_manager/client/plans.rb +40 -0
- data/lib/app_manager/client.rb +9 -3
- data/lib/app_manager/config.rb +82 -0
- data/lib/app_manager/fail_safe.rb +324 -0
- data/lib/app_manager/graphql_helper.rb +125 -0
- data/lib/app_manager/model.rb +98 -0
- data/lib/app_manager/protection.rb +21 -0
- data/lib/app_manager/railtie.rb +10 -0
- data/lib/app_manager/response_cache.rb +40 -0
- data/lib/app_manager/tasks/sync/local_app_manager.rake +12 -0
- data/lib/app_manager/version.rb +1 -1
- data/lib/app_manager.rb +22 -2
- data/lib/generators/app_manager/install/install_generator.rb +8 -0
- data/lib/generators/app_manager/install/templates/app_manager.rb.tt +61 -0
- metadata +45 -2
@@ -0,0 +1,98 @@
|
|
1
|
+
module AppManager
|
2
|
+
module Model
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
def has_plan
|
8
|
+
if !self[AppManager.configuration.plan_id_or_name_field]
|
9
|
+
return false;
|
10
|
+
end
|
11
|
+
plan_id = self.plan_id
|
12
|
+
if !plan_id
|
13
|
+
Rails.logger.info "Plan id found nil or not set"
|
14
|
+
return false;
|
15
|
+
end
|
16
|
+
remaining_days = self.get_remaining_days
|
17
|
+
if remaining_days > 0
|
18
|
+
return true
|
19
|
+
end
|
20
|
+
shopify_fields = @field_names = AppManager.configuration.field_names
|
21
|
+
plan_obj = AppManager::Client.new
|
22
|
+
active_charge = plan_obj.get_charge(shopify_fields['name']) rescue nil
|
23
|
+
return active_charge ? true : false
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
|
28
|
+
def plan_features
|
29
|
+
plan_id = self.plan_id
|
30
|
+
if !plan_id
|
31
|
+
raise "Plan id not found"
|
32
|
+
end
|
33
|
+
plan_obj = AppManager::Client.new
|
34
|
+
plans = plan_obj.get_plan(plan_id)
|
35
|
+
if plans && plans['features'].blank?
|
36
|
+
return []
|
37
|
+
end
|
38
|
+
features_by_plan = plans['features'].map { |h| h.slice('value', 'feature_id') }
|
39
|
+
all_features = AppManager.configuration.plan_features
|
40
|
+
feature_plan_ids = features_by_plan.map{|c| c['feature_id']}
|
41
|
+
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'] }
|
42
|
+
return pf
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
def has_feature(slug)
|
48
|
+
self.plan_features.select{|x| x['slug'].to_s == slug }.size > 0
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
def get_feature(slug)
|
53
|
+
plan_features = self.plan_features
|
54
|
+
features = plan_features.select{|x| x['slug'].to_s == slug }
|
55
|
+
if features.any?
|
56
|
+
feature = features.first
|
57
|
+
return casted_value(feature['value'],feature['value_type'])
|
58
|
+
else
|
59
|
+
nil
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def get_remaining_days
|
64
|
+
shop_domain = self[AppManager.configuration.shopify_domain_field]
|
65
|
+
trial_activated_at_field = AppManager.configuration.field_names['trial_activated_at']
|
66
|
+
trial_activated_at_val = self[trial_activated_at_field]
|
67
|
+
plan_field = AppManager.configuration.field_names['plan_id']
|
68
|
+
plan_id = self[plan_field]
|
69
|
+
plan_obj = AppManager::Client.new
|
70
|
+
shop_domain ? plan_obj.get_remaining_days(shop_domain,trial_activated_at_val,plan_id) : 0
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
74
|
+
|
75
|
+
def casted_value(value,value_type)
|
76
|
+
case value_type
|
77
|
+
when "integer"
|
78
|
+
value.to_i
|
79
|
+
when "boolean"
|
80
|
+
case value
|
81
|
+
when true, 'true', 1, '1'
|
82
|
+
return true
|
83
|
+
when false, 'false', 0, '0'
|
84
|
+
return false
|
85
|
+
end
|
86
|
+
when "string"
|
87
|
+
value.to_s
|
88
|
+
else
|
89
|
+
value
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module AppManager
|
2
|
+
module Protection
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
def authorize_request
|
5
|
+
if request.headers['token'].present? && ENV['APP_MANAGER_ACCESS_TOKEN']
|
6
|
+
if request.headers['token'] === ENV['APP_MANAGER_ACCESS_TOKEN']
|
7
|
+
else
|
8
|
+
render json: {
|
9
|
+
error: "Invalid Token ",
|
10
|
+
status: 401
|
11
|
+
}, status: 401
|
12
|
+
end
|
13
|
+
else
|
14
|
+
render json: {
|
15
|
+
error: "Missing Token in request",
|
16
|
+
status: 401
|
17
|
+
}, status: 401
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module AppManager
|
2
|
+
module Actions
|
3
|
+
class ResponseCache
|
4
|
+
def initialize(cache_path)
|
5
|
+
@cache_path = cache_path
|
6
|
+
@expires_in = AppManager.configuration.expires_in || 1.day
|
7
|
+
end
|
8
|
+
|
9
|
+
def present?
|
10
|
+
cached_response.present?
|
11
|
+
end
|
12
|
+
|
13
|
+
def body
|
14
|
+
cached_response['body']
|
15
|
+
end
|
16
|
+
|
17
|
+
def status
|
18
|
+
cached_response['status']
|
19
|
+
end
|
20
|
+
|
21
|
+
def headers
|
22
|
+
cached_response['headers']
|
23
|
+
end
|
24
|
+
|
25
|
+
def cached_response
|
26
|
+
@cached_response ||= Rails.cache.read(@cache_path)
|
27
|
+
end
|
28
|
+
|
29
|
+
def write_cache(response)
|
30
|
+
cache_object = {
|
31
|
+
body: response.body,
|
32
|
+
status: response.status,
|
33
|
+
headers: response.headers
|
34
|
+
}.as_json
|
35
|
+
Rails.cache.write(@cache_path, cache_object, expires_in: @expires_in)
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
namespace :sync do
|
2
|
+
desc "This task sync local pending charge with app manager portal"
|
3
|
+
task local_app_manager: :environment do
|
4
|
+
begin
|
5
|
+
@fs = AppManager::FailSafe.new
|
6
|
+
@fs.sync_app_manager
|
7
|
+
puts "app manager sync successfully"
|
8
|
+
rescue Exception => e
|
9
|
+
Rails.logger.info "APP MANAGER SYNC TAKS FAILED #{e.inspect}"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/lib/app_manager/version.rb
CHANGED
data/lib/app_manager.rb
CHANGED
@@ -2,11 +2,31 @@
|
|
2
2
|
|
3
3
|
require "httparty"
|
4
4
|
require "rails"
|
5
|
+
require 'sqlite3'
|
5
6
|
require "app_manager/version"
|
6
7
|
require "app_manager/engine"
|
7
8
|
require "app_manager/client"
|
8
|
-
|
9
|
+
require "app_manager/actions"
|
10
|
+
require "app_manager/api_cache_handler"
|
11
|
+
require "app_manager/graphql_helper"
|
12
|
+
require "app_manager/response_cache"
|
13
|
+
require "app_manager/config"
|
14
|
+
require "app_manager/protection"
|
15
|
+
require "app_manager/model"
|
16
|
+
require "app_manager/fail_safe"
|
17
|
+
require 'app_manager/railtie' if defined?(Rails)
|
9
18
|
|
10
19
|
module AppManager
|
11
|
-
|
20
|
+
def self.configure
|
21
|
+
yield configuration
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.configuration
|
25
|
+
@configuration ||= AppManager::Config.new
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.clear_cache
|
29
|
+
Rails.cache.delete_matched('api-response-cache/*')
|
30
|
+
end
|
31
|
+
|
12
32
|
end
|
@@ -8,6 +8,14 @@ module AppManager
|
|
8
8
|
route("mount AppManager::Engine, at: '/'")
|
9
9
|
end
|
10
10
|
|
11
|
+
# def create_initializer_file
|
12
|
+
# copy_file("plan_features.rb", "config/initializers/plan_features.rb")
|
13
|
+
# end
|
14
|
+
|
15
|
+
def create_app_manager_initializer
|
16
|
+
template("app_manager.rb", "config/initializers/app_manager.rb")
|
17
|
+
end
|
18
|
+
|
11
19
|
end
|
12
20
|
end
|
13
21
|
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
AppManager.configure do |config|
|
2
|
+
config.enable_caching = false # Optional, True to enable app-manager api response caching, default is enabled from gem
|
3
|
+
config.expires_in = 1.days # Optional, Example: 30.seconds, 5.minutes or 2.days Default caching is for 1.days from gem
|
4
|
+
config.app_url = '' # App URL like https://volumediscount.hulkapps.dev/ or #https://5044-2409-4052-209a-69da-9d7-925a-9418-a9c3.ngrok.io
|
5
|
+
config.shopify_api_key = '' # Shopify api key of app
|
6
|
+
config.shopify_api_version = '' # Must be 2022-04 or latest
|
7
|
+
config.shopify_table_name = 'shops' # Table name which is generated by shopify mostly it is 'shops'
|
8
|
+
config.shopify_domain_field = 'shopify_domain' #shopify domain field
|
9
|
+
config.plan_id_or_name_field = 'plan_id'
|
10
|
+
config.field_names = {
|
11
|
+
'name' => 'shopify_domain', # demo-rahul-tiwari.myshopify.com
|
12
|
+
'shopify_email' => 'email', # rahul.t@hulkapps.com
|
13
|
+
'shopify_token' => 'shopify_token',
|
14
|
+
'shopify_plan' => 'plan_name', # partner_test
|
15
|
+
'plan_id' => 'plan_id', # 1. t
|
16
|
+
'created_at' => 'created_at', # 2022-04-15 10:43:05
|
17
|
+
'trial_activated_at' => 'trial_activated_at' # field name that stores trial start/activated date
|
18
|
+
}
|
19
|
+
config.plan_features = [
|
20
|
+
{
|
21
|
+
"uuid" => "b48a3a6c-c1fb-11ec-9d64-0242ac120002",
|
22
|
+
"name" => "Features 1",
|
23
|
+
"slug" => "feature-1",
|
24
|
+
"description" => "Feature Description",
|
25
|
+
"value_type" => "integer",
|
26
|
+
"format" => "count",
|
27
|
+
"display_order" => 1
|
28
|
+
},
|
29
|
+
{
|
30
|
+
"uuid" => "9f18f95a-bfaf-11ec-9d64-0242ac120002",
|
31
|
+
"name" => "Features 2",
|
32
|
+
"slug" => "feature-2",
|
33
|
+
"description" => "Feature Description",
|
34
|
+
"value_type" => "boolean",
|
35
|
+
"format" => "percentage",
|
36
|
+
"display_order" => 2
|
37
|
+
},
|
38
|
+
{
|
39
|
+
"uuid" => "9f190a26-bfaf-11ec-9d64-0242ac120002",
|
40
|
+
"name" => "Features 3",
|
41
|
+
"slug" => "feature-3",
|
42
|
+
"description" => "Feature Description",
|
43
|
+
"value_type" => "string",
|
44
|
+
"format" => "string",
|
45
|
+
"display_order" => 3
|
46
|
+
},
|
47
|
+
{
|
48
|
+
"uuid" => "9f191340-bfaf-11ec-9d64-0242ac12000",
|
49
|
+
"name" => "Features 4",
|
50
|
+
"slug" => "feature-4",
|
51
|
+
"description" => "Feature Description",
|
52
|
+
"value_type" => "array",
|
53
|
+
"values" => [
|
54
|
+
"val 1",
|
55
|
+
"val 2"
|
56
|
+
],
|
57
|
+
"format" => "string",
|
58
|
+
"display_order" => 4
|
59
|
+
}
|
60
|
+
] #Required, Values type : integer, boolean, string, array
|
61
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: app_manager
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hulkapps
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-05-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -38,6 +38,34 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 5.2.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: kaminari
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.16.3
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.16.3
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: sqlite3
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.3.0
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.3.0
|
41
69
|
description: Provides helper function to access AppManager API
|
42
70
|
email: rahul.t@hulkapps.com
|
43
71
|
executables: []
|
@@ -54,18 +82,33 @@ files:
|
|
54
82
|
- Rakefile
|
55
83
|
- app/controllers/app_manager/application_controller.rb
|
56
84
|
- app/controllers/app_manager/banners_controller.rb
|
85
|
+
- app/controllers/app_manager/charges_controller.rb
|
86
|
+
- app/controllers/app_manager/plans_controller.rb
|
87
|
+
- app/controllers/concerns/app_manager/authenticate.rb
|
57
88
|
- app_manager-0.1.0.gem
|
58
89
|
- app_manager.gemspec
|
59
90
|
- bin/console
|
60
91
|
- bin/setup
|
61
92
|
- config/routes.rb
|
62
93
|
- lib/app_manager.rb
|
94
|
+
- lib/app_manager/actions.rb
|
95
|
+
- lib/app_manager/api_cache_handler.rb
|
63
96
|
- lib/app_manager/client.rb
|
64
97
|
- lib/app_manager/client/banners.rb
|
65
98
|
- lib/app_manager/client/connection.rb
|
99
|
+
- lib/app_manager/client/plans.rb
|
100
|
+
- lib/app_manager/config.rb
|
66
101
|
- lib/app_manager/engine.rb
|
102
|
+
- lib/app_manager/fail_safe.rb
|
103
|
+
- lib/app_manager/graphql_helper.rb
|
104
|
+
- lib/app_manager/model.rb
|
105
|
+
- lib/app_manager/protection.rb
|
106
|
+
- lib/app_manager/railtie.rb
|
107
|
+
- lib/app_manager/response_cache.rb
|
108
|
+
- lib/app_manager/tasks/sync/local_app_manager.rake
|
67
109
|
- lib/app_manager/version.rb
|
68
110
|
- lib/generators/app_manager/install/install_generator.rb
|
111
|
+
- lib/generators/app_manager/install/templates/app_manager.rb.tt
|
69
112
|
homepage: https://www.hulkapps.com
|
70
113
|
licenses: []
|
71
114
|
metadata: {}
|