Class: Flattr::Request::FlattrOAuth2

Inherits:
Faraday::Middleware
  • Object
show all
Defined in:
lib/flattr/request/oauth2.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, options) ⇒ FlattrOAuth2

Returns a new instance of FlattrOAuth2.



12
13
14
# File 'lib/flattr/request/oauth2.rb', line 12

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

Instance Method Details

#authorization_headerObject



16
17
18
19
20
21
22
23
24
# File 'lib/flattr/request/oauth2.rb', line 16

def authorization_header
  if @options[:access_token]
    "Bearer #{@options[:access_token]}"
  elsif @options[:client_id] && @options[:client_secret]
    "Basic #{Flattr::Client.base64_encode("#{@options[:client_id]}:#{@options[:client_secret]}")}"
  else
    nil
  end
end

#call(env) ⇒ Object



5
6
7
8
9
10
# File 'lib/flattr/request/oauth2.rb', line 5

def call(env)
  if authorization_header
    env[:request_headers]['Authorization'] = authorization_header
  end
  @app.call(env)
end