Sha256: d443d61e012e43ff22509ec38487231d246d0fd20b24f97ea51ae770cf398cb7

Contents?: true

Size: 792 Bytes

Versions: 6

Compression:

Stored size: 792 Bytes

Contents

module AuthorizationEndpoint
  class Response
    HTTP_HEADERS_OPTS = {
      accept: '*/*',
      user_agent: 'Authorization Endpoint Discovery (https://rubygems.org/gems/authorization-endpoint)'
    }.freeze

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

      @uri = uri
    end

    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
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
authorization-endpoint-0.1.5 lib/authorization_endpoint/response.rb
authorization-endpoint-0.1.4 lib/authorization_endpoint/response.rb
authorization-endpoint-0.1.3 lib/authorization_endpoint/response.rb
authorization-endpoint-0.1.2 lib/authorization_endpoint/response.rb
authorization-endpoint-0.1.1 lib/authorization_endpoint/response.rb
authorization-endpoint-0.1.0 lib/authorization_endpoint/response.rb