Class: TokenEndpoint::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/token_endpoint/response.rb

Constant Summary collapse

HTTP_HEADERS_OPTS =
{
  accept: '*/*',
  user_agent: 'Token Endpoint Discovery (https://rubygems.org/gems/token-endpoint)'
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(uri) ⇒ Response

Returns a new instance of Response.

Raises:



8
9
10
11
12
# File 'lib/token_endpoint/response.rb', line 8

def initialize(uri)
  raise ArgumentError, "uri must be an Addressable::URI (given #{uri.class.name})" unless uri.is_a?(Addressable::URI)

  @uri = uri
end

Instance Method Details

#responseObject



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/token_endpoint/response.rb', line 14

def response
  @response ||= HTTP.follow.headers(HTTP_HEADERS_OPTS).timeout(
    connect: 10,
    read: 10
  ).get(@uri)
rescue HTTP::ConnectionError => error
  raise ConnectionError, error
rescue HTTP::TimeoutError => error
  raise TimeoutError, error
rescue HTTP::Redirector::TooManyRedirectsError => error
  raise TooManyRedirectsError, error
end