app_manager 1.0.1 → 1.1.0

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: 8e6965769520fe875a92f79820bd1288c4d46166b3527d3a6a4417d65b530510
4
- data.tar.gz: e84cdb37ae65da5f86e86630b1892ba335939ff46e61309965c7c12a4974c51d
3
+ metadata.gz: b537020a68cfa232a0ad374777b2a3a9317d5aa599da985ac07334814567d321
4
+ data.tar.gz: e89d2d9140a3196468d77b5bed6e014e3cabde20478c5206c29fc47e3322b9e9
5
5
  SHA512:
6
- metadata.gz: f1241ef8b8d0bc7c754f0df7647d3c2402eef5eddbba89f6360844c73cdff81c79ec962bd6322aa8a265fcff07c8296abad3ea5034032eb5c2799262a2b39ad4
7
- data.tar.gz: 43097bc92bad6bb5b7cc43c918b869d565f9bbc2c795312ec15933a71494673c00f79378f2c0e1afbc2cacc75020c05141375b4dec6a77518fb6106fb55318fc
6
+ metadata.gz: 95d3718467208b590e9889a5b774da042a257b7e8f8d05f15b2317637b490b6399bdbe8467fad02226b651d9c7119e805f0e031658202f2f439c9a8dff836111
7
+ data.tar.gz: aaeee10fb9e7e7edeb4c743ce2bb3df1b5c332f42386a6d87b866d9e33da2a06ba74e45cb7888da1ea97ca581a48291ae373c49ea1e93cbf7c9e6322337c2ada
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- app_manager (1.0.1)
4
+ app_manager (1.1.0)
5
5
  httparty
6
6
  kaminari (>= 0.16.3)
7
7
  rails (>= 5.2.0)
data/README.md CHANGED
@@ -2,23 +2,55 @@
2
2
 
3
3
  Welcome to the new gem of Hulkapps.com ! An API wrapper of Hulkapps.com's AppManager portal.
4
4
 
5
- ## Installation
5
+ * [Installation](#step1)
6
+ * [Configuration](#step2)
7
+ * [Usage](#step3)
8
+ * [Extras](#step4)
6
9
 
7
- Step 1) Add following line to your application's Gemfile:
10
+
11
+ <a name="step1"></a>
12
+ ### Installation
13
+
14
+ * Add following line to your application's Gemfile:
8
15
 
9
16
  ```ruby
10
17
  gem 'app_manager'
11
18
  ```
12
19
 
13
- Step 2) Execute following in terminal:
20
+ * Execute following in terminal:
14
21
 
22
+ ```
15
23
  bundle install
24
+ ```
25
+ ```
26
+ rails g app_manager:install
27
+ ```
16
28
 
29
+ this install command will mount routes in your rails route and will create a config file at ```config/initializers/app_manager.rb```
17
30
 
18
- rails g app_manager:install
19
31
 
32
+ <a name="step2"></a>
33
+ ### Configuration
34
+
35
+ * Set Shopify API version to 2022-04 as app_manager is best compatible with this version.
36
+
37
+
38
+ * Please check the 'shops' table that must have 'plan_id' as int/bigint and 'trial_activated_at' as datetime otherwise add its migration like following example:
39
+
40
+ ```
41
+ class AddPlanIdToShops < ActiveRecord::Migration[5.2]
42
+ def change
43
+ add_column :shops, :plan_id, :bigint
44
+ add_column :shops, :trial_activated_at, :datetime
45
+ end
46
+ end
47
+ ```
48
+
49
+ and map these new fields in 'config.field_names' in below initializer file which is generated by install command. Please note: this is important step.
50
+
51
+
52
+ * Please update blank fields in initializer file. Please copy 'uuid' from this [file](https://docs.google.com/spreadsheets/d/1cw2nSKxAHTGn4Cfa98RNdtfHT3zdtwu9bQD7s7hErXc/edit#gid=0) 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](https://docs.google.com/spreadsheets/d/1cw2nSKxAHTGn4Cfa98RNdtfHT3zdtwu9bQD7s7hErXc/edit#gid=0).
20
53
 
21
- this install command will mount routes in your rails route and will create a config file at ```config/initializers/app_manager.rb```
22
54
 
23
55
  ```
24
56
  AppManager.configure do |config|
@@ -85,24 +117,15 @@ end
85
117
  ```
86
118
 
87
119
 
88
- Please note: Your shops table must have 'plan_id' as int/bigint and 'trial_activated_at' as datetime otherwise add its migration. Sample example:
89
- ```
90
- class AddPlanIdToShops < ActiveRecord::Migration[5.2]
91
- def change
92
- add_column :shops, :plan_id, :bigint
93
- add_column :shops, :trial_activated_at, :datetime
94
- end
95
- end
96
- ```
97
-
98
- and map these new fields in 'config.field_names' in above initializer file.
99
-
100
- Step 3) You must have to set ENV variable with key 'APP_MANAGER_ACCESS_TOKEN' in your application.yml or .env file like this:
120
+
121
+ * You must have to set ENV variable with key 'APP_MANAGER_ACCESS_TOKEN' in your application.yml or .env file like this:
101
122
 
123
+ ```
102
124
  APP_MANAGER_ACCESS_TOKEN: 'XXXXXXXXXXXXXXXXXXX'
103
125
  APP_MANAGER_API_URL: 'https://XXXXXXXX.com'
126
+ ```
104
127
 
105
- 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](https://github.com/javan/whenever) gem then you must need to include following rake take in your 'schedule.rb' (created by whenever gem)
128
+ * 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](https://github.com/javan/whenever) gem then you MUST need to include following rake take in your 'schedule.rb' (created by whenever gem)
106
129
 
107
130
  ```
108
131
  every 10.minutes do
@@ -110,7 +133,12 @@ every 10.minutes do
110
133
  end
111
134
  ```
112
135
 
113
- Steps 5) App Manager provides a helper module which needs to include in your 'shop' model something like below
136
+
137
+ <a name="step3"></a>
138
+ ### Usage
139
+
140
+
141
+ * App Manager provides a helper module which needs to include in your 'shop' model something like below
114
142
 
115
143
  ```
116
144
  class Shop < ActiveRecord::Base
@@ -118,10 +146,7 @@ class Shop < ActiveRecord::Base
118
146
  end
119
147
  ```
120
148
 
121
-
122
- ## Usage
123
-
124
- Using above 5th step you can access following methods from your shop object.
149
+ and then you can use follwing methods with your shop objects.
125
150
 
126
151
  ```
127
152
  @shop.has_plan # return true or false
@@ -137,11 +162,10 @@ Using above 5th step you can access following methods from your shop object.
137
162
  ```
138
163
 
139
164
 
165
+ <a name="step4"></a>
166
+ ### Extras
140
167
 
141
- #### As a helper:
142
-
143
-
144
- Then, initialize app_manager instance like with App Manager Portal access:
168
+ * 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:
145
169
 
146
170
  ```ruby
147
171
  ob = AppManager::Client.new(ENV['APP_MANAGER_ACCESS_TOKEN'])
@@ -152,13 +176,15 @@ To get banners use this command:
152
176
  ob.get_banners
153
177
  ```
154
178
 
155
- #### For Vue UI Library in Rails Project:
179
+
180
+ * For Vue UI Library in Rails Project:
156
181
 
157
182
  Please make sure you have following line in your route file otherwise add this manually.
158
183
 
159
184
  mount AppManager::Engine, at: "/"
160
185
 
161
186
 
187
+
162
188
  ## Development
163
189
 
164
190
  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.
@@ -63,21 +63,27 @@ module AppManager
63
63
 
64
64
  def users
65
65
  if model
66
+ if params[:search]
67
+ search = params[:search]
68
+ @shopify_email = AppManager.configuration.field_names['shopify_email']
69
+ data = model.where("#{@shopify_domain} LIKE :search OR #{@shopify_email} LIKE :search", search: "%#{search}%").page(params[:page]).per(10)
70
+ else
66
71
  data = model.page(params[:page]).per(10)
72
+ end
67
73
  users = {
68
- "current_page" => data.current_page,
69
- "data" => data.collect{|st| @field_names.map{ |key, value| [key, "#{st[value]}"] }.to_h },
74
+ "current_page" => data && data.current_page ? data.current_page : 0,
75
+ "data" => data ? data.collect{|st| @field_names.map{ |key, value| [key, "#{st[value]}"] }.to_h } : [],
70
76
  "first_page_url" => "#{app_url}/api/app-manager/users?page=1",
71
- "from" => data.total_pages ? 1 : nil,
72
- "last_page" => data.total_pages,
73
- "last_page_url" => data.total_pages ? "#{app_url}/api/app-manager/users?page=#{data.total_pages}" : nil,
77
+ "from" => data && data.total_pages ? 1 : 0,
78
+ "last_page" => data && data.total_pages ? data.total_pages : 0,
79
+ "last_page_url" => data && data.total_pages ? "#{app_url}/api/app-manager/users?page=#{data.total_pages}" : nil,
74
80
  "links"=> '',
75
- "next_page_url" => data.next_page ? "#{app_url}/api/app-manager/users?page=#{data.next_page}" : nil,
81
+ "next_page_url" => data && data.next_page ? "#{app_url}/api/app-manager/users?page=#{data.next_page}" : nil,
76
82
  "path" => "#{app_url}/api/app-manager/users",
77
83
  "per_page" => 1,
78
- "prev_page_url" => data.prev_page ? "#{app_url}/api/app-manager/users?page=#{data.prev_page}" : nil,
79
- "to" => data.total_pages,
80
- "total" => data.total_pages
84
+ "prev_page_url" => data && data.prev_page ? "#{app_url}/api/app-manager/users?page=#{data.prev_page}" : nil,
85
+ "to" => data && data.total_pages ? data.total_pages : 0,
86
+ "total" => data && data.total_pages ? data.total_pages : 0,
81
87
  }
82
88
  render json: users
83
89
 
@@ -118,6 +124,7 @@ module AppManager
118
124
  rescue Exception => e
119
125
  Rails.logger.info "APP MANGAGER >>>> #{e.inspect}"
120
126
  end
127
+ AppManager.clear_cache
121
128
  end
122
129
  head :ok
123
130
  end
@@ -56,10 +56,10 @@ module AppManager
56
56
  body = @response_cache.body
57
57
  status = @response_cache.status
58
58
  headers = @response_cache.headers
59
- headers.try(:each) do |key, value|
60
- @controller.response.headers[key] = value
61
- end
62
- @controller.render plain: body, status: status
59
+ # headers.try(:each) do |key, value|
60
+ # @controller.response.headers[key] = value
61
+ # end
62
+ @controller.render json: body, status: status
63
63
  end
64
64
  end
65
65
  end
@@ -12,22 +12,46 @@ module AppManager
12
12
 
13
13
  def save_api_data(params)
14
14
  Thread.new do
15
- save_api_plans(params["plans"])
15
+ begin
16
+ save_api_plans(params["plans"])
17
+ rescue Exception => e
18
+ Rails.logger.info "APP MANGAGER >>>> #{e.inspect}"
19
+ end
16
20
  end
17
21
  Thread.new do
18
- save_api_charges(params["charges"])
22
+ begin
23
+ save_api_charges(params["charges"])
24
+ rescue Exception => e
25
+ Rails.logger.info "APP MANGAGER >>>> #{e.inspect}"
26
+ end
19
27
  end
20
28
  Thread.new do
21
- save_api_apps(params["apps"])
29
+ begin
30
+ save_api_apps(params["apps"])
31
+ rescue Exception => e
32
+ Rails.logger.info "APP MANGAGER >>>> #{e.inspect}"
33
+ end
22
34
  end
23
35
  Thread.new do
24
- save_api_app_structures(params["app_structures"])
36
+ begin
37
+ save_api_app_structures(params["app_structures"])
38
+ rescue Exception => e
39
+ Rails.logger.info "APP MANGAGER >>>> #{e.inspect}"
40
+ end
25
41
  end
26
42
  Thread.new do
27
- save_api_discount_plans(params["discount_plans"])
43
+ begin
44
+ save_api_discount_plans(params["discount_plans"])
45
+ rescue Exception => e
46
+ Rails.logger.info "APP MANGAGER >>>> #{e.inspect}"
47
+ end
28
48
  end
29
49
  Thread.new do
30
- save_api_extend_trials(params["extend_trials"])
50
+ begin
51
+ save_api_extend_trials(params["extend_trials"])
52
+ rescue Exception => e
53
+ Rails.logger.info "APP MANGAGER >>>> #{e.inspect}"
54
+ end
31
55
  end
32
56
  end
33
57
 
@@ -71,14 +71,15 @@ module AppManager
71
71
  end
72
72
 
73
73
  discount_type = plan['discount_type'] || "percentage"
74
- discount_val = discount_type == "percentage" ? (plan['discount'].to_f/ 100) : plan['discount']
75
- plan_discount = plan['discount'] ? { "durationLimitInIntervals" => (plan['discount_interval'] || nil), "value" => {"#{discount_type}" => discount_val} } : {}
74
+ discount_val = discount_type == "percentage" ? (plan['discount'].to_f/ 100) : "#{plan['discount']}"
75
+ plan_discount = plan['discount'] ? { "discount" => { "durationLimitInIntervals" => (plan['cycle_count'] || nil), "value" => {"#{discount_type}" => discount_val} } } : {}
76
76
 
77
77
  price_details = {
78
78
  "price": { "amount": plan['price'], "currencyCode": 'USD' },
79
79
  "interval": plan['interval']['value']
80
80
  }
81
- price_details << plan_discount if plan_discount.any?
81
+ price_details.merge! plan_discount if plan_discount.any?
82
+
82
83
 
83
84
  query = 'mutation(
84
85
  $name: String!,
@@ -112,10 +113,11 @@ module AppManager
112
113
  "test": plan_test,
113
114
  "lineItems": [{
114
115
  "plan": {
115
- "appRecurringPricingDetails": price_details
116
+ "appRecurringPricingDetails": price_details
116
117
  }
117
118
  }]
118
119
  }
120
+
119
121
  data = run_graph_api(query,variables)
120
122
  return data
121
123
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AppManager
4
- VERSION = "1.0.1"
4
+ VERSION = "1.1.0"
5
5
  end
data/lib/app_manager.rb CHANGED
@@ -26,7 +26,7 @@ module AppManager
26
26
  end
27
27
 
28
28
  def self.clear_cache
29
- Rails.cache.delete_matched('api-response-cache/*')
29
+ Rails.cache.delete_matched('app-manager-cache/*')
30
30
  end
31
31
 
32
32
  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.0.1
4
+ version: 1.1.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-05-26 00:00:00.000000000 Z
11
+ date: 2022-06-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty