disco_app 0.6.0 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/jobs/disco_app/app_installed_job.rb +2 -40
- data/app/jobs/disco_app/concerns/app_installed_job.rb +46 -0
- data/app/jobs/disco_app/concerns/app_uninstalled_job.rb +4 -3
- data/app/jobs/disco_app/concerns/shop_update_job.rb +16 -0
- data/app/jobs/disco_app/shop_job.rb +18 -20
- data/app/jobs/disco_app/shop_update_job.rb +2 -15
- data/lib/disco_app/version.rb +1 -1
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a29063430cb2904c29bf74567496355a5f70d5e4e5d942d8f9ad8341ee99f935
|
4
|
+
data.tar.gz: c1ad2a5cf842f792213ef025f948057132bfdede2c78945d965edc925ad3f62f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6dd9ac41a62be53b26c1ab0d7aa30d0078a1adbc0ae7cb5342567bca85764da13eba2b6a3cb5dbcfc4867dd8ea7e433811eaa9131549d85a43b2d75fe7a09a89
|
7
|
+
data.tar.gz: 2c06d93aaae37aa4d52b39ae35727e0ebf1bfd9c86f252bbd9bb910e61088c74aaba02037675b8da29beb50b4a8f485ba8f54ac9f0a508c88cb1b2cc05fcb8bc
|
@@ -1,41 +1,3 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
before_enqueue { @shop.awaiting_install! }
|
5
|
-
before_perform { @shop.installing! }
|
6
|
-
after_perform { @shop.installed! }
|
7
|
-
|
8
|
-
def perform(domain)
|
9
|
-
|
10
|
-
# Install webhooks.
|
11
|
-
(base_webhook_topics + webhook_topics).each do |topic|
|
12
|
-
ShopifyAPI::Webhook.create(topic: topic, address: webhooks_url, format: 'json')
|
13
|
-
end
|
14
|
-
|
15
|
-
# Perform initial update of shop information.
|
16
|
-
DiscoApp::ShopUpdateJob.perform_now(domain)
|
17
|
-
|
18
|
-
end
|
19
|
-
|
20
|
-
protected
|
21
|
-
|
22
|
-
# Return a list of additional webhook topics to listen for.
|
23
|
-
# This method should be overridden in the application.
|
24
|
-
def webhook_topics
|
25
|
-
[]
|
26
|
-
end
|
27
|
-
|
28
|
-
private
|
29
|
-
|
30
|
-
# Return a list of webhook topics that will always be set up for the application.
|
31
|
-
def base_webhook_topics
|
32
|
-
[:'app/uninstalled', :'shop/update']
|
33
|
-
end
|
34
|
-
|
35
|
-
# Return the absolute URL to the webhooks endpoint.
|
36
|
-
def webhooks_url
|
37
|
-
DiscoApp::Engine.routes.url_helpers.webhooks_url
|
38
|
-
end
|
39
|
-
|
40
|
-
end
|
1
|
+
class DiscoApp::AppInstalledJob < DiscoApp::ShopJob
|
2
|
+
include DiscoApp::Concerns::AppInstalledJob
|
41
3
|
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module DiscoApp::Concerns::AppInstalledJob
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
included do
|
5
|
+
before_enqueue { @shop.awaiting_install! }
|
6
|
+
before_perform { @shop.installing! }
|
7
|
+
after_perform { @shop.installed! }
|
8
|
+
end
|
9
|
+
|
10
|
+
# Perform application installation.
|
11
|
+
#
|
12
|
+
# - Install webhooks, using a list generated from the base_webhook_topics and
|
13
|
+
# webhook_topics methods.
|
14
|
+
# - Perform initial update of shop information.
|
15
|
+
#
|
16
|
+
def perform(domain)
|
17
|
+
(base_webhook_topics + webhook_topics).each do |topic|
|
18
|
+
ShopifyAPI::Webhook.create(topic: topic, address: webhooks_url, format: 'json')
|
19
|
+
end
|
20
|
+
|
21
|
+
DiscoApp::ShopUpdateJob.perform_now(domain)
|
22
|
+
end
|
23
|
+
|
24
|
+
protected
|
25
|
+
|
26
|
+
# Return a list of additional webhook topics to listen for. This method
|
27
|
+
# can be overridden in the application to provide a list of app-specific
|
28
|
+
# webhooks that should be created during installation.
|
29
|
+
def webhook_topics
|
30
|
+
[]
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
# Return a list of webhook topics that will always be set up for the
|
36
|
+
# # application.
|
37
|
+
def base_webhook_topics
|
38
|
+
[:'app/uninstalled', :'shop/update']
|
39
|
+
end
|
40
|
+
|
41
|
+
# Return the absolute URL to the webhooks endpoint.
|
42
|
+
def webhooks_url
|
43
|
+
DiscoApp::Engine.routes.url_helpers.webhooks_url
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -2,15 +2,16 @@ module DiscoApp::Concerns::AppUninstalledJob
|
|
2
2
|
extend ActiveSupport::Concern
|
3
3
|
|
4
4
|
included do
|
5
|
-
|
6
5
|
before_enqueue { @shop.awaiting_uninstall! }
|
7
6
|
before_perform { @shop.uninstalling! }
|
8
7
|
after_perform { @shop.uninstalled! }
|
9
|
-
|
10
8
|
end
|
11
9
|
|
10
|
+
# Perform application uninstallation.
|
11
|
+
#
|
12
|
+
# - Mark charge status as "cancelled" unless charges have been waived.
|
13
|
+
#
|
12
14
|
def perform(domain, shop_data)
|
13
|
-
# Mark the shop's charge status as "cancelled" unless charges have been waived.
|
14
15
|
unless @shop.charge_waived?
|
15
16
|
@shop.charge_cancelled!
|
16
17
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module DiscoApp::Concerns::ShopUpdateJob
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
# Perform an update of the current shop's information.
|
5
|
+
def perform(shopify_domain, shop_data = nil)
|
6
|
+
# If we weren't provided with shop data (eg from a webhook), fetch it.
|
7
|
+
shop_data ||= ActiveSupport::JSON::decode(ShopifyAPI::Shop.current.to_json)
|
8
|
+
|
9
|
+
# Ensure we can access shop data through symbols.
|
10
|
+
shop_data = HashWithIndifferentAccess.new(shop_data)
|
11
|
+
|
12
|
+
# Update model attributes present in both our model and the data hash.
|
13
|
+
@shop.update_attributes(shop_data.except(:id, :created_at).slice(*DiscoApp::Shop.column_names))
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -1,29 +1,27 @@
|
|
1
|
-
# The base class for all jobs that should be performed in the context of a
|
2
|
-
# argument to any job inheriting from
|
1
|
+
# The base class for all jobs that should be performed in the context of a
|
2
|
+
# particular Shop's API session. The first argument to any job inheriting from
|
3
|
+
# this class must be the domain of the relevant store, so that the appropriate
|
3
4
|
# Shop model can be fetched and the temporary API session created.
|
5
|
+
class DiscoApp::ShopJob < ActiveJob::Base
|
4
6
|
|
5
|
-
|
6
|
-
class ShopJob < ActiveJob::Base
|
7
|
+
queue_as :default
|
7
8
|
|
8
|
-
|
9
|
+
before_perform { |job| find_shop(job) }
|
10
|
+
before_enqueue { |job| find_shop(job) }
|
9
11
|
|
10
|
-
|
11
|
-
|
12
|
+
around_enqueue { |job, block| shop_context(job, block) }
|
13
|
+
around_perform { |job, block| shop_context(job, block) }
|
12
14
|
|
13
|
-
|
14
|
-
around_perform { |job, block| shop_context(job, block) }
|
15
|
+
private
|
15
16
|
|
16
|
-
|
17
|
+
def find_shop(job)
|
18
|
+
@shop ||= DiscoApp::Shop.find_by!(shopify_domain: job.arguments.first)
|
19
|
+
end
|
17
20
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
+
def shop_context(job, block)
|
22
|
+
@shop.temp {
|
23
|
+
block.call(job.arguments)
|
24
|
+
}
|
25
|
+
end
|
21
26
|
|
22
|
-
def shop_context(job, block)
|
23
|
-
@shop.temp {
|
24
|
-
block.call(job.arguments)
|
25
|
-
}
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|
29
27
|
end
|
@@ -1,16 +1,3 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
def perform(domain, shop_data = nil)
|
5
|
-
# If we weren't provided with shop data (eg from a webhook), fetch it.
|
6
|
-
shop_data ||= ActiveSupport::JSON::decode(ShopifyAPI::Shop.current.to_json)
|
7
|
-
|
8
|
-
# Ensure we can access shop data through symbols.
|
9
|
-
shop_data = HashWithIndifferentAccess.new(shop_data)
|
10
|
-
|
11
|
-
# Update model attributes present in both our model and the data hash.
|
12
|
-
@shop.update_attributes(shop_data.except(:id, :created_at).slice(*DiscoApp::Shop.column_names))
|
13
|
-
end
|
14
|
-
|
15
|
-
end
|
1
|
+
class DiscoApp::ShopUpdateJob < DiscoApp::ShopJob
|
2
|
+
include DiscoApp::Concerns::ShopUpdateJob
|
16
3
|
end
|
data/lib/disco_app/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: disco_app
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gavin Ballard
|
@@ -262,7 +262,9 @@ files:
|
|
262
262
|
- app/helpers/disco_app/application_helper.rb
|
263
263
|
- app/jobs/disco_app/app_installed_job.rb
|
264
264
|
- app/jobs/disco_app/app_uninstalled_job.rb
|
265
|
+
- app/jobs/disco_app/concerns/app_installed_job.rb
|
265
266
|
- app/jobs/disco_app/concerns/app_uninstalled_job.rb
|
267
|
+
- app/jobs/disco_app/concerns/shop_update_job.rb
|
266
268
|
- app/jobs/disco_app/shop_job.rb
|
267
269
|
- app/jobs/disco_app/shop_update_job.rb
|
268
270
|
- app/models/disco_app/concerns/plan.rb
|