Sha256: f78af5a4cfc19eb37e8faa2054424335864d7af7a89465940a6b303e97df273c

Contents?: true

Size: 741 Bytes

Versions: 20

Compression:

Stored size: 741 Bytes

Contents

# encoding: utf-8

require 'faraday'
require 'base64'

module Nimbu
  module Request
    class BasicAuth < Faraday::Middleware
      dependency 'base64'

      def call(env)
        env[:request_headers].merge!('Authorization' => "Basic #{@auth}\"")

        @app.call env
      end

      def initialize(app, *args)
        @app = app
        credentials = ""
        options = args.extract_options!
        if options.has_key? :login
          credentials = "#{options[:login]}:#{options[:password]}"
        elsif options.has_key? :basic_auth
          credentials = "#{options[:basic_auth]}"
        end
        @auth = Base64.encode64(credentials)
        @auth.gsub!("\n", "")
      end
    end # BasicAuth
  end # Request
end # Nimbu

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
nimbu-api-0.5.0 lib/nimbu-api/request/basic_auth.rb
nimbu-api-0.4.4 lib/nimbu-api/request/basic_auth.rb
nimbu-api-0.4.3 lib/nimbu-api/request/basic_auth.rb
nimbu-api-0.4.2 lib/nimbu-api/request/basic_auth.rb
nimbu-api-0.4.1 lib/nimbu-api/request/basic_auth.rb
nimbu-api-0.4.0 lib/nimbu-api/request/basic_auth.rb
nimbu-api-0.3.0 lib/nimbu-api/request/basic_auth.rb
nimbu-api-0.2.1 lib/nimbu-api/request/basic_auth.rb
nimbu-api-0.2 lib/nimbu-api/request/basic_auth.rb
nimbu-api-0.2.beta.3 lib/nimbu-api/request/basic_auth.rb
nimbu-api-0.2.beta.2 lib/nimbu-api/request/basic_auth.rb
nimbu-api-0.2.beta.1 lib/nimbu-api/request/basic_auth.rb
nimbu-api-0.2.beta lib/nimbu-api/request/basic_auth.rb
nimbu-api-0.1.5 lib/nimbu-api/request/basic_auth.rb
nimbu-api-0.1.4 lib/nimbu-api/request/basic_auth.rb
nimbu-api-0.1.3 lib/nimbu-api/request/basic_auth.rb
nimbu-api-0.1.1 lib/nimbu-api/request/basic_auth.rb
nimbu-api-0.1 lib/nimbu-api/request/basic_auth.rb
nimbu-api-0.0.2 lib/nimbu-api/request/basic_auth.rb
nimbu-api-0.0.1 lib/nimbu-api/request/basic_auth.rb