Sha256: 476a77cc3e10602b7094fd03465600ca6acf1ab28beb0564324c4701c2743037

Contents?: true

Size: 795 Bytes

Versions: 5

Compression:

Stored size: 795 Bytes

Contents

# encoding: utf-8

require 'faraday'
require 'base64'

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

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

        @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 # BitBucket

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
codenamev_bitbucket_api-0.4.1 lib/bitbucket_rest_api/request/basic_auth.rb
codenamev_bitbucket_api-0.4.0 lib/bitbucket_rest_api/request/basic_auth.rb
reenhanced_bitbucket_api-0.3.2 lib/bitbucket_rest_api/request/basic_auth.rb
reenhanced_bitbucket_api-0.3.1 lib/bitbucket_rest_api/request/basic_auth.rb
reenhanced_bitbucket_api-0.3.0 lib/bitbucket_rest_api/request/basic_auth.rb