Class: HttpClientGenerator::Plugs::SetBearerToken

Inherits:
Object
  • Object
show all
Defined in:
lib/http_client_generator/plugs/set_bearer_token.rb

Instance Method Summary collapse

Constructor Details

#initialize(from_arg:) ⇒ SetBearerToken

Returns a new instance of SetBearerToken.



8
9
10
# File 'lib/http_client_generator/plugs/set_bearer_token.rb', line 8

def initialize(from_arg:)
  @from_arg = from_arg
end

Instance Method Details

#call(req) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/http_client_generator/plugs/set_bearer_token.rb', line 12

def call(req)
  token = req.rest_args[@from_arg]

  req.headers[:authorization] = "Bearer #{token}"

  req
end