webmention 8.0.0 → 9.0.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/CONTRIBUTING.md +13 -10
- data/README.md +5 -16
- data/USAGE.md +10 -11
- data/lib/webmention/client.rb +16 -18
- data/lib/webmention/error_response.rb +5 -7
- data/lib/webmention/parser.rb +1 -1
- data/lib/webmention/parsers/html_parser.rb +9 -10
- data/lib/webmention/parsers/plaintext_parser.rb +1 -1
- data/lib/webmention/request.rb +19 -18
- data/lib/webmention/response.rb +5 -7
- data/lib/webmention/url.rb +3 -5
- data/lib/webmention/verification.rb +16 -10
- data/lib/webmention.rb +15 -17
- data/webmention.gemspec +12 -12
- metadata +15 -17
- data/lib/webmention/version.rb +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 68b2e3b667fedde2265819a6c01a0b547b3a8503389a5209e2b9ce600b50945a
|
4
|
+
data.tar.gz: 622770cbe635b33de6125be189bf43a9cd23bbfff223f8897198862a463e6007
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8be2cd5b737f7ea3c6321373ac41cc53f73830b5f01163591485ec0d1f2138bb133cb9eee39f57d82bb1c5e9871b435f8acbc0a7cf190f2bc55c84b7cfd56006
|
7
|
+
data.tar.gz: 2415239ef05fdd79ce8e417c4071f21bab937487ad499f2ac53c681f0605b986f4922a3b3c1204bfae10cade9916d3e6394ebd5661b03a438a096911ac3ace5d
|
data/CONTRIBUTING.md
CHANGED
@@ -8,9 +8,12 @@ There are a couple ways you can help improve webmention-client-ruby:
|
|
8
8
|
|
9
9
|
## Getting Started
|
10
10
|
|
11
|
-
webmention-client-ruby is developed using Ruby 3.
|
11
|
+
webmention-client-ruby is developed using Ruby 3.4 and is tested against additional Ruby versions using [GitHub Actions](https://github.com/indieweb/webmention-client-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 webmention-client-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 webmention-client-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 `bin/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
@@ -12,12 +12,13 @@
|
|
12
12
|
- Perform [endpoint discovery](https://www.w3.org/TR/webmention/#sender-discovers-receiver-webmention-endpoint) on mentioned URLs.
|
13
13
|
- Send webmentions to one or more mentioned URLs (and optionally include a [vouch](https://indieweb.org/Vouch) URL).
|
14
14
|
- Verify that a received webmention's source URL links to a target URL (and optionally verify that a vouch URL mentions the source URL's domain).
|
15
|
+
- Supports Ruby 2.7 and newer.
|
15
16
|
|
16
17
|
## Getting Started
|
17
18
|
|
18
|
-
Before installing and using webmention-client-ruby, you'll want to have [Ruby](https://www.ruby-lang.org)
|
19
|
+
Before installing and using webmention-client-ruby, you'll want to have [Ruby](https://www.ruby-lang.org) 2.7 (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.
|
19
20
|
|
20
|
-
webmention-client-ruby is developed using Ruby 3.
|
21
|
+
webmention-client-ruby is developed using Ruby 3.4 and is tested against additional Ruby versions using [GitHub Actions](https://github.com/indieweb/webmention-client-ruby/actions).
|
21
22
|
|
22
23
|
## Installation
|
23
24
|
|
@@ -26,24 +27,12 @@ Add webmention-client-ruby to your project's `Gemfile` and run `bundle install`:
|
|
26
27
|
```ruby
|
27
28
|
source "https://rubygems.org"
|
28
29
|
|
29
|
-
gem "webmention
|
30
|
+
gem "webmention"
|
30
31
|
```
|
31
32
|
|
32
33
|
## Usage
|
33
34
|
|
34
|
-
See [USAGE.md](
|
35
|
-
|
36
|
-
## Migrating to version 6
|
37
|
-
|
38
|
-
webmention-client-ruby was completely rewritten for version 6 to better support new features and future development. Some notes on migrating to the new version:
|
39
|
-
|
40
|
-
♻️ **Renamed:** for clarity and consistency, the `Webmention.send_mention` method has been renamed `Webmention.send_webmention`. Both methods use the same interface.
|
41
|
-
|
42
|
-
❌ **Removed:** the `Webmention.client` method has been removed in favor of the additional module methods [noted above](#usage). While the underlying `Webmention::Client` class still exists, its interface has changed and its direct usage is generally unnecessary.
|
43
|
-
|
44
|
-
❌ **Removed:** `Webmention::Client#send_all_mentions` has been removed in favor of `Webmention.send_webmentions`. Combine `Webmention.mentioned_urls` and `Webmention.send_webmentions` to achieve similar results.
|
45
|
-
|
46
|
-
🛠 **Refactored:** Exception handling has been greatly improved [as noted above](#exception-handling).
|
35
|
+
See [USAGE.md](USAGE.md) for documentation of webmention-client-ruby's features.
|
47
36
|
|
48
37
|
## Contributing
|
49
38
|
|
data/USAGE.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# Using webmention-client-ruby
|
2
2
|
|
3
|
-
|
3
|
+
> [!NOTE]
|
4
|
+
> Before using webmention-client-ruby, please read the [Getting Started](README.md#getting-started) and [Installation](README.md#installation) sections of the project's [README.md](README.md).
|
4
5
|
|
5
6
|
## Sending a webmention
|
6
7
|
|
@@ -15,9 +16,7 @@ target = "https://aaronpk.example/post/100" # A post on someone else's website
|
|
15
16
|
response = Webmention.send_webmention(source, target)
|
16
17
|
```
|
17
18
|
|
18
|
-
`Webmention.send_webmention` will return either a `Webmention::Response` or a `Webmention::ErrorResponse`. Instances of both classes respond to `ok?`. Building on the examples above:
|
19
|
-
|
20
|
-
A `Webmention::ErrorResponse` may be returned when:
|
19
|
+
`Webmention.send_webmention` will return either a `Webmention::Response` or a `Webmention::ErrorResponse`. Instances of both classes respond to `ok?`. Building on the examples above, a `Webmention::ErrorResponse` may be returned when:
|
21
20
|
|
22
21
|
1. The target URL does not advertise a Webmention endpoint.
|
23
22
|
2. The request to the target URL raises an `HTTP::Error` or an `OpenSSL::SSL::SSLError`.
|
@@ -54,7 +53,8 @@ response.mime_type #=> String
|
|
54
53
|
response.uri #=> HTTP::URI
|
55
54
|
```
|
56
55
|
|
57
|
-
|
56
|
+
> [!NOTE]
|
57
|
+
> `Webmention::Response` objects may return a variety of status codes that will vary depending on the endpoint's capabilities and the success or failure of the request. See [the Webmention spec](https://www.w3.org/TR/webmention/) for more on status codes on their implications. A `Webmention::Response` responding affirmatively to `ok?` _may_ also have a non-successful HTTP status code (e.g. `404 Not Found`).
|
58
58
|
|
59
59
|
## Sending multiple webmentions
|
60
60
|
|
@@ -93,7 +93,8 @@ urls = Webmention.mentioned_urls("https://jgarber.example/post/100")
|
|
93
93
|
|
94
94
|
When parsing HTML documents, webmention-client-ruby will find the first [h-entry](https://microformats.org/wiki/h-entry) and search its markup for URLs. If no h-entry is found, the parser will search the document's `<body>`.
|
95
95
|
|
96
|
-
|
96
|
+
> [!NOTE]
|
97
|
+
> Links pointing to the supplied URL (or those with internal fragment identifiers) will be rejected. You may wish to additionally filter the results returned by `Webmention.mentioned_urls` before sending webmentions.
|
97
98
|
|
98
99
|
## Verifying a webmention
|
99
100
|
|
@@ -141,13 +142,11 @@ verification.verify_vouch?
|
|
141
142
|
verification.vouch_mentions_source?
|
142
143
|
```
|
143
144
|
|
144
|
-
|
145
|
+
> [!NOTE]
|
146
|
+
> `Webmention.verify_webmention` parses HTML documents using the same rules outlined in [Discovering mentioned URLs](#discovering-mentioned-urls).
|
145
147
|
|
146
148
|
## Exception Handling
|
147
149
|
|
148
150
|
webmention-client-ruby avoids raising exceptions when making HTTP requests. As noted above, a `Webmention::ErrorResponse` should be returned in cases where an HTTP request triggers an exception.
|
149
151
|
|
150
|
-
When crawling the supplied URL, `Webmention.mentioned_urls` _may_ raise a `NoMethodError` if
|
151
|
-
|
152
|
-
- a `Webmention::ErrorResponse` is returned, or
|
153
|
-
- the response is of an unsupported MIME type.
|
152
|
+
When crawling the supplied URL, `Webmention.mentioned_urls` _may_ raise a `NoMethodError` if a `Webmention::ErrorResponse` is returned, or the response is of an unsupported MIME type.
|
data/lib/webmention/client.rb
CHANGED
@@ -9,10 +9,10 @@ module Webmention
|
|
9
9
|
attr_reader :registered_parsers
|
10
10
|
end
|
11
11
|
|
12
|
-
# @return [
|
12
|
+
# @return [Url]
|
13
13
|
attr_reader :source_url
|
14
14
|
|
15
|
-
# @return [
|
15
|
+
# @return [Url]
|
16
16
|
attr_reader :vouch_url
|
17
17
|
|
18
18
|
# @api private
|
@@ -20,21 +20,19 @@ module Webmention
|
|
20
20
|
klass.mime_types.each { |mime_type| @registered_parsers[mime_type] = klass }
|
21
21
|
end
|
22
22
|
|
23
|
-
# Create a new
|
23
|
+
# Create a new {Client}.
|
24
24
|
#
|
25
25
|
# @example
|
26
|
-
# Webmention::Client.new(
|
26
|
+
# Webmention::Client.new("https://jgarber.example/posts/100")
|
27
27
|
#
|
28
28
|
# @example
|
29
|
-
# Webmention::Client.new(
|
29
|
+
# Webmention::Client.new("https://jgarber.example/posts/100", vouch: "https://tantek.example/notes/1")
|
30
30
|
#
|
31
31
|
# @param source [String, HTTP::URI, #to_s]
|
32
32
|
# An absolute URL representing a source document.
|
33
33
|
# @param vouch [String, HTTP::URI, #to_s]
|
34
34
|
# An absolute URL representing a document vouching for the source document.
|
35
35
|
# See https://indieweb.org/Vouch for additional details.
|
36
|
-
#
|
37
|
-
# @return [Webmention::Client]
|
38
36
|
def initialize(source, vouch: nil)
|
39
37
|
@source_url = Url.new(source)
|
40
38
|
@vouch_url = Url.new(vouch)
|
@@ -52,11 +50,11 @@ module Webmention
|
|
52
50
|
# Retrieve unique URLs mentioned by this client's source URL.
|
53
51
|
#
|
54
52
|
# @example
|
55
|
-
# client = Webmention::Client.new(
|
53
|
+
# client = Webmention::Client.new("https://jgarber.example/posts/100")
|
56
54
|
# client.mentioned_urls
|
57
55
|
#
|
58
56
|
# @raise [NoMethodError]
|
59
|
-
# Raised when response is
|
57
|
+
# Raised when response is an {ErrorResponse} or response is of an
|
60
58
|
# unsupported MIME type.
|
61
59
|
#
|
62
60
|
# @return [Array<String>]
|
@@ -78,13 +76,13 @@ module Webmention
|
|
78
76
|
# Send a webmention from this client's source URL to a target URL.
|
79
77
|
#
|
80
78
|
# @example
|
81
|
-
# client = Webmention::Client.new(
|
82
|
-
# client.send_webmention(
|
79
|
+
# client = Webmention::Client.new("https://jgarber.example/posts/100")
|
80
|
+
# client.send_webmention("https://aaronpk.example/notes/1")
|
83
81
|
#
|
84
82
|
# @param target [String, HTTP::URI, #to_s]
|
85
83
|
# An absolute URL representing a target document.
|
86
84
|
#
|
87
|
-
# @return [
|
85
|
+
# @return [Response, ErrorResponse]
|
88
86
|
def send_webmention(target)
|
89
87
|
target_url = Url.new(target)
|
90
88
|
|
@@ -103,14 +101,14 @@ module Webmention
|
|
103
101
|
# Send webmentions from this client's source URL to multiple target URLs.
|
104
102
|
#
|
105
103
|
# @example
|
106
|
-
# client = Webmention::Client.new(
|
107
|
-
# targets = [
|
104
|
+
# client = Webmention::Client.new("https://jgarber.example/posts/100")
|
105
|
+
# targets = ["https://aaronpk.example/notes/1", "https://adactio.example/notes/1"]
|
108
106
|
# client.send_webmentions(targets)
|
109
107
|
#
|
110
108
|
# @param targets [Array<String, HTTP::URI, #to_s>]
|
111
109
|
# An array of absolute URLs representing multiple target documents.
|
112
110
|
#
|
113
|
-
# @return [Array<
|
111
|
+
# @return [Array<Response, ErrorResponse>]
|
114
112
|
def send_webmentions(*targets)
|
115
113
|
targets.map { |target| send_webmention(target) }
|
116
114
|
end
|
@@ -120,9 +118,9 @@ module Webmention
|
|
120
118
|
# @param target [String, HTTP::URI, #to_s]
|
121
119
|
# An absolute URL representing a target document.
|
122
120
|
#
|
123
|
-
# @raise (see
|
121
|
+
# @raise (see Client#mentioned_urls)
|
124
122
|
#
|
125
|
-
# @return [
|
123
|
+
# @return [Verification]
|
126
124
|
def verify_webmention(target)
|
127
125
|
Verification.new(source_url, Url.new(target), vouch_url: vouch_url)
|
128
126
|
end
|
@@ -136,7 +134,7 @@ module Webmention
|
|
136
134
|
opts = {
|
137
135
|
source: source_url,
|
138
136
|
target: target,
|
139
|
-
vouch: vouch_url
|
137
|
+
vouch: vouch_url,
|
140
138
|
}
|
141
139
|
|
142
140
|
opts.transform_values! { |value| value.to_s.strip }
|
@@ -5,20 +5,18 @@ module Webmention
|
|
5
5
|
# @return [String]
|
6
6
|
attr_reader :message
|
7
7
|
|
8
|
-
# @return [
|
8
|
+
# @return [Request]
|
9
9
|
attr_reader :request
|
10
10
|
|
11
|
-
# Create a new
|
11
|
+
# Create a new {ErrorResponse}.
|
12
12
|
#
|
13
13
|
# Instances of this class represent HTTP requests that generated errors
|
14
14
|
# (e.g. connection error, SSL error) or that could not locate a Webmention
|
15
|
-
# endpoint. The nature of the error is captured in the
|
16
|
-
#
|
15
|
+
# endpoint. The nature of the error is captured in the {#message} instance
|
16
|
+
# method.
|
17
17
|
#
|
18
18
|
# @param message [String]
|
19
|
-
# @param request [
|
20
|
-
#
|
21
|
-
# @return [Webmention::ErrorResponse]
|
19
|
+
# @param request [Request]
|
22
20
|
def initialize(message, request)
|
23
21
|
@message = message
|
24
22
|
@request = request
|
data/lib/webmention/parser.rb
CHANGED
@@ -9,17 +9,16 @@ module Webmention
|
|
9
9
|
Client.register_parser(self)
|
10
10
|
|
11
11
|
HTML_ATTRIBUTES_MAP = {
|
12
|
-
"cite" =>
|
13
|
-
"data" =>
|
14
|
-
"href" =>
|
15
|
-
"poster" =>
|
16
|
-
"src" =>
|
17
|
-
"srcset" =>
|
12
|
+
"cite" => ["blockquote", "del", "ins", "q"],
|
13
|
+
"data" => ["object"],
|
14
|
+
"href" => ["a", "area"],
|
15
|
+
"poster" => ["video"],
|
16
|
+
"src" => ["audio", "embed", "img", "source", "track", "video"],
|
17
|
+
"srcset" => ["img", "source"],
|
18
18
|
}.freeze
|
19
19
|
|
20
|
-
CSS_SELECTORS_ARRAY = HTML_ATTRIBUTES_MAP
|
21
|
-
|
22
|
-
end.freeze
|
20
|
+
CSS_SELECTORS_ARRAY = HTML_ATTRIBUTES_MAP
|
21
|
+
.flat_map { |attribute, names| names.map { |name| "#{name}[#{attribute}]" } }.freeze
|
23
22
|
|
24
23
|
ROOT_NODE_SELECTORS_ARRAY = [".h-entry .e-content", ".h-entry", "body"].freeze
|
25
24
|
|
@@ -62,7 +61,7 @@ module Webmention
|
|
62
61
|
|
63
62
|
# @return [Array<Nokogiri::XML::Attr>]
|
64
63
|
def url_attributes
|
65
|
-
url_nodes.flat_map(&:attribute_nodes).
|
64
|
+
url_nodes.flat_map(&:attribute_nodes).select { |attribute| HTML_ATTRIBUTES_MAP.key?(attribute.name) }
|
66
65
|
end
|
67
66
|
|
68
67
|
# @return [Nokogiri::XML::NodeSet]
|
@@ -10,7 +10,7 @@ module Webmention
|
|
10
10
|
|
11
11
|
# @return [Array<String>] An array of absolute URLs.
|
12
12
|
def results
|
13
|
-
@results ||= URI::DEFAULT_PARSER.extract(response_body,
|
13
|
+
@results ||= URI::DEFAULT_PARSER.extract(response_body, ["http", "https"])
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
data/lib/webmention/request.rb
CHANGED
@@ -2,20 +2,22 @@
|
|
2
2
|
|
3
3
|
module Webmention
|
4
4
|
class Request
|
5
|
-
#
|
5
|
+
# Set defaults derived from Webmention specification examples.
|
6
|
+
#
|
6
7
|
# @see https://www.w3.org/TR/webmention/#limits-on-get-requests
|
8
|
+
# W3C Webmention Recommendation § 4.2 Limits on GET requests
|
7
9
|
HTTP_CLIENT_OPTS = {
|
8
10
|
follow: {
|
9
|
-
max_hops: 20
|
11
|
+
max_hops: 20,
|
10
12
|
},
|
11
13
|
headers: {
|
12
14
|
accept: "*/*",
|
13
|
-
user_agent: "Webmention Client (https://rubygems.org/gems/webmention)"
|
15
|
+
user_agent: "Webmention Client (https://rubygems.org/gems/webmention)",
|
14
16
|
},
|
15
17
|
timeout_options: {
|
16
18
|
connect_timeout: 5,
|
17
|
-
read_timeout: 5
|
18
|
-
}
|
19
|
+
read_timeout: 5,
|
20
|
+
},
|
19
21
|
}.freeze
|
20
22
|
|
21
23
|
private_constant :HTTP_CLIENT_OPTS
|
@@ -32,11 +34,11 @@ module Webmention
|
|
32
34
|
# Send an HTTP GET request to the supplied URL.
|
33
35
|
#
|
34
36
|
# @example
|
35
|
-
# Request.get(
|
37
|
+
# Webmention::Request.get("https://jgarber.example/posts/100")
|
36
38
|
#
|
37
39
|
# @param url [String]
|
38
40
|
#
|
39
|
-
# @return [
|
41
|
+
# @return [Response, ErrorResponse]
|
40
42
|
def self.get(url)
|
41
43
|
new(:get, url).perform
|
42
44
|
end
|
@@ -44,11 +46,11 @@ module Webmention
|
|
44
46
|
# Send an HTTP POST request with form-encoded data to the supplied URL.
|
45
47
|
#
|
46
48
|
# @example
|
47
|
-
# Request.post(
|
48
|
-
#
|
49
|
-
# source:
|
50
|
-
# target:
|
51
|
-
# vouch:
|
49
|
+
# Webmention::Request.post(
|
50
|
+
# "https://aaronpk.example/webmention",
|
51
|
+
# source: "https://jgarber.examples/posts/100",
|
52
|
+
# target: "https://aaronpk.example/notes/1",
|
53
|
+
# vouch: "https://tantek.example/notes/1"
|
52
54
|
# )
|
53
55
|
#
|
54
56
|
# @param url [String]
|
@@ -61,18 +63,16 @@ module Webmention
|
|
61
63
|
# An absolute URL representing a document vouching for the source document.
|
62
64
|
# See https://indieweb.org/Vouch for additional details.
|
63
65
|
#
|
64
|
-
# @return [
|
66
|
+
# @return [Response, ErrorResponse]
|
65
67
|
def self.post(url, **options)
|
66
68
|
new(:post, url, form: options.slice(:source, :target, :vouch)).perform
|
67
69
|
end
|
68
70
|
|
69
|
-
# Create a new
|
71
|
+
# Create a new {Request}.
|
70
72
|
#
|
71
73
|
# @param method [Symbol]
|
72
74
|
# @param url [String]
|
73
75
|
# @param options [Hash{Symbol => String}]
|
74
|
-
#
|
75
|
-
# @return [Webmention::Request]
|
76
76
|
def initialize(method, url, **options)
|
77
77
|
@method = method.to_sym
|
78
78
|
@uri = HTTP::URI.parse(url.to_s)
|
@@ -88,9 +88,9 @@ module Webmention
|
|
88
88
|
end
|
89
89
|
# :nocov:
|
90
90
|
|
91
|
-
# Submit the
|
91
|
+
# Submit the {Request}.
|
92
92
|
#
|
93
|
-
# @return [
|
93
|
+
# @return [Response, ErrorResponse]
|
94
94
|
def perform
|
95
95
|
Response.new(client.request(method, uri, options), self)
|
96
96
|
rescue HTTP::Error, OpenSSL::SSL::SSLError => e
|
@@ -99,6 +99,7 @@ module Webmention
|
|
99
99
|
|
100
100
|
private
|
101
101
|
|
102
|
+
# @return [HTTP::Client]
|
102
103
|
def client
|
103
104
|
@client ||= HTTP::Client.new(HTTP_CLIENT_OPTS)
|
104
105
|
end
|
data/lib/webmention/response.rb
CHANGED
@@ -4,7 +4,7 @@ module Webmention
|
|
4
4
|
class Response
|
5
5
|
extend Forwardable
|
6
6
|
|
7
|
-
# @return [
|
7
|
+
# @return [Request]
|
8
8
|
attr_reader :request
|
9
9
|
|
10
10
|
# @!method
|
@@ -31,16 +31,14 @@ module Webmention
|
|
31
31
|
# @return [HTTP::URI]
|
32
32
|
def_delegator :@response, :uri
|
33
33
|
|
34
|
-
# Create a new
|
34
|
+
# Create a new {Response}.
|
35
35
|
#
|
36
36
|
# Instances of this class represent completed HTTP requests, the details
|
37
|
-
# of which may be accessed using the delegated
|
38
|
-
#
|
37
|
+
# of which may be accessed using the delegated {#code} and {#reason}
|
38
|
+
# instance methods.
|
39
39
|
#
|
40
40
|
# @param response [HTTP::Response]
|
41
|
-
# @param request [
|
42
|
-
#
|
43
|
-
# @return [Webmention::Response]
|
41
|
+
# @param request [Request]
|
44
42
|
def initialize(response, request)
|
45
43
|
@response = response
|
46
44
|
@request = request
|
data/lib/webmention/url.rb
CHANGED
@@ -11,11 +11,9 @@ module Webmention
|
|
11
11
|
# @return [String]
|
12
12
|
def_delegator :uri, :to_s
|
13
13
|
|
14
|
-
# Create a new
|
14
|
+
# Create a new {Url}.
|
15
15
|
#
|
16
16
|
# @param url [String, HTTP::URI, #to_s] An absolute URL.
|
17
|
-
#
|
18
|
-
# @return [Webmention::Url]
|
19
17
|
def initialize(url)
|
20
18
|
@uri = HTTP::URI.parse(url.to_s)
|
21
19
|
end
|
@@ -28,14 +26,14 @@ module Webmention
|
|
28
26
|
end
|
29
27
|
# :nocov:
|
30
28
|
|
31
|
-
# @return [
|
29
|
+
# @return [Response, ErrorResponse]
|
32
30
|
def response
|
33
31
|
@response ||= Request.get(uri)
|
34
32
|
end
|
35
33
|
|
36
34
|
# @return [String, nil]
|
37
35
|
def webmention_endpoint
|
38
|
-
@webmention_endpoint ||= IndieWeb::Endpoints::Parser.new(response).
|
36
|
+
@webmention_endpoint ||= IndieWeb::Endpoints::Parser.new(response).to_h[:webmention] if response.ok?
|
39
37
|
end
|
40
38
|
|
41
39
|
# @return [Boolean]
|
@@ -2,9 +2,15 @@
|
|
2
2
|
|
3
3
|
module Webmention
|
4
4
|
class Verification
|
5
|
-
#
|
6
|
-
#
|
7
|
-
# @param
|
5
|
+
# Create a new {Verification}.
|
6
|
+
#
|
7
|
+
# @param source_url [Url]
|
8
|
+
# An {URL} representing a source document.
|
9
|
+
# @param target_url [Url]
|
10
|
+
# An {URL} representing a target document.
|
11
|
+
# @param vouch_url [Url]
|
12
|
+
# An {URL} representing a document vouching for the source document.
|
13
|
+
# See https://indieweb.org/Vouch for additional details.
|
8
14
|
def initialize(source_url, target_url, vouch_url: nil)
|
9
15
|
@source_url = source_url
|
10
16
|
@target_url = target_url
|
@@ -46,27 +52,27 @@ module Webmention
|
|
46
52
|
|
47
53
|
private
|
48
54
|
|
49
|
-
# @return [
|
55
|
+
# @return [Url]
|
50
56
|
attr_reader :source_url
|
51
57
|
|
52
|
-
# @return [
|
58
|
+
# @return [Url]
|
53
59
|
attr_reader :target_url
|
54
60
|
|
55
|
-
# @return [
|
61
|
+
# @return [Url]
|
56
62
|
attr_reader :vouch_url
|
57
63
|
|
58
|
-
# @param response [
|
64
|
+
# @param response [Response]
|
59
65
|
#
|
60
|
-
# @raise (see
|
66
|
+
# @raise (see Client#mentioned_urls)
|
61
67
|
#
|
62
68
|
# @return [Array<String>]
|
63
69
|
def mentioned_domains(response)
|
64
70
|
Set.new(mentioned_urls(response).map { |url| HTTP::URI.parse(url).host }).to_a
|
65
71
|
end
|
66
72
|
|
67
|
-
# @param response [
|
73
|
+
# @param response [Response]
|
68
74
|
#
|
69
|
-
# @raise (see
|
75
|
+
# @raise (see Client#mentioned_urls)
|
70
76
|
#
|
71
77
|
# @return [Array<String>]
|
72
78
|
def mentioned_urls(response)
|
data/lib/webmention.rb
CHANGED
@@ -6,8 +6,6 @@ require "http"
|
|
6
6
|
require "indieweb/endpoints"
|
7
7
|
require "nokogiri"
|
8
8
|
|
9
|
-
require_relative "webmention/version"
|
10
|
-
|
11
9
|
require_relative "webmention/client"
|
12
10
|
require_relative "webmention/url"
|
13
11
|
require_relative "webmention/request"
|
@@ -24,12 +22,12 @@ module Webmention
|
|
24
22
|
# Retrieve unique URLs mentioned by the provided URL.
|
25
23
|
#
|
26
24
|
# @example
|
27
|
-
# Webmention.mentioned_urls(
|
25
|
+
# Webmention.mentioned_urls("https://jgarber.example/posts/100")
|
28
26
|
#
|
29
27
|
# @param url [String, HTTP::URI, #to_s] An absolute URL.
|
30
28
|
#
|
31
29
|
# @raise [NoMethodError]
|
32
|
-
# Raised when response is
|
30
|
+
# Raised when response is an {ErrorResponse} or response is of an
|
33
31
|
# unsupported MIME type.
|
34
32
|
#
|
35
33
|
# @return [Array<String>]
|
@@ -40,14 +38,14 @@ module Webmention
|
|
40
38
|
# Send a webmention from a source URL to a target URL.
|
41
39
|
#
|
42
40
|
# @example Send a webmention
|
43
|
-
# source =
|
44
|
-
# target =
|
41
|
+
# source = "https://jgarber.example/posts/100"
|
42
|
+
# target = "https://aaronpk.example/notes/1"
|
45
43
|
# Webmention.send_webmention(source, target)
|
46
44
|
#
|
47
45
|
# @example Send a webmention with a vouch URL
|
48
|
-
# source =
|
49
|
-
# target =
|
50
|
-
# Webmention.send_webmention(source, target, vouch:
|
46
|
+
# source = "https://jgarber.example/posts/100"
|
47
|
+
# target = "https://aaronpk.example/notes/1"
|
48
|
+
# Webmention.send_webmention(source, target, vouch: "https://tantek.example/notes/1")
|
51
49
|
#
|
52
50
|
# @param source [String, HTTP::URI, #to_s]
|
53
51
|
# An absolute URL representing a source document.
|
@@ -57,7 +55,7 @@ module Webmention
|
|
57
55
|
# An absolute URL representing a document vouching for the source document.
|
58
56
|
# See https://indieweb.org/Vouch for additional details.
|
59
57
|
#
|
60
|
-
# @return [
|
58
|
+
# @return [Response, ErrorResponse]
|
61
59
|
def self.send_webmention(source, target, vouch: nil)
|
62
60
|
Client.new(source, vouch: vouch).send_webmention(target)
|
63
61
|
end
|
@@ -65,14 +63,14 @@ module Webmention
|
|
65
63
|
# Send webmentions from a source URL to multiple target URLs.
|
66
64
|
#
|
67
65
|
# @example Send multiple webmentions
|
68
|
-
# source =
|
69
|
-
# targets = [
|
66
|
+
# source = "https://jgarber.example/posts/100"
|
67
|
+
# targets = ["https://aaronpk.example/notes/1", "https://adactio.example/notes/1"]
|
70
68
|
# Webmention.send_webmentions(source, targets)
|
71
69
|
#
|
72
70
|
# @example Send multiple webmentions with a vouch URL
|
73
|
-
# source =
|
74
|
-
# targets = [
|
75
|
-
# Webmention.send_webmentions(source, targets, vouch:
|
71
|
+
# source = "https://jgarber.example/posts/100"
|
72
|
+
# targets = ["https://aaronpk.example/notes/1", "https://adactio.example/notes/1"]
|
73
|
+
# Webmention.send_webmentions(source, targets, vouch: "https://tantek.example/notes/1")
|
76
74
|
#
|
77
75
|
# @param source [String, HTTP::URI, #to_s]
|
78
76
|
# An absolute URL representing a source document.
|
@@ -82,7 +80,7 @@ module Webmention
|
|
82
80
|
# An absolute URL representing a document vouching for the source document.
|
83
81
|
# See https://indieweb.org/Vouch for additional details.
|
84
82
|
#
|
85
|
-
# @return [Array<
|
83
|
+
# @return [Array<Response, ErrorResponse>]
|
86
84
|
def self.send_webmentions(source, *targets, vouch: nil)
|
87
85
|
Client.new(source, vouch: vouch).send_webmentions(*targets)
|
88
86
|
end
|
@@ -91,7 +89,7 @@ module Webmention
|
|
91
89
|
#
|
92
90
|
# @param (see Webmention.send_webmention)
|
93
91
|
#
|
94
|
-
# @raise (see
|
92
|
+
# @raise (see Client#mentioned_urls)
|
95
93
|
#
|
96
94
|
# @return [Boolean]
|
97
95
|
def self.verify_webmention(source, target, vouch: nil)
|
data/webmention.gemspec
CHANGED
@@ -1,34 +1,34 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative "lib/webmention/version"
|
4
|
-
|
5
3
|
Gem::Specification.new do |spec|
|
6
|
-
spec.required_ruby_version = ">=
|
4
|
+
spec.required_ruby_version = ">= 2.7"
|
7
5
|
|
8
6
|
spec.name = "webmention"
|
9
|
-
spec.version =
|
7
|
+
spec.version = "9.0.0"
|
10
8
|
spec.authors = ["Jason Garber"]
|
11
9
|
spec.email = ["jason@sixtwothree.org"]
|
12
10
|
|
13
|
-
spec.summary = "Webmention
|
14
|
-
spec.description =
|
11
|
+
spec.summary = "A Ruby gem for sending and verifying Webmention notifications."
|
12
|
+
spec.description = spec.summary
|
15
13
|
spec.homepage = "https://github.com/indieweb/webmention-client-ruby"
|
16
14
|
spec.license = "Apache-2.0"
|
17
15
|
|
18
16
|
spec.files = Dir["lib/**/*"].reject { |f| File.directory?(f) }
|
19
|
-
spec.files +=
|
20
|
-
spec.files +=
|
17
|
+
spec.files += ["LICENSE", "CHANGELOG.md", "CONTRIBUTING.md", "README.md", "USAGE.md"]
|
18
|
+
spec.files += ["webmention.gemspec"]
|
21
19
|
|
22
20
|
spec.require_paths = ["lib"]
|
23
21
|
|
24
22
|
spec.metadata = {
|
25
23
|
"bug_tracker_uri" => "#{spec.homepage}/issues",
|
26
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
27
|
"rubygems_mfa_required" => "true",
|
28
|
-
"source_code_uri" => "#{spec.homepage}/tree/v#{spec.version}"
|
28
|
+
"source_code_uri" => "#{spec.homepage}/tree/v#{spec.version}",
|
29
29
|
}
|
30
30
|
|
31
|
-
spec.
|
32
|
-
spec.
|
33
|
-
spec.
|
31
|
+
spec.add_dependency "http", "~> 5.3"
|
32
|
+
spec.add_dependency "indieweb-endpoints", "~> 10.0"
|
33
|
+
spec.add_dependency "nokogiri", ">= 1.14"
|
34
34
|
end
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: webmention
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 9.0.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,42 +15,42 @@ dependencies:
|
|
16
15
|
requirements:
|
17
16
|
- - "~>"
|
18
17
|
- !ruby/object:Gem::Version
|
19
|
-
version: '5.
|
18
|
+
version: '5.3'
|
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.3'
|
27
26
|
- !ruby/object:Gem::Dependency
|
28
27
|
name: indieweb-endpoints
|
29
28
|
requirement: !ruby/object:Gem::Requirement
|
30
29
|
requirements:
|
31
30
|
- - "~>"
|
32
31
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
32
|
+
version: '10.0'
|
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: '10.0'
|
41
40
|
- !ruby/object:Gem::Dependency
|
42
41
|
name: nokogiri
|
43
42
|
requirement: !ruby/object:Gem::Requirement
|
44
43
|
requirements:
|
45
44
|
- - ">="
|
46
45
|
- !ruby/object:Gem::Version
|
47
|
-
version: '1.
|
46
|
+
version: '1.14'
|
48
47
|
type: :runtime
|
49
48
|
prerelease: false
|
50
49
|
version_requirements: !ruby/object:Gem::Requirement
|
51
50
|
requirements:
|
52
51
|
- - ">="
|
53
52
|
- !ruby/object:Gem::Version
|
54
|
-
version: '1.
|
53
|
+
version: '1.14'
|
55
54
|
description: A Ruby gem for sending and verifying Webmention notifications.
|
56
55
|
email:
|
57
56
|
- jason@sixtwothree.org
|
@@ -75,17 +74,17 @@ files:
|
|
75
74
|
- lib/webmention/response.rb
|
76
75
|
- lib/webmention/url.rb
|
77
76
|
- lib/webmention/verification.rb
|
78
|
-
- lib/webmention/version.rb
|
79
77
|
- webmention.gemspec
|
80
78
|
homepage: https://github.com/indieweb/webmention-client-ruby
|
81
79
|
licenses:
|
82
80
|
- Apache-2.0
|
83
81
|
metadata:
|
84
82
|
bug_tracker_uri: https://github.com/indieweb/webmention-client-ruby/issues
|
85
|
-
changelog_uri: https://github.com/indieweb/webmention-client-ruby/releases/tag/
|
83
|
+
changelog_uri: https://github.com/indieweb/webmention-client-ruby/releases/tag/v9.0.0
|
84
|
+
documentation_uri: https://rubydoc.info/gems/webmention/9.0.0
|
85
|
+
homepage_uri: https://github.com/indieweb/webmention-client-ruby
|
86
86
|
rubygems_mfa_required: 'true'
|
87
|
-
source_code_uri: https://github.com/indieweb/webmention-client-ruby/tree/
|
88
|
-
post_install_message:
|
87
|
+
source_code_uri: https://github.com/indieweb/webmention-client-ruby/tree/v9.0.0
|
89
88
|
rdoc_options: []
|
90
89
|
require_paths:
|
91
90
|
- lib
|
@@ -93,15 +92,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
93
92
|
requirements:
|
94
93
|
- - ">="
|
95
94
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
95
|
+
version: '2.7'
|
97
96
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
97
|
requirements:
|
99
98
|
- - ">="
|
100
99
|
- !ruby/object:Gem::Version
|
101
100
|
version: '0'
|
102
101
|
requirements: []
|
103
|
-
rubygems_version: 3.
|
104
|
-
signing_key:
|
102
|
+
rubygems_version: 3.6.9
|
105
103
|
specification_version: 4
|
106
|
-
summary: Webmention
|
104
|
+
summary: A Ruby gem for sending and verifying Webmention notifications.
|
107
105
|
test_files: []
|