Class: ShopifyCLI::Tasks::CreateApiClient

Inherits:
ShopifyCLI::Task show all
Defined in:
lib/shopify_cli/tasks/create_api_client.rb

Constant Summary collapse

VALID_APP_TYPES =
%w(public custom)
DEFAULT_APP_URL =
"https://shopify.github.io/shopify-cli/help/start-app/"

Instance Method Summary collapse

Instance Method Details

#call(ctx, org_id:, title:, type:) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/shopify_cli/tasks/create_api_client.rb', line 9

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: [IdentityAuth::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.[:api_key] = resp.dig("data", "appCreate", "app", "apiKey")

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