Class: BitBucket::Request::BasicAuth

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

Instance Method Summary collapse

Constructor Details

#initialize(app, *args) ⇒ BasicAuth

Returns a new instance of BasicAuth.



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/bitbucket_rest_api/request/basic_auth.rb', line 17

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

Instance Method Details

#call(env) ⇒ Object



11
12
13
14
15
# File 'lib/bitbucket_rest_api/request/basic_auth.rb', line 11

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

  @app.call env
end