Sha256: d2e0028db07127e2ae4766a1c10574e33368f17b6723edc89ee6d92907bda225

Contents?: true

Size: 1.63 KB

Versions: 9

Compression:

Stored size: 1.63 KB

Contents

require "shopify_cli"
require "json"
module Rails
  class Command
    class Generate
      class Webhook
        class << self
          def start(ctx, args)
            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::Command::Generate.run_generate(generate_command(selected_type, ctx), selected_type, ctx)
              spinner.update_title("{{green:#{selected_type}}} config/initializers/shopify_app.rb")
            end
            spin_group.wait
          end

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

          def generate_command(selected_type, ctx)
            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
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
shopify-cli-2.4.0 lib/project_types/rails/commands/generate/webhook.rb
shopify-cli-2.3.0 lib/project_types/rails/commands/generate/webhook.rb
shopify-cli-2.2.2 lib/project_types/rails/commands/generate/webhook.rb
shopify-cli-2.2.1 lib/project_types/rails/commands/generate/webhook.rb
shopify-cli-2.2.0 lib/project_types/rails/commands/generate/webhook.rb
shopify-cli-2.1.0 lib/project_types/rails/commands/generate/webhook.rb
shopify-cli-2.0.2 lib/project_types/rails/commands/generate/webhook.rb
shopify-cli-2.0.1 lib/project_types/rails/commands/generate/webhook.rb
shopify-cli-2.0.0 lib/project_types/rails/commands/generate/webhook.rb