Class: Dropmark::Authentication

Inherits:
Faraday::Middleware
  • Object
show all
Defined in:
lib/dropmark/authentication.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ Authentication

Returns a new instance of Authentication.



6
7
8
9
# File 'lib/dropmark/authentication.rb', line 6

def initialize(app, options={})
  @app = app
  @options = options
end

Instance Method Details

#call(env) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/dropmark/authentication.rb', line 11

def call(env)
  if Dropmark.user_id
    basic_auth = Base64.encode64([Dropmark.user_id, Dropmark.user_token].join(':')).to_s.gsub!("\n", '')
    env[:request_headers]["Authorization"] = "Basic #{basic_auth}"
  end
  env[:request_headers]["X-API-Key"] = Dropmark.api_key
  @app.call(env)
end