app_manager 1.2.1 → 1.2.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bd770dce16b7f6239b4d98067abafbf7701a3dd5b02cd4094b2f264c2ce9d8dd
4
- data.tar.gz: 466aa7a4aba2811f53b582b0d2fa6dd7b94b2eb0430ef146729214414175ad8c
3
+ metadata.gz: 9c547a5aa3260006c06faf84cd242801459dc0d6557139d94797558b2e960cf3
4
+ data.tar.gz: bb52538ee806521616ca899b526db05d5dfa606921c0a49874584af7d5960ed2
5
5
  SHA512:
6
- metadata.gz: 6d6e415883e4a5e08155776f041da234c099ec0a9c17814be2013d7efafa91263d117046c35b2dd95c4a0809230a637878cb1d9e1f785b385e9f9588269547db
7
- data.tar.gz: 0d3e02114538f9178a88cfc1e2f30409227852088755121c47dd1648d20bd1919e78228f197c41199ae02f2251fef66953ae6ee560b46389ded1bd555f48088a
6
+ metadata.gz: 0cf9d50efcfd4a72bc88a842d1ba7508a56cfe0a4eb29c3226ed526cda19a095125382292093fd2f296ea71c8cdca562039af5dda5b2ba2df34fe4ca05070f8c
7
+ data.tar.gz: 6b4db1ea27b42898de5549a5fa528a3df9c759071e228d9a373075766b91086658d632b8427e5d9761382d16c3f46cb2685b5dcb8f33898f4590e3f7dd50f3f9
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- app_manager (1.2.1)
4
+ app_manager (1.2.4)
5
5
  httparty
6
6
  kaminari (>= 0.16.3)
7
7
  rails (>= 5.2.0)
@@ -18,11 +18,12 @@ module AppManager
18
18
  if plan_data['price'] == 0
19
19
  active_charge_data = plan_obj.get_charge(params[:shop])
20
20
  begin
21
- if active_charge_data && active_charge_data.any? && !active_charge_data['active_charge']['charge_id'].nil?
21
+ if active_charge_data && active_charge_data.any? && !active_charge_data['active_charge'].nil? && !active_charge_data['active_charge']['charge_id'].nil?
22
22
  gq_obj = AppManager::GraphqlHelper.new(@shop.shopify_domain,@shop.shopify_token)
23
23
  rec_cancel_data = gq_obj.recurring_charge_cancel_api_call(active_charge_data['active_charge']['charge_id'],@shop)
24
- if !rec_cancel_data["errors"].present? && (rec_cancel_data["data"].present? && rec_cancel_data["data"]["appSubscriptionCancel"].present? && !rec_cancel_data["data"]["appSubscriptionCreate"]["userErrors"].any? && (rec_cancel_data["data"]["appSubscriptionCancel"]["appSubscription"]["status"] == 'CANCELLED'))
25
- plan_obj.cancel_charge(params[:shop],active_charge_data['active_charge']['plan_id'])
24
+ if !rec_cancel_data["errors"].present? && (rec_cancel_data["data"].present? && rec_cancel_data["data"]["appSubscriptionCancel"].present? && !rec_cancel_data["data"]["appSubscriptionCancel"]["userErrors"].any? && (rec_cancel_data["data"]["appSubscriptionCancel"]["appSubscription"]["status"] == 'CANCELLED'))
25
+ cancelled_charge_id = rec_cancel_data["data"]["appSubscriptionCancel"]["appSubscription"]["id"].split('/')[-1]
26
+ plan_obj.cancel_charge(params[:shop],cancelled_charge_id)
26
27
  end
27
28
  end
28
29
  rescue Exception => e
@@ -172,6 +172,7 @@ module AppManager
172
172
  end
173
173
 
174
174
 
175
+
175
176
  private
176
177
 
177
178
  def params_permit
@@ -35,7 +35,7 @@ module AppManager
35
35
  'email' => 'email'
36
36
  }
37
37
  @fs = AppManager::FailSafe.new
38
- AppManager.clear_cache
38
+ # AppManager.clear_cache
39
39
  end
40
40
 
41
41
  def expires_in
@@ -10,7 +10,7 @@ module AppManager
10
10
  def initialize(db_name='app_manager_local')
11
11
  @apm_db = SQLite3::Database.open "db/#{db_name}.db"
12
12
  begin
13
- FileUtils.chmod 0777, "db/#{db_name}.db"
13
+ FileUtils.chmod 0664, "db/#{db_name}.db"
14
14
  rescue Exception => e
15
15
  puts ">>>>>> #{e.inspect}"
16
16
  end
@@ -29,36 +29,90 @@ module AppManager
29
29
  save_api_plans(params["plans"])
30
30
  rescue Exception => e
31
31
  Rails.logger.info "APP MANAGER >>>> #{e.inspect}"
32
+ begin
33
+ create_plan_table
34
+ save_api_plans(params["plans"])
35
+ rescue Exception => e
36
+ Rails.logger.info "APP MANAGER FailSafe >>>> #{e.inspect}"
37
+ end
32
38
  end
39
+
40
+
33
41
  begin
34
42
  save_api_charges(params["charges"])
35
43
  rescue Exception => e
36
- Rails.logger.info "APP MANAGER >>>> #{e.inspect}"
44
+ Rails.logger.info "APP MANAGER >>>> #{e.inspect}"
45
+ begin
46
+ create_charges_table
47
+ save_api_charges(params["charges"])
48
+ rescue Exception => e
49
+ Rails.logger.info "APP MANAGER FailSafe >>>> #{e.inspect}"
50
+ end
37
51
  end
52
+
53
+
38
54
  begin
39
55
  save_api_apps(params["apps"])
40
56
  rescue Exception => e
41
- Rails.logger.info "APP MANAGER >>>> #{e.inspect}"
57
+ Rails.logger.info "APP MANAGER >>>> #{e.inspect}"
58
+ begin
59
+ create_apps_table
60
+ save_api_apps(params["apps"])
61
+ rescue Exception => e
62
+ Rails.logger.info "APP MANAGER FailSafe >>>> #{e.inspect}"
63
+ end
42
64
  end
65
+
66
+
43
67
  begin
44
68
  save_api_app_structures(params["app_structures"])
45
69
  rescue Exception => e
46
- Rails.logger.info "APP MANAGER >>>> #{e.inspect}"
70
+ Rails.logger.info "APP MANAGER >>>> #{e.inspect}"
71
+ begin
72
+ create_app_structures_table
73
+ save_api_app_structures(params["app_structures"])
74
+ rescue Exception => e
75
+ Rails.logger.info "APP MANAGER FailSafe >>>> #{e.inspect}"
76
+ end
47
77
  end
78
+
79
+
48
80
  begin
49
81
  save_api_discount_plans(params["discount_plans"])
50
82
  rescue Exception => e
51
83
  Rails.logger.info "APP MANAGER >>>> #{e.inspect}"
84
+ begin
85
+ create_discount_plans_table
86
+ save_api_discount_plans(params["discount_plans"])
87
+ rescue Exception => e
88
+ Rails.logger.info "APP MANAGER FailSafe >>>> #{e.inspect}"
89
+ end
52
90
  end
91
+
92
+
53
93
  begin
54
94
  save_api_extend_trials(params["extend_trials"])
55
95
  rescue Exception => e
56
- Rails.logger.info "APP MANAGER >>>> #{e.inspect}"
96
+ Rails.logger.info "APP MANAGER >>>> #{e.inspect}"
97
+ begin
98
+ create_extend_trials_table
99
+ save_api_extend_trials(params["extend_trials"])
100
+ rescue Exception => e
101
+ Rails.logger.info "APP MANAGER FailSafe >>>> #{e.inspect}"
102
+ end
57
103
  end
104
+
105
+
58
106
  begin
59
107
  save_api_plan_users(params["plan_users"])
60
108
  rescue Exception => e
61
- Rails.logger.info "APP MANAGER >>>> #{e.inspect}"
109
+ Rails.logger.info "APP MANAGER >>>> #{e.inspect}"
110
+ begin
111
+ create_plan_users_table
112
+ save_api_plan_users(params["plan_users"])
113
+ rescue Exception => e
114
+ Rails.logger.info "APP MANAGER FailSafe >>>> #{e.inspect}"
115
+ end
62
116
  end
63
117
  end
64
118
 
@@ -2,7 +2,8 @@ module AppManager
2
2
  module Model
3
3
  extend ActiveSupport::Concern
4
4
 
5
-
5
+ @@remaining_cache_key = "get_remaining_days_key"
6
+ @@get_charge_key = "get_charge_key"
6
7
 
7
8
  def has_plan
8
9
  if !self[AppManager.configuration.plan_id_or_name_field]
@@ -16,14 +17,15 @@ module AppManager
16
17
  Rails.logger.info "Plan id found nil or not set"
17
18
  return false;
18
19
  end
19
- remaining_days = self.get_remaining_days
20
+ remaining_days = fetch_static_remaining_days
20
21
  if remaining_days > 0
21
22
  return true
22
23
  end
23
- plan_obj = AppManager::Client.new
24
- shop_domain = self[AppManager.configuration.shopify_domain_field]
25
- active_charge = plan_obj.get_charge(shop_domain) rescue nil
26
- return active_charge['active_charge'].present? && !active_charge['active_charge'].nil? ? true : false
24
+ # plan_obj = AppManager::Client.new
25
+ # shop_domain = self[AppManager.configuration.shopify_domain_field]
26
+ # active_charge = plan_obj.get_charge(shop_domain) rescue nil
27
+ active_charge = fetch_static_get_charge
28
+ return active_charge && active_charge['active_charge'].present? && !active_charge['active_charge'].nil? ? true : false
27
29
  end
28
30
 
29
31
 
@@ -195,6 +197,41 @@ module AppManager
195
197
 
196
198
 
197
199
 
200
+ def fetch_static_remaining_days
201
+ @remaining_cache_key = "app-manager-cache/#{self.shopify_domain}-remaining_days"
202
+ if fetch_cached_static_remaining_days(@remaining_cache_key).present?
203
+ return fetch_cached_static_remaining_days(@remaining_cache_key)
204
+ end
205
+ remaining_days = self.get_remaining_days
206
+ Rails.cache.write(@remaining_cache_key, remaining_days, expires_in: AppManager.configuration.expires_in)
207
+ return remaining_days
208
+ end
209
+
210
+ def fetch_cached_static_remaining_days(cache_key)
211
+ if Rails.cache.read(cache_key).present?
212
+ return Rails.cache.read(cache_key)
213
+ end
214
+ end
215
+
216
+
217
+
218
+ def fetch_static_get_charge
219
+ @get_charge_key = "app-manager-cache/#{self.shopify_domain}-get_charge"
220
+ if fetch_cached_static_get_charge(@get_charge_key).present?
221
+ return fetch_cached_static_get_charge(@get_charge_key)
222
+ end
223
+ charge = self.get_charge
224
+ Rails.cache.write(@get_charge_key, charge, expires_in: AppManager.configuration.expires_in)
225
+ return charge
226
+ end
227
+
228
+ def fetch_cached_static_get_charge(cache_key)
229
+ if Rails.cache.read(cache_key).present?
230
+ return Rails.cache.read(cache_key)
231
+ end
232
+ end
233
+
234
+
198
235
  private
199
236
 
200
237
  def casted_value(value,value_type)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AppManager
4
- VERSION = "1.2.1"
4
+ VERSION = "1.2.4"
5
5
  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: 1.2.1
4
+ version: 1.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hulkapps
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-07-05 00:00:00.000000000 Z
11
+ date: 2022-07-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty