Sha256: df2b19291daa87689b5b87098d3ad30147ae51beb11eb3ddf606dbceb39456de

Contents?: true

Size: 759 Bytes

Versions: 25

Compression:

Stored size: 759 Bytes

Contents

# encoding: utf-8

require 'faraday'
require 'base64'

module Github
  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.last.is_a?(Hash) ? args.pop : {}
        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

25 entries across 25 versions & 1 rubygems

Version Path
github_api-0.5.3 lib/github_api/request/basic_auth.rb
github_api-0.5.2 lib/github_api/request/basic_auth.rb
github_api-0.5.1 lib/github_api/request/basic_auth.rb
github_api-0.5.0 lib/github_api/request/basic_auth.rb
github_api-0.5.0.rc1 lib/github_api/request/basic_auth.rb
github_api-0.4.11 lib/github_api/request/basic_auth.rb
github_api-0.4.10 lib/github_api/request/basic_auth.rb
github_api-0.4.9 lib/github_api/request/basic_auth.rb
github_api-0.4.8 lib/github_api/request/basic_auth.rb
github_api-0.4.7 lib/github_api/request/basic_auth.rb
github_api-0.4.6 lib/github_api/request/basic_auth.rb
github_api-0.4.5 lib/github_api/request/basic_auth.rb
github_api-0.4.4 lib/github_api/request/basic_auth.rb
github_api-0.4.3 lib/github_api/request/basic_auth.rb
github_api-0.4.2 lib/github_api/request/basic_auth.rb
github_api-0.4.1 lib/github_api/request/basic_auth.rb
github_api-0.4.0 lib/github_api/request/basic_auth.rb
github_api-0.3.9 lib/github_api/request/basic_auth.rb
github_api-0.3.8 lib/github_api/request/basic_auth.rb
github_api-0.3.7 lib/github_api/request/basic_auth.rb