Class: BRL::Auth::AuthenticatedConnection

Inherits:
Connection
  • Object
show all
Defined in:
lib/brl/auth/authenticated_connection.rb

Constant Summary collapse

"BRL_AUTH_COOKIE_CACHE_KEY"
CONTENT_TYPE =
"application/json"

Constants inherited from Connection

Connection::ACCEPT

Instance Method Summary collapse

Constructor Details

#initialize(token_service: BRL::Auth::TokenService.new, cache: defined?(Rails) ? Rails.cache : nil, request_class: Faraday, base_url: BRL::BASE_URL) ⇒ AuthenticatedConnection

Returns a new instance of AuthenticatedConnection.



9
10
11
12
13
14
15
16
# File 'lib/brl/auth/authenticated_connection.rb', line 9

def initialize(token_service: BRL::Auth::TokenService.new,
                cache: defined?(Rails) ? Rails.cache : nil,
                request_class: Faraday,
                base_url: BRL::BASE_URL)
  super(request_class: request_class, base_url: base_url)
  @token_service = token_service
  @cache = cache
end

Instance Method Details

#default_headersObject



18
19
20
21
22
23
24
# File 'lib/brl/auth/authenticated_connection.rb', line 18

def default_headers
  {
    "Accept": CONTENT_TYPE,
    "Authorization": (@cache ? cached_token : auth_token),
    "Content-Type": CONTENT_TYPE
  }
end