Sha256: 73b40f520716cc4bf1975d416e8818374c63f457eb450438bbb5bed02a4a3802

Contents?: true

Size: 1008 Bytes

Versions: 1

Compression:

Stored size: 1008 Bytes

Contents

module ApiClient
  # ApiClient::Configuration provides a way to configure ApiClient globally.
  class Configuration
    attr_accessor :mock
    attr_reader :header

    # Return the api url.
    #
    # @return [String] the api url.
    def path
      raise Exceptions::NotConfigured unless @path.size > 1
      @path
    end

    # Set the api url.
    #
    # @param [String] path api url.
    def path=(path)
      path = "#{path}/" unless path[path.size - 1, 1] == '/'
      @path = path
    end

    # Set the default params of header.
    #
    # @param [Hash] header the default header for requisitions.
    def header=(header = {})
      @header = { 'Content-Type' => 'application/json' }.merge(header)
    end

    # Set a basic authentication for all requisitions.
    #
    # @param [Hash] header the default header for requisitions.
    def basic_auth(account, password)
      @header.merge!({ 'Authorization' => "Basic #{["#{account}:#{password}"].pack('m').delete("\r\n")}" })
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
api-client-2.3.0 lib/api-client/configuration.rb