indieweb-endpoints 8.0.0 → 9.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: efd7555091687973a996b1914f1a739e7933381dc149d7b67babdf739f8c7c0b
4
- data.tar.gz: 744cf8171f987add528d18713c2869c954fa9f227c84508ae1d7ad30ea4cba17
3
+ metadata.gz: da8f18ac80e24b04e834e41ef4ec959cc26c3496b888de60c92d518fb89bbc78
4
+ data.tar.gz: 64a2117a77c161ab5d4c5b616c4fe1685406ea58218ade5af72eb2998048f402
5
5
  SHA512:
6
- metadata.gz: a799aaede4a422adf01c660b7a7ed7b88b6d5907c7f30fef7bf6a12c1b50b2eba64c055ba7b47a3cb899e865552ae6ae124be657ebf7539dba6206baf7457c36
7
- data.tar.gz: b6ebbaed9561e1b8773329f1782dad87c1a8415bd2849593ec529734eb07930bd9df52e55a9881cc3706003f7479f367cd001ab40802c216aee56c7c30e7926a
6
+ metadata.gz: 54fdc8310a995d36c8f46e8926790bafd8352a5db02e32144a4d4ce074258bc5c7ca80cc9778d910a522749f4b9807eb5cd202465ee8d811ca5ee4d4aa6311f7
7
+ data.tar.gz: 1d36d41eccca9f32ccecd622bc739915af4af9f61596fabf48d994e4d6f741ae4c8013a064c9b908917bf6896ac4ad291df8a90e882f074a3b1a12dbcc23b76b
data/CHANGELOG.md CHANGED
@@ -1,6 +1,9 @@
1
1
  # Changelog
2
2
 
3
- ## 8.0.0 / unreleased
3
+ > [!NOTE]
4
+ > From v9.0.0, changes are documented using [GitHub Releases](https://github.com/indieweb/indieweb-endpoints-ruby/releases). For a given release, metadata on RubyGems.org will link to that version's Release page.
5
+
6
+ ## 8.0.0 / 2022-11-09
4
7
 
5
8
  - Refactor `ResponseHeadersParser#results_for` to use `Enumerable#filter_map` (946ff3d)
6
9
  - Update link-header-parser dependency constraint (4f093fb)
data/CONTRIBUTING.md CHANGED
@@ -2,15 +2,18 @@
2
2
 
3
3
  There are a couple ways you can help improve indieweb-endpoints-ruby:
4
4
 
5
- 1. Fix an existing [issue][issues] and submit a [pull request][pulls].
6
- 1. Review open [pull requests][pulls].
7
- 1. Report a new [issue][issues]. _Only do this after you've made sure the behavior or problem you're observing isn't already documented in an open issue._
5
+ 1. Fix an existing [Issue][issues] and submit a [Pull Request][pulls].
6
+ 1. Review open [Pull Requests][pulls].
7
+ 1. Report a new [Issue][issues]. _Only do this after you've made sure the behavior or problem you're observing isn't already documented in an open issue._
8
8
 
9
9
  ## Getting Started
10
10
 
11
- indieweb-endpoints-ruby is developed using Ruby 2.7.6 and is additionally tested against Ruby 3.0 and 3.1 using [GitHub Actions](https://github.com/indieweb/indieweb-endpoints-ruby/actions).
11
+ indieweb-endpoints-ruby is developed using Ruby 3.4 and is tested against additional Ruby versions using [GitHub Actions](https://github.com/indieweb/indieweb-endpoints-ruby/actions).
12
12
 
13
- Before making changes to indieweb-endpoints-ruby, you'll want to install Ruby 2.7.6. It's recommended that you use a Ruby version managment tool like [rbenv](https://github.com/rbenv/rbenv), [chruby](https://github.com/postmodern/chruby), or [rvm](https://github.com/rvm/rvm). Once you've installed Ruby 2.7.6 using your method of choice, install the project's gems by running:
13
+ > [!TIP]
14
+ > This project is configured with a [Dev Container](https://containers.dev) which includes everything you'd need to contribute to indieweb-endpoints-ruby. If you use a supported code editor or IDE, you're encouraged to use the existing Dev Container setup.
15
+
16
+ Before making changes to indieweb-endpoints-ruby, you'll want to install Ruby 3.4. Using a Ruby version managment tool like [rbenv](https://github.com/rbenv/rbenv), [chruby](https://github.com/postmodern/chruby), or [rvm](https://github.com/rvm/rvm) is recommended. Once you've installed Ruby 3.4 using your method of choice, install the project's gems by running:
14
17
 
15
18
  ```sh
16
19
  bundle install
@@ -19,17 +22,17 @@ bundle install
19
22
  ## Making Changes
20
23
 
21
24
  1. Fork and clone the project's repo.
22
- 1. Install development dependencies as outlined above.
23
- 1. Create a feature branch for the code changes you're looking to make: `git checkout -b my-new-feature`.
24
- 1. _Write some code!_
25
- 1. If your changes would benefit from testing, add the necessary tests and verify everything passes by running `bundle exec rspec`.
26
- 1. Commit your changes: `git commit -am 'Add some new feature or fix some issue'`. _(See [this excellent article](https://chris.beams.io/posts/git-commit/) for tips on writing useful Git commit messages.)_
27
- 1. Push the branch to your fork: `git push -u origin my-new-feature`.
28
- 1. Create a new [pull request][pulls] and we'll review your changes.
25
+ 2. Install development dependencies as outlined above.
26
+ 3. Create a feature branch for the code changes you're looking to make: `git checkout -b my-new-feature`.
27
+ 4. _Write some code!_
28
+ 5. If your changes would benefit from testing, add the necessary tests and verify everything passes by running `bundle exec rspec`.
29
+ 6. Commit your changes: `git commit -am 'Add some new feature or fix some issue'`. _(See [this excellent article](https://cbea.ms/git-commit/) for tips on writing useful Git commit messages.)_
30
+ 7. Push the branch to your fork: `git push -u origin my-new-feature`.
31
+ 8. Create a new [Pull Request][pulls] and we'll review your changes.
29
32
 
30
33
  ## Code Style
31
34
 
32
- Code formatting conventions are defined in the `.editorconfig` file which uses the [EditorConfig](http://editorconfig.org) syntax. There are [plugins for a variety of editors](http://editorconfig.org/#download) that utilize the settings in the `.editorconfig` file. We recommended you install the EditorConfig plugin for your editor of choice.
35
+ Code formatting conventions are defined in the `.editorconfig` file which uses the [EditorConfig](https://editorconfig.org) syntax. There are [plugins for a variety of editors](https://editorconfig.org/#download) that utilize the settings in the `.editorconfig` file. We recommended installing the EditorConfig plugin for your editor of choice.
33
36
 
34
37
  Your bug fix or feature addition won't be rejected if it runs afoul of any (or all) of these guidelines, but following the guidelines will definitely make everyone's lives a little easier.
35
38
 
data/README.md CHANGED
@@ -4,36 +4,28 @@
4
4
 
5
5
  [![Gem](https://img.shields.io/gem/v/indieweb-endpoints.svg?logo=rubygems&style=for-the-badge)](https://rubygems.org/gems/indieweb-endpoints)
6
6
  [![Downloads](https://img.shields.io/gem/dt/indieweb-endpoints.svg?logo=rubygems&style=for-the-badge)](https://rubygems.org/gems/indieweb-endpoints)
7
- [![Build](https://img.shields.io/github/workflow/status/indieweb/indieweb-endpoints-ruby/CI?logo=github&style=for-the-badge)](https://github.com/indieweb/indieweb-endpoints-ruby/actions/workflows/ci.yml)
8
- [![Maintainability](https://img.shields.io/codeclimate/maintainability/indieweb/indieweb-endpoints-ruby.svg?logo=code-climate&style=for-the-badge)](https://codeclimate.com/github/indieweb/indieweb-endpoints-ruby)
9
- [![Coverage](https://img.shields.io/codeclimate/c/indieweb/indieweb-endpoints-ruby.svg?logo=code-climate&style=for-the-badge)](https://codeclimate.com/github/indieweb/indieweb-endpoints-ruby/code)
7
+ [![Build](https://img.shields.io/github/actions/workflow/status/indieweb/indieweb-endpoints-ruby/ci.yml?branch=main&logo=github&style=for-the-badge)](https://github.com/indieweb/indieweb-endpoints-ruby/actions/workflows/ci.yml)
10
8
 
11
9
  ## Key Features
12
10
 
13
11
  - Compliant with [Section 4.1](https://www.w3.org/TR/indieauth/#discovery-by-clients) and [Section 4.2.2](https://www.w3.org/TR/indieauth/#redirect-url) of [the W3C's IndieAuth Working Group Note](https://www.w3.org/TR/indieauth/), [Section 5.3](https://www.w3.org/TR/micropub/#endpoint-discovery) of [the W3C's Micropub Recommendation](https://www.w3.org/TR/micropub/), and [Section 3.1.2](https://www.w3.org/TR/webmention/#sender-discovers-receiver-webmention-endpoint) of [the W3C's Webmention Recommendation](https://www.w3.org/TR/webmention/).
14
12
  - Passes all Endpoint Discovery tests on [webmention.rocks](https://webmention.rocks).
15
- - Supports Ruby 2.7 and newer.
13
+ - Supports Ruby 2.6 and newer.
16
14
 
17
15
  ## Getting Started
18
16
 
19
- Before installing and using indieweb-endpoints-ruby, you'll want to have [Ruby](https://www.ruby-lang.org) 2.7 (or newer) installed. It's recommended that you use a Ruby version managment tool like [rbenv](https://github.com/rbenv/rbenv), [chruby](https://github.com/postmodern/chruby), or [rvm](https://github.com/rvm/rvm).
17
+ Before installing and using indieweb-endpoints-ruby, you'll want to have [Ruby](https://www.ruby-lang.org) 2.6 (or newer) installed. Using a Ruby version managment tool like [rbenv](https://github.com/rbenv/rbenv), [chruby](https://github.com/postmodern/chruby), or [rvm](https://github.com/rvm/rvm) is recommended.
20
18
 
21
- indieweb-endpoints-ruby is developed using Ruby 2.7.6 and is additionally tested against Ruby 3.0 and 3.1 using [GitHub Actions](https://github.com/indieweb/indieweb-endpoints-ruby/actions).
19
+ indieweb-endpoints-ruby is developed using Ruby 3.4 and is tested against additional Ruby versions using [GitHub Actions](https://github.com/indieweb/indieweb-endpoints-ruby/actions).
22
20
 
23
21
  ## Installation
24
22
 
25
- If you're using [Bundler](https://bundler.io), add indieweb-endpoints-ruby to your project's `Gemfile`:
23
+ Add indieweb-endpoints-ruby to your project's `Gemfile` and run `bundle install`:
26
24
 
27
25
  ```ruby
28
- source 'https://rubygems.org'
26
+ source "https://rubygems.org"
29
27
 
30
- gem 'indieweb-endpoints'
31
- ```
32
-
33
- …and hop over to your command prompt and run…
34
-
35
- ```sh
36
- $ bundle install
28
+ gem "indieweb-endpoints"
37
29
  ```
38
30
 
39
31
  ## Usage
@@ -43,22 +35,22 @@ $ bundle install
43
35
  With indieweb-endpoints-ruby added to your project's `Gemfile` and installed, you may discover a URL's IndieWeb-relevant endpoints by doing:
44
36
 
45
37
  ```ruby
46
- require 'indieweb/endpoints'
38
+ require "indieweb/endpoints"
47
39
 
48
- IndieWeb::Endpoints.get('https://aaronparecki.com')
40
+ IndieWeb::Endpoints.get("https://aaronparecki.com")
49
41
  #=> { authorization_endpoint: "https://aaronparecki.com/auth", "indieauth-metadata": "https://aaronparecki.com/.well-known/oauth-authorization-server", micropub: "https://aaronparecki.com/micropub", microsub: "https://aperture.p3k.io/microsub/1", redirect_uri: nil, token_endpoint: "https://aaronparecki.com/auth/token", webmention: "https://webmention.io/aaronpk/webmention" }
50
42
  ```
51
43
 
52
- This example will search `https://aaronparecki.com` for valid IndieAuth, Micropub, and Webmention endpoints and return a `Hash` of results. Each key in the returned `Hash` will have a value of either a `String` representing a URL or `nil`. The `redirect_uri` key's value will be either an `Array` or `nil` since a given URL may register multiple callback URLs.
44
+ This example will search [Aaron's website](https://aaronparecki.com) for valid IndieAuth, Micropub, and Webmention endpoints and return a `Hash` of results. Each key in the returned `Hash` will have a value of either a `String` representing a URL or `nil`. The `redirect_uri` key's value will be either an `Array` or `nil` since a given URL may register multiple callback URLs.
53
45
 
54
46
  ### Advanced Usage
55
47
 
56
48
  Should the need arise, you may work with the `IndieWeb::Endpoints::Client` class:
57
49
 
58
50
  ```ruby
59
- require 'indieweb/endpoints'
51
+ require "indieweb/endpoints"
60
52
 
61
- client = IndieWeb::Endpoints::Client.new('https://aaronparecki.com')
53
+ client = IndieWeb::Endpoints::Client.new("https://aaronparecki.com")
62
54
  #=> #<IndieWeb::Endpoints::Client uri: "https://aaronparecki.com">
63
55
 
64
56
  client.response
@@ -70,23 +62,15 @@ client.endpoints
70
62
 
71
63
  ### Exception Handling
72
64
 
73
- There are several exceptions that may be raised by indieweb-endpoints-ruby's underlying dependencies. These errors are raised as subclasses of `IndieWeb::Endpoints::Error` (which itself is a subclass of `StandardError`).
74
-
75
- From [sporkmonger/addressable](https://github.com/sporkmonger/addressable):
65
+ indieweb-endpoints-ruby may raise the following exceptions which are subclasses of `IndieWeb::Endpoints::Error` (which itself is a subclass of `StandardError`).
76
66
 
77
67
  - `IndieWeb::Endpoints::InvalidURIError`
78
-
79
- From [httprb/http](https://github.com/httprb/http):
80
-
81
68
  - `IndieWeb::Endpoints::HttpError`
82
-
83
- From the Ruby Standard Library's [`OpenSSL::SSL::SSLError`](https://ruby-doc.org/stdlib-2.7.6/libdoc/openssl/rdoc/OpenSSL/SSL/SSLError.html):
84
-
85
69
  - `IndieWeb::Endpoints::SSLError`
86
70
 
87
71
  ## Contributing
88
72
 
89
- Interested in helping improve indieweb-endpoints-ruby? Awesome! Your help is greatly appreciated. See [CONTRIBUTING.md](https://github.com/indieweb/indieweb-endpoints-ruby/blob/main/CONTRIBUTING.md) for details.
73
+ See [CONTRIBUTING.md](https://github.com/indieweb/indieweb-endpoints-ruby/blob/main/CONTRIBUTING.md) for more on how to contribute to indieweb-endpoints-ruby. Your help is greatly appreciated!
90
74
 
91
75
  By contributing to and participating in the development of indieweb-endpoints-ruby, you acknowledge that you have read and agree to the [IndieWeb Code of Conduct](https://indieweb.org/code-of-conduct).
92
76
 
@@ -98,4 +82,4 @@ indieweb-endpoints-ruby is written and maintained by [Jason Garber](https://sixt
98
82
 
99
83
  ## License
100
84
 
101
- indieweb-endpoints-ruby is freely available under the [MIT License](https://opensource.org/licenses/MIT). Use it, learn from it, fork it, improve it, change it, tailor it to your needs.
85
+ indieweb-endpoints-ruby is freely available under the [MIT License](https://opensource.org/licenses/MIT).
@@ -1,33 +1,34 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'lib/indieweb/endpoints/version'
4
-
5
3
  Gem::Specification.new do |spec|
6
- spec.required_ruby_version = '>= 2.7', '< 4'
4
+ spec.required_ruby_version = ">= 2.6"
7
5
 
8
- spec.name = 'indieweb-endpoints'
9
- spec.version = IndieWeb::Endpoints::VERSION
10
- spec.authors = ['Jason Garber']
11
- spec.email = ['jason@sixtwothree.org']
6
+ spec.name = "indieweb-endpoints"
7
+ spec.version = "9.1.0"
8
+ spec.authors = ["Jason Garber"]
9
+ spec.email = ["jason@sixtwothree.org"]
12
10
 
13
- spec.summary = 'Discover a URL’s IndieAuth, Micropub, Microsub, and Webmention endpoints.'
14
- spec.description = spec.summary
15
- spec.homepage = 'https://github.com/indieweb/indieweb-endpoints-ruby'
16
- spec.license = 'MIT'
11
+ spec.summary = "Discover a URL’s IndieAuth, Micropub, Microsub, and Webmention endpoints."
12
+ spec.description = spec.summary
13
+ spec.homepage = "https://github.com/indieweb/indieweb-endpoints-ruby"
14
+ spec.license = "MIT"
17
15
 
18
- spec.files = Dir['lib/**/*'].reject { |f| File.directory?(f) }
19
- spec.files += %w[LICENSE CHANGELOG.md CODE_OF_CONDUCT.md CONTRIBUTING.md README.md]
20
- spec.files += %w[indieweb-endpoints.gemspec]
16
+ spec.files = Dir["lib/**/*"].reject { |f| File.directory?(f) }
17
+ spec.files += ["LICENSE", "CHANGELOG.md", "CODE_OF_CONDUCT.md", "CONTRIBUTING.md", "README.md"]
18
+ spec.files += ["indieweb-endpoints.gemspec"]
21
19
 
22
- spec.require_paths = ['lib']
20
+ spec.require_paths = ["lib"]
23
21
 
24
22
  spec.metadata = {
25
- 'bug_tracker_uri' => "#{spec.homepage}/issues",
26
- 'changelog_uri' => "#{spec.homepage}/blob/v#{spec.version}/CHANGELOG.md",
27
- 'rubygems_mfa_required' => 'true'
23
+ "bug_tracker_uri" => "#{spec.homepage}/issues",
24
+ "changelog_uri" => "#{spec.homepage}/releases/tag/v#{spec.version}",
25
+ "documentation_uri" => "https://rubydoc.info/gems/#{spec.name}/#{spec.version}",
26
+ "homepage_uri" => spec.homepage,
27
+ "rubygems_mfa_required" => "true",
28
+ "source_code_uri" => "#{spec.homepage}/tree/v#{spec.version}",
28
29
  }
29
30
 
30
- spec.add_runtime_dependency 'http', '~> 5.0'
31
- spec.add_runtime_dependency 'link-header-parser', '~> 5.0'
32
- spec.add_runtime_dependency 'nokogiri', '>= 1.13'
31
+ spec.add_dependency "http", "~> 5.2"
32
+ spec.add_dependency "link-header-parser", "~> 6.1"
33
+ spec.add_dependency "nokogiri", ">= 1.13"
33
34
  end
@@ -4,8 +4,8 @@ module IndieWeb
4
4
  module Endpoints
5
5
  class Client
6
6
  HTTP_HEADERS_OPTS = {
7
- accept: '*/*',
8
- user_agent: 'IndieWeb Endpoint Discovery (https://rubygems.org/gems/indieweb-endpoints)'
7
+ accept: "*/*",
8
+ user_agent: "IndieWeb Endpoint Discovery (https://rubygems.org/gems/indieweb-endpoints)",
9
9
  }.freeze
10
10
 
11
11
  private_constant :HTTP_HEADERS_OPTS
@@ -13,10 +13,11 @@ module IndieWeb
13
13
  # Create a new client with a URL to parse for IndieWeb endpoints.
14
14
  #
15
15
  # @example
16
- # client = IndieWeb::Endpoints::Client.new('https://aaronparecki.com')
16
+ # client = IndieWeb::Endpoints::Client.new("https://aaronparecki.com")
17
17
  #
18
18
  # @param url [String, HTTP::URI, #to_s] an absolute URL
19
- # @raise [IndieWeb::Endpoints::InvalidURIError]
19
+ #
20
+ # @raise [InvalidURIError]
20
21
  def initialize(url)
21
22
  @uri = HTTP::URI.parse(url.to_s)
22
23
  rescue Addressable::URI::InvalidURIError => e
@@ -25,25 +26,27 @@ module IndieWeb
25
26
 
26
27
  # @return [String]
27
28
  def inspect
28
- %(#<#{self.class.name}:#{format('%#0x', object_id)} uri: "#{uri}">)
29
+ %(#<#{self.class.name}:#{format("%#0x", object_id)} uri: "#{uri}">)
29
30
  end
30
31
 
31
32
  # A Hash of the discovered IndieWeb endpoints from the provided URL.
32
33
  #
33
34
  # @return [Hash{Symbol => String, Array, nil}]
34
35
  def endpoints
35
- @endpoints ||= Parser.new(response).results
36
+ @endpoints ||= Parser.new(response).to_h
36
37
  end
37
38
 
38
- # The +HTTP::Response+ object returned by the provided URL.
39
+ # The {HTTP::Response} object returned by the provided URL.
39
40
  #
40
41
  # @return [HTTP::Response]
41
- # @raise [IndieWeb::Endpoints::HttpError, IndieWeb::Endpoints::SSLError]
42
+ #
43
+ # @raise [HttpError, SSLError]
42
44
  def response
43
- @response ||= HTTP.follow(max_hops: 20)
44
- .headers(HTTP_HEADERS_OPTS)
45
- .timeout(connect: 5, read: 5)
46
- .get(uri)
45
+ @response ||= HTTP
46
+ .follow(max_hops: 20)
47
+ .headers(HTTP_HEADERS_OPTS)
48
+ .timeout(connect: 5, read: 5)
49
+ .get(uri)
47
50
  rescue HTTP::Error => e
48
51
  raise HttpError, e
49
52
  rescue OpenSSL::SSL::SSLError => e
@@ -9,16 +9,43 @@ module IndieWeb
9
9
  @response = response
10
10
  end
11
11
 
12
- # @return [Hash{Symbol => String, Array<String>, nil}]
13
- def results
12
+ # @param identifier [String]
13
+ # @param node_names [Array<String>]
14
+ #
15
+ # @return [Array<String>]
16
+ #
17
+ # @raise [InvalidURIError]
18
+ def matches(identifier, node_names: ["link"])
19
+ results =
20
+ (matches_from_headers(identifier) + matches_from_body(identifier, node_names))
21
+ .compact
22
+ .map! { |endpoint| response.uri.join(endpoint).to_s }
23
+
24
+ results.uniq!
25
+ results.sort!
26
+
27
+ results
28
+ rescue Addressable::URI::InvalidURIError => e
29
+ raise InvalidURIError, e
30
+ end
31
+
32
+ # @param (see #matches)
33
+ #
34
+ # @return [String]
35
+ def match(identifier, **kwargs)
36
+ matches(identifier, **kwargs).first
37
+ end
38
+
39
+ # @return [Hash{Symbol => String, Array, nil}]
40
+ def to_h
14
41
  {
15
- authorization_endpoint: result_for(:authorization_endpoint),
16
- 'indieauth-metadata': result_for(:'indieauth-metadata'),
17
- micropub: result_for(:micropub),
18
- microsub: result_for(:microsub),
19
- redirect_uri: results_for(:redirect_uri),
20
- token_endpoint: result_for(:token_endpoint),
21
- webmention: result_for(:webmention, %w[link a])
42
+ authorization_endpoint: match("authorization_endpoint"),
43
+ "indieauth-metadata": match("indieauth-metadata"),
44
+ micropub: match("micropub"),
45
+ microsub: match("microsub"),
46
+ redirect_uri: (redirect_uri = matches("redirect_uri")).any? ? redirect_uri : nil,
47
+ token_endpoint: match("token_endpoint"),
48
+ webmention: match("webmention", node_names: ["link", "a"]),
22
49
  }
23
50
  end
24
51
 
@@ -27,38 +54,32 @@ module IndieWeb
27
54
  # @return [HTTP::Response]
28
55
  attr_reader :response
29
56
 
30
- # @return [IndieWeb::Endpoints::ResponseBodyParser]
31
- def response_body_parser
32
- @response_body_parser ||= ResponseBodyParser.new(response)
57
+ # @return [Nokogiri::HTML5::Document]
58
+ def body
59
+ @body ||= Nokogiri::HTML5(response.body)
33
60
  end
34
61
 
35
- # @return [IndieWeb::Endpoints::ResponseHeadersParser]
36
- def response_headers_parser
37
- @response_headers_parser ||= ResponseHeadersParser.new(response)
62
+ # @return [Hash{Symbol => Array<LinkHeaderParser::LinkHeader>}]
63
+ def headers
64
+ @headers ||= LinkHeaderParser.parse(response.headers.get("link"), base: response.uri).group_by_relation_type
38
65
  end
39
66
 
40
- # @param identifier [Symbol]
41
- # @param nodes [Array<String>]
42
- # @return [String, nil]
43
- def result_for(identifier, nodes = ['link'])
44
- results_for(identifier, nodes)&.first
45
- end
67
+ # @return [Array<String>]
68
+ def matches_from_body(identifier, node_names)
69
+ return [] unless response.mime_type == "text/html"
46
70
 
47
- # @param identifier [Symbol]
48
- # @param nodes [Array<String>]
49
- # @return [Array<String>, nil]
50
- # @raise [IndieWeb::Endpoints::InvalidURIError]
51
- def results_for(identifier, nodes = ['link'])
52
- results_from_request = [
53
- response_headers_parser.results_for(identifier),
54
- response_body_parser.results_for(identifier, nodes)
55
- ].flatten.compact
71
+ # Reject endpoints that contain a fragment identifier.
72
+ selectors = node_names.map { |node| %(#{node}[rel~="#{identifier}"][href]:not([href*="#"])) }.join(",")
56
73
 
57
- return if results_from_request.none?
74
+ body.css(selectors).map { |element| element["href"] }
75
+ end
58
76
 
59
- results_from_request.map { |endpoint| response.uri.join(endpoint).to_s }.uniq.sort
60
- rescue Addressable::URI::InvalidURIError => e
61
- raise InvalidURIError, e
77
+ # @return [Array<String>]
78
+ def matches_from_headers(identifier)
79
+ # Reject endpoints that contain a fragment identifier.
80
+ Array(headers[identifier.to_sym])
81
+ .filter { |header| !HTTP::URI.parse(header.target_uri).fragment }
82
+ .map(&:target_uri)
62
83
  end
63
84
  end
64
85
  end
@@ -1,32 +1,32 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'http'
4
- require 'link-header-parser'
5
- require 'nokogiri'
3
+ require "http"
4
+ require "link-header-parser"
5
+ require "nokogiri"
6
6
 
7
- require_relative 'endpoints/version'
8
-
9
- require_relative 'endpoints/client'
10
- require_relative 'endpoints/parser'
11
- require_relative 'endpoints/response_body_parser'
12
- require_relative 'endpoints/response_headers_parser'
7
+ require_relative "endpoints/client"
8
+ require_relative "endpoints/parser"
13
9
 
14
10
  module IndieWeb
15
11
  module Endpoints
16
12
  class Error < StandardError; end
13
+
17
14
  class HttpError < Error; end
15
+
18
16
  class InvalidURIError < Error; end
17
+
19
18
  class SSLError < Error; end
20
19
 
21
20
  # Discover a URL's IndieAuth, Micropub, Microsub, and Webmention endpoints.
22
21
  #
23
- # Convenience method for {IndieWeb::Endpoints::Client#endpoints}.
22
+ # Convenience method for {Client#endpoints}.
24
23
  #
25
24
  # @example
26
- # IndieWeb::Endpoints.get('https://aaronparecki.com')
25
+ # IndieWeb::Endpoints.get("https://aaronparecki.com")
26
+ #
27
+ # @param (see Client#initialize)
27
28
  #
28
- # @param (see IndieWeb::Endpoints::Client#endpoints)
29
- # @return (see IndieWeb::Endpoints::Client#endpoints)
29
+ # @return (see Client#endpoints)
30
30
  def self.get(url)
31
31
  Client.new(url).endpoints
32
32
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: indieweb-endpoints
3
3
  version: !ruby/object:Gem::Version
4
- version: 8.0.0
4
+ version: 9.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Garber
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2022-11-09 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: http
@@ -16,28 +15,28 @@ dependencies:
16
15
  requirements:
17
16
  - - "~>"
18
17
  - !ruby/object:Gem::Version
19
- version: '5.0'
18
+ version: '5.2'
20
19
  type: :runtime
21
20
  prerelease: false
22
21
  version_requirements: !ruby/object:Gem::Requirement
23
22
  requirements:
24
23
  - - "~>"
25
24
  - !ruby/object:Gem::Version
26
- version: '5.0'
25
+ version: '5.2'
27
26
  - !ruby/object:Gem::Dependency
28
27
  name: link-header-parser
29
28
  requirement: !ruby/object:Gem::Requirement
30
29
  requirements:
31
30
  - - "~>"
32
31
  - !ruby/object:Gem::Version
33
- version: '5.0'
32
+ version: '6.1'
34
33
  type: :runtime
35
34
  prerelease: false
36
35
  version_requirements: !ruby/object:Gem::Requirement
37
36
  requirements:
38
37
  - - "~>"
39
38
  - !ruby/object:Gem::Version
40
- version: '5.0'
39
+ version: '6.1'
41
40
  - !ruby/object:Gem::Dependency
42
41
  name: nokogiri
43
42
  requirement: !ruby/object:Gem::Requirement
@@ -68,17 +67,16 @@ files:
68
67
  - lib/indieweb/endpoints.rb
69
68
  - lib/indieweb/endpoints/client.rb
70
69
  - lib/indieweb/endpoints/parser.rb
71
- - lib/indieweb/endpoints/response_body_parser.rb
72
- - lib/indieweb/endpoints/response_headers_parser.rb
73
- - lib/indieweb/endpoints/version.rb
74
70
  homepage: https://github.com/indieweb/indieweb-endpoints-ruby
75
71
  licenses:
76
72
  - MIT
77
73
  metadata:
78
74
  bug_tracker_uri: https://github.com/indieweb/indieweb-endpoints-ruby/issues
79
- changelog_uri: https://github.com/indieweb/indieweb-endpoints-ruby/blob/v8.0.0/CHANGELOG.md
75
+ changelog_uri: https://github.com/indieweb/indieweb-endpoints-ruby/releases/tag/v9.1.0
76
+ documentation_uri: https://rubydoc.info/gems/indieweb-endpoints/9.1.0
77
+ homepage_uri: https://github.com/indieweb/indieweb-endpoints-ruby
80
78
  rubygems_mfa_required: 'true'
81
- post_install_message:
79
+ source_code_uri: https://github.com/indieweb/indieweb-endpoints-ruby/tree/v9.1.0
82
80
  rdoc_options: []
83
81
  require_paths:
84
82
  - lib
@@ -86,18 +84,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
86
84
  requirements:
87
85
  - - ">="
88
86
  - !ruby/object:Gem::Version
89
- version: '2.7'
90
- - - "<"
91
- - !ruby/object:Gem::Version
92
- version: '4'
87
+ version: '2.6'
93
88
  required_rubygems_version: !ruby/object:Gem::Requirement
94
89
  requirements:
95
90
  - - ">="
96
91
  - !ruby/object:Gem::Version
97
92
  version: '0'
98
93
  requirements: []
99
- rubygems_version: 3.3.16
100
- signing_key:
94
+ rubygems_version: 3.6.7
101
95
  specification_version: 4
102
96
  summary: Discover a URL’s IndieAuth, Micropub, Microsub, and Webmention endpoints.
103
97
  test_files: []
@@ -1,43 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module IndieWeb
4
- module Endpoints
5
- # @api private
6
- class ResponseBodyParser
7
- # @param response [HTTP::Response]
8
- def initialize(response)
9
- @body = response.body.to_s
10
- @mime_type = response.mime_type
11
- @uri = response.uri
12
- end
13
-
14
- # @param identifier [Symbol]
15
- # @param nodes [Array<String>]
16
- # @return [Array<string>, nil]
17
- def results_for(identifier, nodes = ['link'])
18
- return unless mime_type == 'text/html'
19
-
20
- # Reject endpoints that contain a fragment identifier
21
- selectors = nodes.map { |node| %(#{node}[rel~="#{identifier}"][href]:not([href*="#"])) }.join(',')
22
-
23
- parsed_body.css(selectors).map { |element| element['href'] }
24
- end
25
-
26
- private
27
-
28
- # @return [String]
29
- attr_reader :body
30
-
31
- # @return [String]
32
- attr_reader :mime_type
33
-
34
- # @return [HTTP::URI]
35
- attr_reader :uri
36
-
37
- # @return [Nokogiri::HTML5::Document]
38
- def parsed_body
39
- @parsed_body ||= Nokogiri::HTML5(body)
40
- end
41
- end
42
- end
43
- end
@@ -1,36 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module IndieWeb
4
- module Endpoints
5
- # @api private
6
- class ResponseHeadersParser
7
- # @param response [HTTP::Response]
8
- def initialize(response)
9
- @headers = response.headers.get('link')
10
- @uri = response.uri
11
- end
12
-
13
- # @param identifier [Symbol]
14
- # @return [Array<String>, nil]
15
- def results_for(identifier)
16
- # Reject endpoints that contain a fragment identifier
17
- parsed_headers[identifier]&.filter_map do |header|
18
- header.target_uri unless HTTP::URI.parse(header.target_uri).fragment
19
- end
20
- end
21
-
22
- private
23
-
24
- # @return [Array<String>]
25
- attr_reader :headers
26
-
27
- # @return [HTTP::URI]
28
- attr_reader :uri
29
-
30
- # @return [Hash{Symbol => Array<LinkHeaderParser::LinkHeader>}]
31
- def parsed_headers
32
- @parsed_headers ||= LinkHeaderParser.parse(headers, base: uri).group_by_relation_type
33
- end
34
- end
35
- end
36
- end
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module IndieWeb
4
- module Endpoints
5
- VERSION = '8.0.0'
6
- end
7
- end