indieweb-endpoints 10.1.0 → 10.2.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/.yardopts +5 -0
- data/CONTRIBUTING.md +2 -2
- data/README.md +3 -3
- data/indieweb-endpoints.gemspec +2 -2
- data/lib/indieweb/endpoints/client.rb +39 -26
- data/lib/indieweb/endpoints/exceptions.rb +0 -3
- data/lib/indieweb/endpoints/parser.rb +11 -19
- data/lib/indieweb/endpoints.rb +6 -1
- metadata +6 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 93961d5b2254ded47773579d8b1d357621571be0256c6ccfc5768177703a28c5
|
|
4
|
+
data.tar.gz: 95904542302a29d07aefe58f49095a4db8cacb2a3fb0faca80ddd4a62b8e178d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6b33c1da625391e747d6b8481cff57980d3bb8099b6ff5d286f8d6765bdec91cba5560d9a49d0cc0df51593e94ea8eb0bb42c34a8c6ccd85f6d3d898eeba5234
|
|
7
|
+
data.tar.gz: f4394054e1814421691e981d4b16d6c8568d0f9184f03b74ce88f228687b24ecc10e9de253dc9ad12aeb23342cee77ab8ef39c2844cd2f2f0ec854e20ed207e7
|
data/.yardopts
ADDED
data/CONTRIBUTING.md
CHANGED
|
@@ -8,12 +8,12 @@ There are a couple ways you can help improve indieweb-endpoints-ruby:
|
|
|
8
8
|
|
|
9
9
|
## Getting Started
|
|
10
10
|
|
|
11
|
-
indieweb-endpoints-ruby is developed using Ruby
|
|
11
|
+
indieweb-endpoints-ruby is developed using Ruby 4.0 and is tested against additional Ruby versions using [GitHub Actions](https://github.com/indieweb/indieweb-endpoints-ruby/actions).
|
|
12
12
|
|
|
13
13
|
> [!TIP]
|
|
14
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
15
|
|
|
16
|
-
Before making changes to indieweb-endpoints-ruby, you'll want to install Ruby
|
|
16
|
+
Before making changes to indieweb-endpoints-ruby, you'll want to install Ruby 4.0. Using a Ruby version managment tool like [rv](https://github.com/spinel-coop/rv) or [rbenv](https://github.com/rbenv/rbenv) is recommended. Once you've installed Ruby 4.0 using your method of choice, install the project's gems by running:
|
|
17
17
|
|
|
18
18
|
```sh
|
|
19
19
|
bundle install
|
data/README.md
CHANGED
|
@@ -14,9 +14,9 @@ A Ruby gem for discovering a URL's [IndieAuth](https://indieweb.org/IndieAuth),
|
|
|
14
14
|
|
|
15
15
|
## Getting Started
|
|
16
16
|
|
|
17
|
-
Before installing and using indieweb-endpoints-ruby, you'll want to have [Ruby](https://www.ruby-lang.org) 2.7 (or newer) installed. Using a Ruby version managment tool like [
|
|
17
|
+
Before installing and using indieweb-endpoints-ruby, you'll want to have [Ruby](https://www.ruby-lang.org) 2.7 (or newer) installed. Using a Ruby version managment tool like [rv](https://github.com/spinel-coop/rv) or [rbenv](https://github.com/rbenv/rbenv) is recommended.
|
|
18
18
|
|
|
19
|
-
indieweb-endpoints-ruby is developed using Ruby
|
|
19
|
+
indieweb-endpoints-ruby is developed using Ruby 4.0 and is tested against additional Ruby versions using [GitHub Actions](https://github.com/indieweb/indieweb-endpoints-ruby/actions).
|
|
20
20
|
|
|
21
21
|
## Installation
|
|
22
22
|
|
|
@@ -70,7 +70,7 @@ indieweb-endpoints-ruby may raise the following exceptions which are subclasses
|
|
|
70
70
|
|
|
71
71
|
## Contributing
|
|
72
72
|
|
|
73
|
-
See [CONTRIBUTING.md](
|
|
73
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for more on how to contribute to indieweb-endpoints-ruby. Your help is greatly appreciated!
|
|
74
74
|
|
|
75
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).
|
|
76
76
|
|
data/indieweb-endpoints.gemspec
CHANGED
|
@@ -4,7 +4,7 @@ Gem::Specification.new do |spec|
|
|
|
4
4
|
spec.required_ruby_version = ">= 2.7"
|
|
5
5
|
|
|
6
6
|
spec.name = "indieweb-endpoints"
|
|
7
|
-
spec.version = "10.
|
|
7
|
+
spec.version = "10.2.0"
|
|
8
8
|
spec.authors = ["Jason Garber"]
|
|
9
9
|
spec.email = ["jason@sixtwothree.org"]
|
|
10
10
|
|
|
@@ -14,7 +14,7 @@ Gem::Specification.new do |spec|
|
|
|
14
14
|
spec.license = "MIT"
|
|
15
15
|
|
|
16
16
|
spec.files = Dir["lib/**/*"].reject { |f| File.directory?(f) }
|
|
17
|
-
spec.files += ["LICENSE", "CHANGELOG.md", "CODE_OF_CONDUCT.md", "CONTRIBUTING.md", "README.md"]
|
|
17
|
+
spec.files += [".yardopts", "LICENSE", "CHANGELOG.md", "CODE_OF_CONDUCT.md", "CONTRIBUTING.md", "README.md"]
|
|
18
18
|
spec.files += ["indieweb-endpoints.gemspec"]
|
|
19
19
|
|
|
20
20
|
spec.require_paths = ["lib"]
|
|
@@ -2,13 +2,34 @@
|
|
|
2
2
|
|
|
3
3
|
module IndieWeb
|
|
4
4
|
module Endpoints
|
|
5
|
+
# A client interface to parse IndieWeb endpoints from a URL.
|
|
5
6
|
class Client
|
|
6
|
-
#
|
|
7
|
+
# Set defaults derived from Webmention specification examples.
|
|
8
|
+
#
|
|
9
|
+
# @see https://www.w3.org/TR/webmention/#limits-on-get-requests
|
|
10
|
+
# W3C Webmention Recommendation § 4.2 Limits on GET requests
|
|
11
|
+
HTTP_CLIENT_OPTS = {
|
|
12
|
+
follow: {
|
|
13
|
+
max_hops: 20,
|
|
14
|
+
},
|
|
15
|
+
headers: {
|
|
16
|
+
accept: "*/*",
|
|
17
|
+
user_agent: "Mozilla/5.0 (compatible; IndieWebEndpointsDiscovery/1.0; +https://rubygems.org/gems/indieweb-endpoints)",
|
|
18
|
+
},
|
|
19
|
+
timeout_options: {
|
|
20
|
+
connect_timeout: 5,
|
|
21
|
+
read_timeout: 5,
|
|
22
|
+
},
|
|
23
|
+
}.freeze
|
|
24
|
+
|
|
25
|
+
private_constant :HTTP_CLIENT_OPTS
|
|
26
|
+
|
|
27
|
+
# Create a new {Client} to parse a URL for IndieWeb endpoints.
|
|
7
28
|
#
|
|
8
29
|
# @example
|
|
9
|
-
#
|
|
30
|
+
# IndieWeb::Endpoints::Client.new("https://aaronparecki.com")
|
|
10
31
|
#
|
|
11
|
-
# @param url [String, HTTP::URI, #to_s]
|
|
32
|
+
# @param url [String, HTTP::URI, #to_s] An absolute URL.
|
|
12
33
|
#
|
|
13
34
|
# @raise [InvalidURIError]
|
|
14
35
|
def initialize(url)
|
|
@@ -17,35 +38,30 @@ module IndieWeb
|
|
|
17
38
|
raise InvalidURIError, e
|
|
18
39
|
end
|
|
19
40
|
|
|
20
|
-
#
|
|
21
|
-
#
|
|
41
|
+
# @!visibility private
|
|
42
|
+
# simplecov:disable
|
|
22
43
|
def inspect
|
|
23
|
-
format
|
|
24
|
-
class: self.class,
|
|
25
|
-
id: object_id << 1,
|
|
26
|
-
uri: uri.inspect
|
|
44
|
+
"#<#{self.class}:#{format("%#0x", object_id)} @uri: #{@uri.inspect}>"
|
|
27
45
|
end
|
|
28
|
-
# :
|
|
46
|
+
# simplecov:enable
|
|
29
47
|
|
|
30
|
-
#
|
|
48
|
+
# The IndieWeb endpoints advertised by the provided URL.i
|
|
49
|
+
#
|
|
50
|
+
# @example
|
|
51
|
+
# IndieWeb::Endpoints::Client.new("https://aaronparecki.com").endpoints
|
|
31
52
|
#
|
|
32
53
|
# @return [Hash{Symbol => String, Array, nil}]
|
|
33
54
|
def endpoints
|
|
34
55
|
@endpoints ||= Parser.new(response).to_h
|
|
35
56
|
end
|
|
36
57
|
|
|
37
|
-
# The
|
|
38
|
-
#
|
|
39
|
-
# @return [HTTP::Response]
|
|
58
|
+
# The `HTTP::Response` object for the provided URL.
|
|
40
59
|
#
|
|
41
60
|
# @raise [HttpError, SSLError]
|
|
61
|
+
#
|
|
62
|
+
# @return [HTTP::Response]
|
|
42
63
|
def response
|
|
43
|
-
@response ||=
|
|
44
|
-
HTTP
|
|
45
|
-
.follow(max_hops: 20)
|
|
46
|
-
.headers(accept: "*/*", user_agent: user_agent)
|
|
47
|
-
.timeout(connect: 5, read: 5)
|
|
48
|
-
.get(uri)
|
|
64
|
+
@response ||= client.request(:get, @uri)
|
|
49
65
|
rescue HTTP::Error => e
|
|
50
66
|
raise HttpError, e
|
|
51
67
|
rescue OpenSSL::SSL::SSLError => e
|
|
@@ -54,12 +70,9 @@ module IndieWeb
|
|
|
54
70
|
|
|
55
71
|
private
|
|
56
72
|
|
|
57
|
-
# @return [HTTP::
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
# @return [String]
|
|
61
|
-
def user_agent
|
|
62
|
-
"Mozilla/5.0 (compatible; IndieWebEndpointsDiscovery/1.0; +https://rubygems.org/gems/indieweb-endpoints)"
|
|
73
|
+
# @return [HTTP::Client]
|
|
74
|
+
def client
|
|
75
|
+
@client ||= HTTP::Client.new(HTTP_CLIENT_OPTS)
|
|
63
76
|
end
|
|
64
77
|
end
|
|
65
78
|
end
|
|
@@ -2,19 +2,24 @@
|
|
|
2
2
|
|
|
3
3
|
module IndieWeb
|
|
4
4
|
module Endpoints
|
|
5
|
+
# A parser for extracting IndieWeb endpoints from an `HTTP::Response`
|
|
6
|
+
# instance's headers and body.
|
|
7
|
+
#
|
|
5
8
|
# @api private
|
|
6
9
|
class Parser
|
|
7
10
|
# @param response [HTTP::Response]
|
|
8
11
|
def initialize(response)
|
|
9
|
-
@
|
|
12
|
+
@body = Nokogiri::HTML5(response.body, response.uri.to_s).resolve_urls!
|
|
13
|
+
@headers = LinkHeaderParser.parse(response.headers.get("link"), base_uri: response.uri).group_by_relation_type
|
|
14
|
+
@mime_type = response.mime_type
|
|
10
15
|
end
|
|
11
16
|
|
|
12
17
|
# @param identifier [String]
|
|
13
18
|
# @param node_names [Array<String>]
|
|
14
19
|
#
|
|
15
|
-
# @return [Array<String>]
|
|
16
|
-
#
|
|
17
20
|
# @raise [InvalidURIError]
|
|
21
|
+
#
|
|
22
|
+
# @return [Array<String>]
|
|
18
23
|
def matches(identifier, node_names: ["link"])
|
|
19
24
|
results = (matches_from_headers(identifier) + matches_from_body(identifier, node_names)).compact
|
|
20
25
|
|
|
@@ -46,19 +51,6 @@ module IndieWeb
|
|
|
46
51
|
|
|
47
52
|
private
|
|
48
53
|
|
|
49
|
-
# @return [HTTP::Response]
|
|
50
|
-
attr_reader :response
|
|
51
|
-
|
|
52
|
-
# @return [Nokogiri::HTML5::Document]
|
|
53
|
-
def body
|
|
54
|
-
@body ||= Nokogiri::HTML5(response.body, response.uri.to_s).resolve_urls!
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
# @return [Hash{Symbol => Array<LinkHeaderParser::LinkHeader>}]
|
|
58
|
-
def headers
|
|
59
|
-
@headers ||= LinkHeaderParser.parse(response.headers.get("link"), base_uri: response.uri).group_by_relation_type
|
|
60
|
-
end
|
|
61
|
-
|
|
62
54
|
# Reject URLs with fragment identifiers per the IndieAuth specification.
|
|
63
55
|
#
|
|
64
56
|
# @param identifier [String, #to_s]
|
|
@@ -66,9 +58,9 @@ module IndieWeb
|
|
|
66
58
|
#
|
|
67
59
|
# @return [Array<String>]
|
|
68
60
|
def matches_from_body(identifier, node_names)
|
|
69
|
-
return [] unless
|
|
61
|
+
return [] unless @mime_type == "text/html"
|
|
70
62
|
|
|
71
|
-
body
|
|
63
|
+
@body
|
|
72
64
|
.css(*node_names.map { |node| %(#{node}[rel~="#{identifier}"][href]:not([href*="#"]) / @href) })
|
|
73
65
|
.map(&:value)
|
|
74
66
|
end
|
|
@@ -79,7 +71,7 @@ module IndieWeb
|
|
|
79
71
|
#
|
|
80
72
|
# @return [Array<String>]
|
|
81
73
|
def matches_from_headers(identifier)
|
|
82
|
-
Array(headers[identifier]).filter_map do |header|
|
|
74
|
+
Array(@headers[identifier]).filter_map do |header|
|
|
83
75
|
header.target_uri unless HTTP::URI.parse(header.target_uri).fragment
|
|
84
76
|
end
|
|
85
77
|
end
|
data/lib/indieweb/endpoints.rb
CHANGED
|
@@ -5,11 +5,14 @@ require "link-header-parser"
|
|
|
5
5
|
require "nokogiri/html-ext"
|
|
6
6
|
|
|
7
7
|
require_relative "endpoints/exceptions"
|
|
8
|
-
|
|
9
8
|
require_relative "endpoints/client"
|
|
10
9
|
require_relative "endpoints/parser"
|
|
11
10
|
|
|
11
|
+
# Welcome to the IndieWeb, a people-focused alternative to the "corporate web."
|
|
12
|
+
#
|
|
13
|
+
# @see https://indieweb.org
|
|
12
14
|
module IndieWeb
|
|
15
|
+
# @see https://indieweb.org/endpoint
|
|
13
16
|
module Endpoints
|
|
14
17
|
# Discover a URL's IndieAuth, Micropub, Microsub, and Webmention endpoints.
|
|
15
18
|
#
|
|
@@ -20,6 +23,8 @@ module IndieWeb
|
|
|
20
23
|
#
|
|
21
24
|
# @param (see Client#initialize)
|
|
22
25
|
#
|
|
26
|
+
# @raise (see Client#initialize)
|
|
27
|
+
#
|
|
23
28
|
# @return (see Client#endpoints)
|
|
24
29
|
def self.get(url)
|
|
25
30
|
Client.new(url).endpoints
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: indieweb-endpoints
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 10.
|
|
4
|
+
version: 10.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jason Garber
|
|
@@ -64,6 +64,7 @@ executables: []
|
|
|
64
64
|
extensions: []
|
|
65
65
|
extra_rdoc_files: []
|
|
66
66
|
files:
|
|
67
|
+
- ".yardopts"
|
|
67
68
|
- CHANGELOG.md
|
|
68
69
|
- CODE_OF_CONDUCT.md
|
|
69
70
|
- CONTRIBUTING.md
|
|
@@ -79,11 +80,11 @@ licenses:
|
|
|
79
80
|
- MIT
|
|
80
81
|
metadata:
|
|
81
82
|
bug_tracker_uri: https://github.com/indieweb/indieweb-endpoints-ruby/issues
|
|
82
|
-
changelog_uri: https://github.com/indieweb/indieweb-endpoints-ruby/releases/tag/v10.
|
|
83
|
-
documentation_uri: https://rubydoc.info/gems/indieweb-endpoints/10.
|
|
83
|
+
changelog_uri: https://github.com/indieweb/indieweb-endpoints-ruby/releases/tag/v10.2.0
|
|
84
|
+
documentation_uri: https://rubydoc.info/gems/indieweb-endpoints/10.2.0
|
|
84
85
|
homepage_uri: https://github.com/indieweb/indieweb-endpoints-ruby
|
|
85
86
|
rubygems_mfa_required: 'true'
|
|
86
|
-
source_code_uri: https://github.com/indieweb/indieweb-endpoints-ruby/tree/v10.
|
|
87
|
+
source_code_uri: https://github.com/indieweb/indieweb-endpoints-ruby/tree/v10.2.0
|
|
87
88
|
rdoc_options: []
|
|
88
89
|
require_paths:
|
|
89
90
|
- lib
|
|
@@ -98,7 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
98
99
|
- !ruby/object:Gem::Version
|
|
99
100
|
version: '0'
|
|
100
101
|
requirements: []
|
|
101
|
-
rubygems_version: 4.0.
|
|
102
|
+
rubygems_version: 4.0.20
|
|
102
103
|
specification_version: 4
|
|
103
104
|
summary: Discover a URL’s IndieAuth, Micropub, Microsub, and Webmention endpoints.
|
|
104
105
|
test_files: []
|