Sha256: 8154cdd2d09848782605788d1a6b7d2ccd2b105c2595cf9edafc867f74d8d5dd
Contents?: true
Size: 1.12 KB
Versions: 1
Compression:
Stored size: 1.12 KB
Contents
module IndieWeb module Endpoints class Client HTTP_HEADERS_OPTS = { accept: '*/*', user_agent: 'IndieAuth, Micropub, and Webmention Endpoint Discovery (https://rubygems.org/gems/indieweb-endpoints)' }.freeze 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 def endpoints @endpoints ||= Parsers.registered.transform_values { |parser| parser.new(response).results } end def response @response ||= HTTP.follow.headers(HTTP_HEADERS_OPTS).timeout(connect: 10, read: 10).get(@url) rescue HTTP::ConnectionError, HTTP::TimeoutError, HTTP::Redirector::TooManyRedirectsError => exception raise IndieWeb::Endpoints.const_get(exception.class.name.split('::').last), exception end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
indieweb-endpoints-0.2.0 | lib/indieweb/endpoints/client.rb |