Class: IndieWeb::Endpoints::Client
- Inherits:
-
Object
- Object
- IndieWeb::Endpoints::Client
- Defined in:
- lib/indieweb/endpoints/client.rb
Constant Summary collapse
- HTTP_HEADERS_OPTS =
{ accept: '*/*', user_agent: 'IndieAuth, Micropub, and Webmention Endpoint Discovery (https://rubygems.org/gems/indieweb-endpoints)' }.freeze
Instance Method Summary collapse
- #endpoints ⇒ Object
-
#initialize(url) ⇒ Client
constructor
A new instance of Client.
- #response ⇒ Object
Constructor Details
#initialize(url) ⇒ Client
Returns a new instance of Client.
9 10 11 12 13 14 15 16 17 |
# File 'lib/indieweb/endpoints/client.rb', line 9 def initialize(url) raise ArgumentError, "url must be a String (given #{url.class.name})" unless url.is_a?(String) @url = Addressable::URI.parse(url) raise ArgumentError, 'url must be an absolute URL (e.g. https://example.com)' unless @url.absolute? rescue Addressable::URI::InvalidURIError => exception raise InvalidURIError, exception end |
Instance Method Details
#endpoints ⇒ Object
19 20 21 |
# File 'lib/indieweb/endpoints/client.rb', line 19 def endpoints @endpoints ||= Parsers.registered.transform_values { |parser| parser.new(response).results } end |
#response ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/indieweb/endpoints/client.rb', line 23 def response @response ||= HTTP.follow.headers(HTTP_HEADERS_OPTS).timeout( connect: 10, read: 10 ).get(@url) rescue HTTP::ConnectionError => exception raise ConnectionError, exception rescue HTTP::TimeoutError => exception raise TimeoutError, exception rescue HTTP::Redirector::TooManyRedirectsError => exception raise TooManyRedirectsError, exception end |