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:



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

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})


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

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

#inspectString

Returns:

  • (String)


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

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:



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

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