Module: Locomotive::Wagon::ApiConcern

Included in:
AuthenticateCommand, DeleteCommand, PullCommand, PushCommand, SyncCommand
Defined in:
lib/locomotive/wagon/commands/concerns/api_concern.rb

Instance Method Summary collapse

Instance Method Details

#api_clientObject

Instance of the API client to request an account or his/her list of sites.



8
9
10
# File 'lib/locomotive/wagon/commands/concerns/api_concern.rb', line 8

def api_client
  @api_client ||= Locomotive::Coal::Client.new(api_uri, api_credentials)
end

#api_credentialsObject



40
41
42
43
44
45
46
# File 'lib/locomotive/wagon/commands/concerns/api_concern.rb', line 40

def api_credentials
  if respond_to?(:email)
    { email: email, password: password }
  elsif respond_to?(:credentials)
    credentials
  end
end

#api_hostObject

Host (+ port) extracted from the platform_url instance variable. If port equals 80, do not add it to the host.

Examples:

www.myengine.com
localhost:3000


33
34
35
36
37
38
# File 'lib/locomotive/wagon/commands/concerns/api_concern.rb', line 33

def api_host
  uri = api_uri
  host, port = uri.host, uri.port

  port == 80 ? uri.host : "#{uri.host}:#{uri.port}"
end

#api_site_client(connection) ⇒ Object Also known as: build_api_site_client

Instance of the API client to request resources of a site: pages, theme_assets, …etc.



13
14
15
16
17
18
19
20
21
# File 'lib/locomotive/wagon/commands/concerns/api_concern.rb', line 13

def api_site_client(connection)
  return if connection.nil?
  return @api_site_client if @api_site_client

  _host, _credentials = connection['host'], connection.slice('email', 'api_key', 'password')
  _options = connection.slice('ssl', 'handle')

  @api_site_client = Locomotive::Coal::Client.new(_host, _credentials, _options)
end

#connection_information_from_env_and_pathObject



48
49
50
# File 'lib/locomotive/wagon/commands/concerns/api_concern.rb', line 48

def connection_information_from_env_and_path
  read_deploy_settings(self.env, self.path)
end