Sha256: ce1ded0b2c09c8cbb909608886643fdb0721ec5f7e42c38889fd5f34a4e4c076

Contents?: true

Size: 1.45 KB

Versions: 10

Compression:

Stored size: 1.45 KB

Contents

module DiscoApp::Concerns::SynchroniseCarrierServiceJob
  extend ActiveSupport::Concern

  # Ensure that any carrier service required by our app is registered.
  def perform(shopify_domain)
    # Don't proceed unless we have a name and callback url.
    return unless carrier_service_name and callback_url

    # Registered the carrier service if it hasn't been registered yet.
    unless current_carrier_service_names.include?(carrier_service_name)
      ShopifyAPI::CarrierService.create(
        name: carrier_service_name,
        callback_url: callback_url,
        service_discovery: true,
        format: :json
      )
    end

    # Ensure any existing carrier services (with the correct name) are active
    # and have a current callback URL.
    current_carrier_services.each do |carrier_service|
      if carrier_service.name == carrier_service_name
        carrier_service.callback_url = callback_url
        carrier_service.active = true
        carrier_service.save
      end
    end
  end

  protected

    def carrier_service_name
      DiscoApp.configuration.app_name
    end

    def callback_url
      nil
    end

  private

    # Return a list of currently registered carrier service names.
    def current_carrier_service_names
      current_carrier_services.map(&:name)
    end

    # Return a list of currently registered carrier services.
    def current_carrier_services
      @current_carrier_service ||= ShopifyAPI::CarrierService.find(:all)
    end

end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
disco_app-0.8.4 app/jobs/disco_app/concerns/synchronise_carrier_service_job.rb
disco_app-0.8.5 app/jobs/disco_app/concerns/synchronise_carrier_service_job.rb
disco_app-0.8.6 app/jobs/disco_app/concerns/synchronise_carrier_service_job.rb
disco_app-0.8.7 app/jobs/disco_app/concerns/synchronise_carrier_service_job.rb
disco_app-0.8.8 app/jobs/disco_app/concerns/synchronise_carrier_service_job.rb
disco_app-0.8.9 app/jobs/disco_app/concerns/synchronise_carrier_service_job.rb
disco_app-0.9.0 app/jobs/disco_app/concerns/synchronise_carrier_service_job.rb
disco_app-0.9.1 app/jobs/disco_app/concerns/synchronise_carrier_service_job.rb
disco_app-0.9.2 app/jobs/disco_app/concerns/synchronise_carrier_service_job.rb
disco_app-0.9.3 app/jobs/disco_app/concerns/synchronise_carrier_service_job.rb