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

Raises:



14
15
16
17
18
# File 'lib/indieweb/endpoints/client.rb', line 14

def initialize(url)
  @uri = HTTP::URI.parse(url)
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.



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

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

#inspectString

:nocov:



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

def inspect
  format "#<%<class>s:%<id>#0x @uri=%<uri>s>",
         class: self.class,
         id: object_id << 1,
         uri: uri.inspect
end

#responseHTTP::Response

The HTTP::Response object.

Raises:



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

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