Sha256: 7def8404cece7356709b04f676d4c57571a692d72b99c2212a254d1bc4630948

Contents?: true

Size: 789 Bytes

Versions: 9

Compression:

Stored size: 789 Bytes

Contents

# encoding: utf-8

require 'faraday'
require 'base64'

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

      # @api private
      def initialize(app, *args)
        @app    = app
        @auth   = nil
        options = args.extract_options!

        if options.key?(:login) && !options[:login].nil?
          credentials = "#{options[:login]}:#{options[:password]}"
          @auth = Base64.encode64(credentials)
          @auth.gsub!("\n", "")
        end
      end

      # Update request headers
      #
      # @api private
      def call(env)
        if @auth
          env[:request_headers].merge!('Authorization' => "Basic #{@auth}\"")
        end

        @app.call(env)
      end
    end # BasicAuth
  end # Request
end # Github

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
github_api-0.18.1 lib/github_api/request/basic_auth.rb
github_api-0.17.0 lib/github_api/request/basic_auth.rb
github_api-0.16.0 lib/github_api/request/basic_auth.rb
github_api-0.15.0 lib/github_api/request/basic_auth.rb
github_api-0.14.5 lib/github_api/request/basic_auth.rb
github_api-0.14.4 lib/github_api/request/basic_auth.rb
github_api-0.14.3 lib/github_api/request/basic_auth.rb
github_api-0.14.2 lib/github_api/request/basic_auth.rb
github_api-0.14.1 lib/github_api/request/basic_auth.rb