Sha256: 6b8cc7b292d01de2bff2f052ee82a30d39ea852733bfb177d18d4d1d8a640a45

Contents?: true

Size: 1.09 KB

Versions: 5

Compression:

Stored size: 1.09 KB

Contents

require 'faraday_middleware'
require 'her'

require 'rancher/api/configuration'
require 'rancher/api/middlewares'
require 'rancher/api/version'
require 'rancher/api/logger'

module Rancher
  module Api
    class << self
      attr_writer :configuration
    end

    def self.setup!
      configure do |_x|
      end
    end

    def self.configuration
      @configuration ||= Configuration.new
    end

    def self.reset
      @configuration = Configuration.new
    end

    def self.configure
      yield(configuration)

      api = Her::API.setup url: configuration.url do |c|
        # Request
        c.request :json

        c.use Her::Middleware::AcceptJSON
        c.use Faraday::Request::BasicAuthentication, configuration.access_key, configuration.secret_key

        # Response
        c.use Rancher::Api::JsonParserMiddleware
        c.use Her::Middleware::DefaultParseJSON
        c.use Faraday::Response::Logger, ActiveSupport::Logger.new(STDOUT) if configuration.verbose

        # Adapter
        c.use Faraday::Adapter::NetHttp
      end

      require 'rancher/api/models'
      api
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rancher-api-0.7.0 lib/rancher/api.rb
rancher-api-0.6.0 lib/rancher/api.rb
rancher-api-0.5.2 lib/rancher/api.rb
rancher-api-0.5.1 lib/rancher/api.rb
rancher-api-0.5.0 lib/rancher/api.rb