Class: ShopifyCLI::Tasks::EnsureLoopbackURL

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

Instance Method Summary collapse

Instance Method Details

#call(ctx) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/shopify_cli/tasks/ensure_loopback_url.rb', line 4

def call(ctx)
  @ctx = ctx
  api_key = Project.current.env.api_key
  result = ShopifyCLI::PartnersAPI.query(ctx, "get_app_urls", apiKey: api_key)
  loopback = IdentityAuth::REDIRECT_HOST
  app = result["data"]["app"]
  urls = app["redirectUrlWhitelist"]
  if urls.grep(/#{loopback}/).empty?
    with_loopback = urls.push(loopback)
    ShopifyCLI::PartnersAPI.query(@ctx, "update_dashboard_urls", input: {
      redirectUrlWhitelist: with_loopback, apiKey: api_key
    })
  end
end