Class: ShopifyCLI::Services::App::Create::RailsService

Inherits:
BaseService
  • Object
show all
Defined in:
lib/shopify_cli/services/app/create/rails_service.rb

Constant Summary collapse

USER_AGENT_CODE =
<<~USERAGENT
  module ShopifyAPI
    class Base < ActiveResource::Base
      self.headers['User-Agent'] << " | ShopifyApp/\#{ShopifyApp::VERSION} | Shopify CLI"
    end
  end
USERAGENT
DEFAULT_RAILS_FLAGS =
%w(--skip-spring)

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BaseService

call

Constructor Details

#initialize(name:, organization_id:, store_domain:, type:, db:, rails_opts:, context:) ⇒ RailsService

Returns a new instance of RailsService.



20
21
22
23
24
25
26
27
28
29
# File 'lib/shopify_cli/services/app/create/rails_service.rb', line 20

def initialize(name:, organization_id:, store_domain:, type:, db:, rails_opts:, context:)
  @name = name
  @organization_id = organization_id
  @store_domain = store_domain
  @type = type
  @db = db
  @rails_opts = rails_opts
  @context = context
  super()
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



18
19
20
# File 'lib/shopify_cli/services/app/create/rails_service.rb', line 18

def context
  @context
end

#dbObject (readonly)

Returns the value of attribute db.



18
19
20
# File 'lib/shopify_cli/services/app/create/rails_service.rb', line 18

def db
  @db
end

#nameObject (readonly)

Returns the value of attribute name.



18
19
20
# File 'lib/shopify_cli/services/app/create/rails_service.rb', line 18

def name
  @name
end

#organization_idObject (readonly)

Returns the value of attribute organization_id.



18
19
20
# File 'lib/shopify_cli/services/app/create/rails_service.rb', line 18

def organization_id
  @organization_id
end

#rails_optsObject (readonly)

Returns the value of attribute rails_opts.



18
19
20
# File 'lib/shopify_cli/services/app/create/rails_service.rb', line 18

def rails_opts
  @rails_opts
end

#store_domainObject (readonly)

Returns the value of attribute store_domain.



18
19
20
# File 'lib/shopify_cli/services/app/create/rails_service.rb', line 18

def store_domain
  @store_domain
end

#typeObject (readonly)

Returns the value of attribute type.



18
19
20
# File 'lib/shopify_cli/services/app/create/rails_service.rb', line 18

def type
  @type
end

Instance Method Details

#callObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/shopify_cli/services/app/create/rails_service.rb', line 31

def call
  form_options = {
    name: name,
    organization_id: organization_id,
    shop_domain: store_domain,
    type: type,
  }
  form_options[:db] = db unless db.nil?
  form_options[:rails_opts] = rails_opts unless rails_opts.nil?
  form = form_data(form_options)

  raise ShopifyCLI::AbortSilent if form.nil?

  check_dependencies

  build(form.name, form.db)
  set_custom_ua
  ShopifyCLI::Project.write(
    context,
    project_type: "rails",
    organization_id: form.organization_id,
  )

  api_client = if ShopifyCLI::Environment.acceptance_test?
    {
      "apiKey" => "public_api_key",
      "apiSecretKeys" => [
        {
          "secret" => "api_secret_key",
        },
      ],
    }
  else
    ShopifyCLI::Tasks::CreateApiClient.call(
      context,
      org_id: form.organization_id,
      title: form.name,
      type: form.type,
    )
  end

  ShopifyCLI::Resources::EnvFile.new(
    api_key: api_client["apiKey"],
    secret: api_client["apiSecretKeys"].first["secret"],
    shop: form.shop_domain,
    scopes: "write_products,write_customers,write_draft_orders",
  ).write(context)

  partners_url = ShopifyCLI::PartnersAPI.partners_url_for(form.organization_id, api_client["id"])

  context.puts(context.message("apps.create.info.created", form.name, partners_url))
  context.puts(context.message("apps.create.info.serve", form.name, ShopifyCLI::TOOL_NAME))
  unless ShopifyCLI::Shopifolk.acting_as_shopify_organization?
    context.puts(context.message("apps.create.info.install", partners_url, form.name))
  end
end