Class: IndieWeb::Endpoints::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/indieweb/endpoints/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ Client

Create a new client with a URL to parse for IndieWeb endpoints.

Examples:

client = IndieWeb::Endpoints::Client.new("https://aaronparecki.com")

Parameters:

  • url (String, HTTP::URI, #to_s)

    an absolute URL

Raises:



21
22
23
24
25
# File 'lib/indieweb/endpoints/client.rb', line 21

def initialize(url)
  @uri = HTTP::URI.parse(url.to_s)
rescue Addressable::URI::InvalidURIError => e
  raise InvalidURIError, e
end

Instance Method Details

#endpointsHash{Symbol => String, Array, nil}

A Hash of the discovered IndieWeb endpoints from the provided URL.

Returns:

  • (Hash{Symbol => String, Array, nil})


35
36
37
# File 'lib/indieweb/endpoints/client.rb', line 35

def endpoints
  @endpoints ||= Parser.new(response).to_h
end

#inspectString

Returns:

  • (String)


28
29
30
# File 'lib/indieweb/endpoints/client.rb', line 28

def inspect
  %(#<#{self.class.name}:#{format("%#0x", object_id)} uri: "#{uri}">)
end

#responseHTTP::Response

The HTTP::Response object returned by the provided URL.

Returns:

  • (HTTP::Response)

Raises:



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/indieweb/endpoints/client.rb', line 44

def response
  @response ||= HTTP
                  .follow(max_hops: 20)
                  .headers(HTTP_HEADERS_OPTS)
                  .timeout(connect: 5, read: 5)
                  .get(uri)
rescue HTTP::Error => e
  raise HttpError, e
rescue OpenSSL::SSL::SSLError => e
  raise SSLError, e
end