Class: ShopifyCLI::Connect

Inherits:
Object
  • Object
show all
Defined in:
lib/shopify_cli/connect.rb

Instance Method Summary collapse

Constructor Details

#initialize(ctx) ⇒ Connect

Returns a new instance of Connect.



5
6
7
# File 'lib/shopify_cli/connect.rb', line 5

def initialize(ctx)
  @ctx = ctx
end

Instance Method Details

#default_connect(project_type) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/shopify_cli/connect.rb', line 9

def default_connect(project_type)
  if Project.current&.env
    @ctx.puts(@ctx.message("core.connect.already_connected_warning"))
  end
  org = ShopifyCLI::Tasks::EnsureEnv.call(@ctx, regenerate: true)
  write_cli_yml(project_type, org["id"]) unless Project.has_current?
  api_key = Project.current(force_reload: true).env["api_key"]
  get_app(org["apps"], api_key).first["title"]
end

#get_app(apps, api_key) ⇒ Object



28
29
30
# File 'lib/shopify_cli/connect.rb', line 28

def get_app(apps, api_key)
  apps.select { |app| app["apiKey"] == api_key }
end

#write_cli_yml(project_type, org_id) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/shopify_cli/connect.rb', line 19

def write_cli_yml(project_type, org_id)
  ShopifyCLI::Project.write(
    @ctx,
    project_type: project_type,
    organization_id: org_id,
  )
  @ctx.done(@ctx.message("core.connect.cli_yml_saved"))
end