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 +4 -4
- data/CHANGELOG.md +4 -1
- data/CONTRIBUTING.md +16 -13
- data/README.md +15 -31
- data/indieweb-endpoints.gemspec +22 -21
- data/lib/indieweb/endpoints/client.rb +15 -12
- data/lib/indieweb/endpoints/parser.rb +55 -34
- data/lib/indieweb/endpoints.rb +13 -13
- metadata +12 -18
- data/lib/indieweb/endpoints/response_body_parser.rb +0 -43
- data/lib/indieweb/endpoints/response_headers_parser.rb +0 -36
- data/lib/indieweb/endpoints/version.rb +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: da8f18ac80e24b04e834e41ef4ec959cc26c3496b888de60c92d518fb89bbc78
|
4
|
+
data.tar.gz: 64a2117a77c161ab5d4c5b616c4fe1685406ea58218ade5af72eb2998048f402
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 54fdc8310a995d36c8f46e8926790bafd8352a5db02e32144a4d4ce074258bc5c7ca80cc9778d910a522749f4b9807eb5cd202465ee8d811ca5ee4d4aa6311f7
|
7
|
+
data.tar.gz: 1d36d41eccca9f32ccecd622bc739915af4af9f61596fabf48d994e4d6f741ae4c8013a064c9b908917bf6896ac4ad291df8a90e882f074a3b1a12dbcc23b76b
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
-
|
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 [
|
6
|
-
1. Review open [
|
7
|
-
1. Report a new [
|
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
|
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
|
-
|
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
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
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](
|
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
|
[](https://rubygems.org/gems/indieweb-endpoints)
|
6
6
|
[](https://rubygems.org/gems/indieweb-endpoints)
|
7
|
-
[](https://codeclimate.com/github/indieweb/indieweb-endpoints-ruby)
|
9
|
-
[](https://codeclimate.com/github/indieweb/indieweb-endpoints-ruby/code)
|
7
|
+
[](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.
|
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.
|
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
|
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
|
-
|
23
|
+
Add indieweb-endpoints-ruby to your project's `Gemfile` and run `bundle install`:
|
26
24
|
|
27
25
|
```ruby
|
28
|
-
source
|
26
|
+
source "https://rubygems.org"
|
29
27
|
|
30
|
-
gem
|
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
|
38
|
+
require "indieweb/endpoints"
|
47
39
|
|
48
|
-
IndieWeb::Endpoints.get(
|
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
|
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
|
51
|
+
require "indieweb/endpoints"
|
60
52
|
|
61
|
-
client = IndieWeb::Endpoints::Client.new(
|
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
|
-
|
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
|
-
|
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).
|
85
|
+
indieweb-endpoints-ruby is freely available under the [MIT License](https://opensource.org/licenses/MIT).
|
data/indieweb-endpoints.gemspec
CHANGED
@@ -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 =
|
4
|
+
spec.required_ruby_version = ">= 2.6"
|
7
5
|
|
8
|
-
spec.name
|
9
|
-
spec.version
|
10
|
-
spec.authors
|
11
|
-
spec.email
|
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
|
14
|
-
spec.description
|
15
|
-
spec.homepage
|
16
|
-
spec.license
|
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
|
19
|
-
spec.files
|
20
|
-
spec.files
|
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 = [
|
20
|
+
spec.require_paths = ["lib"]
|
23
21
|
|
24
22
|
spec.metadata = {
|
25
|
-
|
26
|
-
|
27
|
-
|
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.
|
31
|
-
spec.
|
32
|
-
spec.
|
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:
|
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(
|
16
|
+
# client = IndieWeb::Endpoints::Client.new("https://aaronparecki.com")
|
17
17
|
#
|
18
18
|
# @param url [String, HTTP::URI, #to_s] an absolute URL
|
19
|
-
#
|
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(
|
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).
|
36
|
+
@endpoints ||= Parser.new(response).to_h
|
36
37
|
end
|
37
38
|
|
38
|
-
# The
|
39
|
+
# The {HTTP::Response} object returned by the provided URL.
|
39
40
|
#
|
40
41
|
# @return [HTTP::Response]
|
41
|
-
#
|
42
|
+
#
|
43
|
+
# @raise [HttpError, SSLError]
|
42
44
|
def response
|
43
|
-
@response ||= HTTP
|
44
|
-
|
45
|
-
|
46
|
-
|
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
|
-
# @
|
13
|
-
|
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:
|
16
|
-
|
17
|
-
micropub:
|
18
|
-
microsub:
|
19
|
-
redirect_uri:
|
20
|
-
token_endpoint:
|
21
|
-
webmention:
|
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 [
|
31
|
-
def
|
32
|
-
@
|
57
|
+
# @return [Nokogiri::HTML5::Document]
|
58
|
+
def body
|
59
|
+
@body ||= Nokogiri::HTML5(response.body)
|
33
60
|
end
|
34
61
|
|
35
|
-
# @return [
|
36
|
-
def
|
37
|
-
@
|
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
|
-
# @
|
41
|
-
|
42
|
-
|
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
|
-
|
48
|
-
|
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
|
-
|
74
|
+
body.css(selectors).map { |element| element["href"] }
|
75
|
+
end
|
58
76
|
|
59
|
-
|
60
|
-
|
61
|
-
|
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
|
data/lib/indieweb/endpoints.rb
CHANGED
@@ -1,32 +1,32 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
3
|
+
require "http"
|
4
|
+
require "link-header-parser"
|
5
|
+
require "nokogiri"
|
6
6
|
|
7
|
-
require_relative
|
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 {
|
22
|
+
# Convenience method for {Client#endpoints}.
|
24
23
|
#
|
25
24
|
# @example
|
26
|
-
# IndieWeb::Endpoints.get(
|
25
|
+
# IndieWeb::Endpoints.get("https://aaronparecki.com")
|
26
|
+
#
|
27
|
+
# @param (see Client#initialize)
|
27
28
|
#
|
28
|
-
# @
|
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:
|
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:
|
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.
|
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.
|
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: '
|
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: '
|
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/
|
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
|
-
|
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.
|
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.
|
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
|