Sha256: 21d8eaf98e26b2c19f38e059aa0f739049211319445a71d331e0e5aec1efe909

Contents?: true

Size: 789 Bytes

Versions: 7

Compression:

Stored size: 789 Bytes

Contents

# encoding: utf-8

require 'faraday'
require 'base64'

module Github
  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 # Github

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
github_api-0.14.0 lib/github_api/request/basic_auth.rb
github_api-0.13.1 lib/github_api/request/basic_auth.rb
github_api-0.13.0 lib/github_api/request/basic_auth.rb
github_api-0.12.4 lib/github_api/request/basic_auth.rb
github_api-0.12.3 lib/github_api/request/basic_auth.rb
github_api-0.12.2 lib/github_api/request/basic_auth.rb
github_api-0.12.1 lib/github_api/request/basic_auth.rb