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-app-cli/help/start-app/'

Instance Method Summary collapse

Methods inherited from ShopifyCli::Task

call

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
# 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: [OAuth::REDIRECT_HOST]
  )

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

  resp["data"]["appCreate"]["app"]
end