Sha256: f1b3f9524888605f7a2d4140884cd79b3717a0b0eeb87bd3a1a334ffecadacc1

Contents?: true

Size: 1.15 KB

Versions: 11

Compression:

Stored size: 1.15 KB

Contents

require "shopify_cli"

module ShopifyCli
  module Tasks
    class CreateApiClient < ShopifyCli::Task
      VALID_APP_TYPES = %w(public custom)
      DEFAULT_APP_URL = "https://shopify.github.io/shopify-app-cli/help/start-app/"

      def call(ctx, org_id:, title:, type:)
        resp = ShopifyCli::PartnersAPI.query(
          ctx,
          "create_app",
          org: org_id.to_i,
          title: title,
          type: type,
          app_url: DEFAULT_APP_URL,
          redir: [OAuth::REDIRECT_HOST]
        )

        unless resp
          ctx.abort("Error - empty response")
        end

        errors = resp.dig("errors")
        if !errors.nil? && errors.any?
          ctx.abort(errors.map { |err| "#{err["field"]} #{err["message"]}" }.join(", "))
        end

        user_errors = resp.dig("data", "appCreate", "userErrors")
        if !user_errors.nil? && user_errors.any?
          ctx.abort(user_errors.map { |err| "#{err["field"]} #{err["message"]}" }.join(", "))
        end

        ShopifyCli::Core::Monorail.metadata[:api_key] = resp.dig("data", "appCreate", "app", "apiKey")

        resp.dig("data", "appCreate", "app")
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
shopify-cli-1.14.0 lib/shopify-cli/tasks/create_api_client.rb
shopify-cli-1.13.1 lib/shopify-cli/tasks/create_api_client.rb
shopify-cli-1.13.0 lib/shopify-cli/tasks/create_api_client.rb
shopify-cli-1.12.0 lib/shopify-cli/tasks/create_api_client.rb
shopify-cli-1.11.0 lib/shopify-cli/tasks/create_api_client.rb
shopify-cli-1.10.0 lib/shopify-cli/tasks/create_api_client.rb
shopify-cli-1.9.1 lib/shopify-cli/tasks/create_api_client.rb
shopify-cli-1.9.0 lib/shopify-cli/tasks/create_api_client.rb
shopify-cli-1.8.0 lib/shopify-cli/tasks/create_api_client.rb
shopify-cli-1.7.1 lib/shopify-cli/tasks/create_api_client.rb
shopify-cli-1.7.0 lib/shopify-cli/tasks/create_api_client.rb