Class: Psc::Faraday::HttpBasic

Inherits:
Object
  • Object
show all
Defined in:
lib/psc/faraday/http_basic.rb

Overview

Faraday middleware that implements HTTP Basic. This is not PSC-specific, and Faraday even includes HTTP Basic support, but Faraday's support is not implemented as middleware. Using middleware makes setting up a connection based on the :authenticator option cleaner.

Instance Method Summary collapse

Constructor Details

#initialize(app, username, password) ⇒ HttpBasic

Create an instance of the middleware.

Parameters:

  • app (#call)
  • username (String)
  • password (String)


21
22
23
24
# File 'lib/psc/faraday/http_basic.rb', line 21

def initialize(app, username, password)
  @app = app
  @header_value = "Basic #{Base64.encode64([username, password].join(':')).strip}"
end

Instance Method Details

#call(env) ⇒ Object

Sets the Authorization request header using the HTTP Basic scheme.



29
30
31
32
33
# File 'lib/psc/faraday/http_basic.rb', line 29

def call(env)
  env[:request_headers]['Authorization'] = @header_value

  @app.call(env)
end