Sha256: ef97fe4fc29eee515d6cbf3426d1e531f5e6c0928c7f03a09f1b350b28111745

Contents?: true

Size: 1.55 KB

Versions: 10

Compression:

Stored size: 1.55 KB

Contents

require 'locomotive/coal'

module Locomotive::Wagon

  module ApiConcern

    # Instance of the API client to request an account or his/her list of sites.
    def api_client
      @api_client ||= Locomotive::Coal::Client.new(api_uri, api_credentials)
    end

    # Instance of the API client to request resources of a site: pages, theme_assets, ...etc.
    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

    alias :build_api_site_client :api_site_client

    # 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
    #
    def api_host
      uri = api_uri
      host, port = uri.host, uri.port

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

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

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

    private

    def api_uri
      if (self.platform_url =~ /^https?:\/\//).nil?
        self.platform_url = 'http://' + self.platform_url
      end

      URI(platform_url)
    end

  end

end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
locomotivecms_wagon-3.2.0.alpha2 lib/locomotive/wagon/commands/concerns/api_concern.rb
locomotivecms_wagon-3.2.0.alpha1 lib/locomotive/wagon/commands/concerns/api_concern.rb
locomotivecms_wagon-3.1.1 lib/locomotive/wagon/commands/concerns/api_concern.rb
locomotivecms_wagon-3.1.0 lib/locomotive/wagon/commands/concerns/api_concern.rb
locomotivecms_wagon-3.1.0.beta1 lib/locomotive/wagon/commands/concerns/api_concern.rb
locomotivecms_wagon-3.0.5 lib/locomotive/wagon/commands/concerns/api_concern.rb
locomotivecms_wagon-3.0.4 lib/locomotive/wagon/commands/concerns/api_concern.rb
locomotivecms_wagon-3.0.3 lib/locomotive/wagon/commands/concerns/api_concern.rb
locomotivecms_wagon-3.0.2 lib/locomotive/wagon/commands/concerns/api_concern.rb
locomotivecms_wagon-3.0.0 lib/locomotive/wagon/commands/concerns/api_concern.rb