Sha256: 1354803b9035b382bc751a4cbdbf1cb8bf330cda7f5e543b310eb30f5c597141

Contents?: true

Size: 1.02 KB

Versions: 1

Compression:

Stored size: 1.02 KB

Contents

module DiscoApp
  class AppInstalledJob < DiscoApp::ShopJob

    before_enqueue { @shop.awaiting_install! }
    before_perform { @shop.installing! }
    after_perform { @shop.installed! }

    def perform(domain)

      # Install webhooks.
      (base_webhook_topics + webhook_topics).each do |topic|
        ShopifyAPI::Webhook.create(topic: topic, address: webhooks_url, format: 'json')
      end

      # Perform initial update of shop information.
      DiscoApp::ShopUpdateJob.perform_now(domain)

    end

    protected

      # Return a list of additional webhook topics to listen for.
      # This method should be overridden in the application.
      def webhook_topics
        []
      end

    private

      # Return a list of webhook topics that will always be set up for the application.
      def base_webhook_topics
        [:'app/uninstalled', :'shop/update']
      end

      # Return the absolute URL to the webhooks endpoint.
      def webhooks_url
        DiscoApp::Engine.routes.url_helpers.webhooks_url
      end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
disco_app-0.6.0 app/jobs/disco_app/app_installed_job.rb