disco_app 0.6.6 → 0.6.7

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: aa5a75b03995277ab80d6bd150044085e1f7c7fad16340838ee717d292fcf38e
4
- data.tar.gz: 218728b186a4210cf8f3411f8272b049eca6936f3ab123b82560b72b71634bc3
3
+ metadata.gz: '06960bd40f8d13cfc0976f62ef2dad843f3d6ce3fd6360fe3d39decf27474ffa'
4
+ data.tar.gz: c7629e5dc53f093f18f7336bb1e56b19317da51a15c35831dbe5622c454d92b5
5
5
  SHA512:
6
- metadata.gz: 748b9644cd88061e016a169438bb8ad318f41d587fb67ee8a001f02632cccb108e3cc7ff3d613d0efd75557d1c6bcf8a3e4aa81851ba8b8a25a8efff9de959e9
7
- data.tar.gz: 93e97fbd2f46744b30babe64fe32ae1f94a328af7aef7952883734915919ea14cd884988cc862afdeaa9931bfc2af452aed13f34e2d5cbd0a73604473bba1a5f
6
+ metadata.gz: 94a757245376dc817637b122fe6e6d0d89f8a983ed38cd51ada10d46348d5fb35082c20f54da371eb9ac95689701c3558024fdf673257f6424f4643310a5d64e
7
+ data.tar.gz: 56c7869198c5eb5074336694b8e2b3d0c1963f46314859486f2310bba201a80b03257a427afcf59c9713d727b5c4dd0ad34850e2dcc7e492785da3365a63b74f
@@ -10,12 +10,12 @@ module DiscoApp::Concerns::AppInstalledJob
10
10
  # Perform application installation.
11
11
  #
12
12
  # - Synchronise webhooks.
13
- # - Synchronise carrier services.
13
+ # - Synchronise carrier service, if required.
14
14
  # - Perform initial update of shop information.
15
15
  #
16
16
  def perform(domain)
17
17
  DiscoApp::SynchroniseWebhooksJob.perform_now(domain)
18
- DiscoApp::SynchroniseCarrierServicesJob.perform_now(domain)
18
+ DiscoApp::SynchroniseCarrierServiceJob.perform_now(domain)
19
19
  DiscoApp::ShopUpdateJob.perform_now(domain)
20
20
  end
21
21
 
@@ -0,0 +1,51 @@
1
+ module DiscoApp::Concerns::SynchroniseCarrierServiceJob
2
+ extend ActiveSupport::Concern
3
+
4
+ # Ensure that any carrier service required by our app is registered.
5
+ def perform(shopify_domain)
6
+ # Don't proceed unless we have a name and callback url.
7
+ return unless carrier_service_name and callback_url
8
+
9
+ # Don't proceed if the carrier service is already registered.
10
+ return if current_carrier_service_names.include?(carrier_service_name)
11
+
12
+ # Otherwise, register the carrier service.
13
+ ShopifyAPI::CarrierService.create(
14
+ name: carrier_service_name,
15
+ callback_url: callback_url,
16
+ service_discovery: true,
17
+ format: 'json'
18
+ )
19
+
20
+ # De-activate and extraneous carrier services.
21
+ current_carrier_services.each do |carrier_service|
22
+ unless carrier_service.name == carrier_service_name
23
+ carrier_service.active = false
24
+ carrier_service.save
25
+ end
26
+ end
27
+ end
28
+
29
+ protected
30
+
31
+ def carrier_service_name
32
+ Rails.application.config.x.shopify_app_name
33
+ end
34
+
35
+ def callback_url
36
+ nil
37
+ end
38
+
39
+ private
40
+
41
+ # Return a list of currently registered callback URLs.
42
+ def current_carrier_service_names
43
+ current_carrier_services.map(&:name)
44
+ end
45
+
46
+ # Return a list of currently registered carrier services.
47
+ def current_carrier_services
48
+ @current_carrier_service ||= ShopifyAPI::CarrierService.find(:all)
49
+ end
50
+
51
+ end
@@ -0,0 +1,3 @@
1
+ class DiscoApp::SynchroniseCarrierServiceJob < DiscoApp::ShopJob
2
+ include DiscoApp::Concerns::SynchroniseCarrierServiceJob
3
+ end
@@ -1,3 +1,3 @@
1
1
  module DiscoApp
2
- VERSION = "0.6.6"
2
+ VERSION = "0.6.7"
3
3
  end
@@ -0,0 +1,10 @@
1
+ namespace :carrier_service do
2
+
3
+ desc 'Synchronise carrier service across all installed shops.'
4
+ task sync: :environment do
5
+ DiscoApp::Shop.installed.has_active_shopify_plan.each do |shop|
6
+ DiscoApp::SynchroniseCarrierServiceJob.perform_later(shop.shopify_domain)
7
+ end
8
+ end
9
+
10
+ end
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.6
4
+ version: 0.6.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gavin Ballard
@@ -278,11 +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
+ - app/jobs/disco_app/concerns/synchronise_carrier_service_job.rb
282
282
  - app/jobs/disco_app/concerns/synchronise_webhooks_job.rb
283
283
  - app/jobs/disco_app/shop_job.rb
284
284
  - app/jobs/disco_app/shop_update_job.rb
285
- - app/jobs/disco_app/synchronise_carrier_services_job.rb
285
+ - app/jobs/disco_app/synchronise_carrier_service_job.rb
286
286
  - app/jobs/disco_app/synchronise_webhooks_job.rb
287
287
  - app/models/disco_app/concerns/plan.rb
288
288
  - app/models/disco_app/concerns/shop.rb
@@ -333,7 +333,7 @@ files:
333
333
  - lib/generators/disco_app/templates/initializers/shopify_session_repository.rb
334
334
  - lib/generators/disco_app/templates/root/Procfile
335
335
  - lib/generators/disco_app/templates/views/home/index.html.erb
336
- - lib/tasks/carrier_services.rake
336
+ - lib/tasks/carrier_service.rake
337
337
  - lib/tasks/start.rake
338
338
  - lib/tasks/webhooks.rake
339
339
  - test/controllers/disco_app/install_controller_test.rb
@@ -1,47 +0,0 @@
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
@@ -1,3 +0,0 @@
1
- class DiscoApp::SynchroniseCarrierServicesJob < DiscoApp::ShopJob
2
- include DiscoApp::Concerns::SynchroniseCarrierServicesJob
3
- end
@@ -1,10 +0,0 @@
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