Class: IndieWeb::Endpoints::ResponseBodyParser Private

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

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ ResponseBodyParser

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of ResponseBodyParser.

Parameters:

  • response (HTTP::Response)


8
9
10
11
12
# File 'lib/indieweb/endpoints/response_body_parser.rb', line 8

def initialize(response)
  @body = response.body.to_s
  @mime_type = response.mime_type
  @uri = response.uri
end

Instance Method Details

#results_for(identifier, nodes = ["link"]) ⇒ Array<string>?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • identifier (Symbol)
  • nodes (Array<String>) (defaults to: ["link"])

Returns:

  • (Array<string>, nil)


17
18
19
20
21
22
23
24
# File 'lib/indieweb/endpoints/response_body_parser.rb', line 17

def results_for(identifier, nodes = ["link"])
  return unless mime_type == "text/html"

  # Reject endpoints that contain a fragment identifier
  selectors = nodes.map { |node| %(#{node}[rel~="#{identifier}"][href]:not([href*="#"])) }.join(",")

  parsed_body.css(selectors).map { |element| element["href"] }
end