Class: Github::Request::BasicAuth

Inherits:
Faraday::Middleware
  • Object
show all
Defined in:
lib/github_api/request/basic_auth.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, *args) ⇒ BasicAuth

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of BasicAuth.

API:

  • private



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/github_api/request/basic_auth.rb', line 12

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

Instance Method Details

#call(env) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Update request headers

API:

  • private



27
28
29
30
31
32
33
# File 'lib/github_api/request/basic_auth.rb', line 27

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

  @app.call(env)
end