Class: ShopifyCLI::Tasks::UpdateDashboardURLS
- Inherits:
-
ShopifyCLI::Task
- Object
- ShopifyCLI::Task
- ShopifyCLI::Tasks::UpdateDashboardURLS
- Defined in:
- lib/shopify_cli/tasks/update_dashboard_urls.rb
Constant Summary collapse
- NGROK_REGEX =
/https:\/\/([a-z0-9\-]+\.ngrok\.io)(.*)/
Instance Method Summary collapse
- #call(ctx, url:, callback_urls:) ⇒ Object
- #construct_redirect_urls(urls, new_url, callback_urls) ⇒ Object
Instance Method Details
#call(ctx, url:, callback_urls:) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/shopify_cli/tasks/update_dashboard_urls.rb', line 8 def call(ctx, url:, callback_urls:) @ctx = ctx project = ShopifyCLI::Project.current api_key = project.env.api_key result = ShopifyCLI::PartnersAPI.query(ctx, "get_app_urls", apiKey: api_key) app = result["data"]["app"] constructed_urls = construct_redirect_urls(app["redirectUrlWhitelist"], url, callback_urls) return if already_updated(app, constructed_urls, url) ShopifyCLI::PartnersAPI.query(@ctx, "update_dashboard_urls", input: { applicationUrl: url, redirectUrlWhitelist: constructed_urls, apiKey: api_key, }) @ctx.puts(@ctx.("core.tasks.update_dashboard_urls.updated")) rescue @ctx.puts(@ctx.("core.tasks.update_dashboard_urls.update_error", ShopifyCLI::TOOL_NAME)) raise end |
#construct_redirect_urls(urls, new_url, callback_urls) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/shopify_cli/tasks/update_dashboard_urls.rb', line 31 def construct_redirect_urls(urls, new_url, callback_urls) new_urls = urls.map do |url| if (match = url.match(NGROK_REGEX)) "#{new_url}#{match[2]}" else url end end callback_urls.each do |callback_url| if new_urls.grep(/#{new_url}#{callback_url}/).empty? new_urls.push("#{new_url}#{callback_url}") end end new_urls.uniq end |