Sha256: 48d48fe179d79e4d68aa93f84e01f4d6b1dfd1a136dd4af4a89df92ab8cc125f

Contents?: true

Size: 1.57 KB

Versions: 11

Compression:

Stored size: 1.57 KB

Contents

require "shopify_cli"
require "json"
module Rails
  module Commands
    class Generate
      class Webhook < ShopifyCli::SubCommand
        def call(args, _name)
          selected_type = args.first
          schema = ShopifyCli::AdminAPI::Schema.get(@ctx)
          webhooks = schema.get_names_from_type("WebhookSubscriptionTopic")
          unless selected_type && webhooks.include?(selected_type)
            selected_type = CLI::UI::Prompt.ask(@ctx.message("rails.generate.webhook.select")) do |handler|
              webhooks.each do |type|
                handler.option(type) { type }
              end
            end
          end
          spin_group = CLI::UI::SpinGroup.new
          spin_group.add(@ctx.message("rails.generate.webhook.selected", selected_type)) do |spinner|
            Rails::Commands::Generate.run_generate(generate_command(selected_type), selected_type, @ctx)
            spinner.update_title("{{green:#{selected_type}}} config/initializers/shopify_app.rb")
          end
          spin_group.wait
        end

        def self.help
          ShopifyCli::Context.message("rails.generate.webhook.help", ShopifyCli::TOOL_NAME)
        end

        def generate_command(selected_type)
          parts = selected_type.downcase.split("_")
          host = ShopifyCli::Project.current.env.host
          selected_type = parts[0..-2].join("_") + "/" + parts[-1]
          command = @ctx.windows? ? "ruby bin\\rails" : "bin/rails"
          "#{command} g shopify_app:add_webhook -t #{selected_type} -a #{host}/webhooks/#{selected_type.downcase}"
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
shopify-cli-1.14.0 lib/project_types/rails/commands/generate/webhook.rb
shopify-cli-1.13.1 lib/project_types/rails/commands/generate/webhook.rb
shopify-cli-1.13.0 lib/project_types/rails/commands/generate/webhook.rb
shopify-cli-1.12.0 lib/project_types/rails/commands/generate/webhook.rb
shopify-cli-1.11.0 lib/project_types/rails/commands/generate/webhook.rb
shopify-cli-1.10.0 lib/project_types/rails/commands/generate/webhook.rb
shopify-cli-1.9.1 lib/project_types/rails/commands/generate/webhook.rb
shopify-cli-1.9.0 lib/project_types/rails/commands/generate/webhook.rb
shopify-cli-1.8.0 lib/project_types/rails/commands/generate/webhook.rb
shopify-cli-1.7.1 lib/project_types/rails/commands/generate/webhook.rb
shopify-cli-1.7.0 lib/project_types/rails/commands/generate/webhook.rb