disco_app 0.6.5 → 0.6.6
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/concerns/app_installed_job.rb +2 -0
- data/app/jobs/disco_app/concerns/synchronise_carrier_services_job.rb +47 -0
- data/app/jobs/disco_app/concerns/synchronise_webhooks_job.rb +5 -1
- data/app/jobs/disco_app/synchronise_carrier_services_job.rb +3 -0
- data/lib/disco_app/version.rb +1 -1
- data/lib/generators/disco_app/disco_app_generator.rb +2 -2
- data/lib/generators/disco_app/mailify/mailify_generator.rb +2 -2
- data/lib/tasks/carrier_services.rake +10 -0
- data/test/fixtures/api/widget_store/webhooks.json +1 -0
- data/test/jobs/disco_app/app_installed_job_test.rb +1 -0
- metadata +6 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aa5a75b03995277ab80d6bd150044085e1f7c7fad16340838ee717d292fcf38e
|
4
|
+
data.tar.gz: 218728b186a4210cf8f3411f8272b049eca6936f3ab123b82560b72b71634bc3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 748b9644cd88061e016a169438bb8ad318f41d587fb67ee8a001f02632cccb108e3cc7ff3d613d0efd75557d1c6bcf8a3e4aa81851ba8b8a25a8efff9de959e9
|
7
|
+
data.tar.gz: 93e97fbd2f46744b30babe64fe32ae1f94a328af7aef7952883734915919ea14cd884988cc862afdeaa9931bfc2af452aed13f34e2d5cbd0a73604473bba1a5f
|
@@ -10,10 +10,12 @@ module DiscoApp::Concerns::AppInstalledJob
|
|
10
10
|
# Perform application installation.
|
11
11
|
#
|
12
12
|
# - Synchronise webhooks.
|
13
|
+
# - Synchronise carrier services.
|
13
14
|
# - Perform initial update of shop information.
|
14
15
|
#
|
15
16
|
def perform(domain)
|
16
17
|
DiscoApp::SynchroniseWebhooksJob.perform_now(domain)
|
18
|
+
DiscoApp::SynchroniseCarrierServicesJob.perform_now(domain)
|
17
19
|
DiscoApp::ShopUpdateJob.perform_now(domain)
|
18
20
|
end
|
19
21
|
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module DiscoApp::Concerns::SynchroniseCarrierServicesJob
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
# Ensure the carrier services registered with our shop are the same as those
|
5
|
+
# listed in our application configuration.
|
6
|
+
def perform(shopify_domain)
|
7
|
+
# Registered any carrier services that haven't been registered yet.
|
8
|
+
(callback_urls - current_callback_urls).each do |callback_url|
|
9
|
+
ShopifyAPI::CarrierService.create(
|
10
|
+
name: carrier_service_name,
|
11
|
+
callback_url: callback_url,
|
12
|
+
service_discovery: true,
|
13
|
+
format: 'json'
|
14
|
+
)
|
15
|
+
end
|
16
|
+
|
17
|
+
# Remove any extraneous carrier services.
|
18
|
+
current_carrier_services.each do |carrier_service|
|
19
|
+
unless callback_urls.include?(carrier_service.callback_url)
|
20
|
+
carrier_service.delete
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
protected
|
26
|
+
|
27
|
+
def carrier_service_name
|
28
|
+
Rails.application.config.x.shopify_app_name
|
29
|
+
end
|
30
|
+
|
31
|
+
def callback_urls
|
32
|
+
[]
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
# Return a list of currently registered callback URLs.
|
38
|
+
def current_callback_urls
|
39
|
+
current_carrier_services.map(&:callback_url)
|
40
|
+
end
|
41
|
+
|
42
|
+
# Return a list of currently registered carrier services.
|
43
|
+
def current_carrier_services
|
44
|
+
@current_carrier_service ||= ShopifyAPI::CarrierService.find(:all)
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
@@ -9,7 +9,11 @@ module DiscoApp::Concerns::SynchroniseWebhooksJob
|
|
9
9
|
|
10
10
|
# Registered any webhooks that haven't been registered yet.
|
11
11
|
(expected_topics - current_topics).each do |topic|
|
12
|
-
ShopifyAPI::Webhook.create(
|
12
|
+
ShopifyAPI::Webhook.create(
|
13
|
+
topic: topic,
|
14
|
+
address: webhooks_url,
|
15
|
+
format: 'json'
|
16
|
+
)
|
13
17
|
end
|
14
18
|
|
15
19
|
# Remove any extraneous topics.
|
data/lib/disco_app/version.rb
CHANGED
@@ -4,12 +4,12 @@ class DiscoAppGenerator < Rails::Generators::Base
|
|
4
4
|
|
5
5
|
# Copy a number of template files to the top-level directory of our application:
|
6
6
|
#
|
7
|
-
# - .env and .env.
|
7
|
+
# - .env and .env.local for settings environment variables in development with dotenv-rails;
|
8
8
|
# - Slightly customised version of the default Rails .gitignore;
|
9
9
|
# - Default simple Procfile for Heroku.
|
10
10
|
#
|
11
11
|
def copy_root_files
|
12
|
-
%w(.env .env.
|
12
|
+
%w(.env .env.local .gitignore Procfile).each do |file|
|
13
13
|
copy_file "root/#{file}", file
|
14
14
|
end
|
15
15
|
end
|
@@ -38,7 +38,7 @@ module DiscoApp
|
|
38
38
|
application configuration, env: :production
|
39
39
|
end
|
40
40
|
|
41
|
-
# Add entries to .env and .env.
|
41
|
+
# Add entries to .env and .env.local
|
42
42
|
def add_env_variables
|
43
43
|
configuration = <<-CONFIG.strip_heredoc
|
44
44
|
|
@@ -46,7 +46,7 @@ module DiscoApp
|
|
46
46
|
MAILGUN_API_DOMAIN=
|
47
47
|
CONFIG
|
48
48
|
append_to_file '.env', configuration
|
49
|
-
append_to_file '.env.
|
49
|
+
append_to_file '.env.local', configuration
|
50
50
|
end
|
51
51
|
|
52
52
|
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
namespace :carrier_services do
|
2
|
+
|
3
|
+
desc 'Synchronise carrier services across all installed shops.'
|
4
|
+
task sync: :environment do
|
5
|
+
DiscoApp::Shop.installed.has_active_shopify_plan.each do |shop|
|
6
|
+
DiscoApp::SynchroniseCarrierServicesJob.perform_later(shop.shopify_domain)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
[]
|
@@ -12,6 +12,7 @@ class DiscoApp::AppInstalledJobTest < ActionController::TestCase
|
|
12
12
|
end
|
13
13
|
|
14
14
|
test 'app installed job performs shop update job' do
|
15
|
+
stub_request(:get, "#{@shop.admin_url}/webhooks.json").to_return(status: 200, body: api_fixture('widget_store/webhooks'))
|
15
16
|
stub_request(:post, "#{@shop.admin_url}/webhooks.json").to_return(status: 200)
|
16
17
|
stub_request(:get, "#{@shop.admin_url}/shop.json").to_return(status: 200, body: api_fixture('widget_store/shop'))
|
17
18
|
|
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.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gavin Ballard
|
@@ -278,9 +278,11 @@ files:
|
|
278
278
|
- app/jobs/disco_app/concerns/app_installed_job.rb
|
279
279
|
- app/jobs/disco_app/concerns/app_uninstalled_job.rb
|
280
280
|
- app/jobs/disco_app/concerns/shop_update_job.rb
|
281
|
+
- app/jobs/disco_app/concerns/synchronise_carrier_services_job.rb
|
281
282
|
- app/jobs/disco_app/concerns/synchronise_webhooks_job.rb
|
282
283
|
- app/jobs/disco_app/shop_job.rb
|
283
284
|
- app/jobs/disco_app/shop_update_job.rb
|
285
|
+
- app/jobs/disco_app/synchronise_carrier_services_job.rb
|
284
286
|
- app/jobs/disco_app/synchronise_webhooks_job.rb
|
285
287
|
- app/models/disco_app/concerns/plan.rb
|
286
288
|
- app/models/disco_app/concerns/shop.rb
|
@@ -331,6 +333,7 @@ files:
|
|
331
333
|
- lib/generators/disco_app/templates/initializers/shopify_session_repository.rb
|
332
334
|
- lib/generators/disco_app/templates/root/Procfile
|
333
335
|
- lib/generators/disco_app/templates/views/home/index.html.erb
|
336
|
+
- lib/tasks/carrier_services.rake
|
334
337
|
- lib/tasks/start.rake
|
335
338
|
- lib/tasks/webhooks.rake
|
336
339
|
- test/controllers/disco_app/install_controller_test.rb
|
@@ -379,6 +382,7 @@ files:
|
|
379
382
|
- test/dummy/public/500.html
|
380
383
|
- test/dummy/public/favicon.ico
|
381
384
|
- test/fixtures/api/widget_store/shop.json
|
385
|
+
- test/fixtures/api/widget_store/webhooks.json
|
382
386
|
- test/fixtures/disco_app/plans.yml
|
383
387
|
- test/fixtures/disco_app/shops.yml
|
384
388
|
- test/fixtures/disco_app/subscriptions.yml
|
@@ -458,6 +462,7 @@ test_files:
|
|
458
462
|
- test/dummy/config/boot.rb
|
459
463
|
- test/dummy/config/database.yml
|
460
464
|
- test/dummy/config/application.rb
|
465
|
+
- test/fixtures/api/widget_store/webhooks.json
|
461
466
|
- test/fixtures/api/widget_store/shop.json
|
462
467
|
- test/fixtures/disco_app/shops.yml
|
463
468
|
- test/fixtures/disco_app/subscriptions.yml
|