webmention 10.0.0 → 10.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: 18cd676b542de4d7d4507fb30a6475cba645feca8dccebb4230d48904165d1dd
4
- data.tar.gz: 309bb9ad852cc944a747a1b18a25e04009e9c0095f3249212654b4ee920e5132
3
+ metadata.gz: 0aef2414279b18a19630ebbff1fbd432bcdf6f99bebd04fbec000956d13de4d0
4
+ data.tar.gz: caaace5949544c00d5d020844d3ed4ce34208cbea81a67a8fd8acd8729bbe97a
5
5
  SHA512:
6
- metadata.gz: f73890fc04da3b8ec912f3b469cdb7f29ef2761b56e0ca4854133981c3b18ecb09c7be7d1e24253935dafd0c858be13fd45c60c0365b2e005f7659ec74ee9467
7
- data.tar.gz: d00e9b5a4b32fefcdc48e59e3a33d73662e79c563f69517be55984c57ba2fc790d544fac3f58c06b91bee6b92258fa2fe6b7f59aac73c92030d2ca14bbcd4d76
6
+ metadata.gz: 336f4b3d91f462223978f5fd52db6f1d3da4a4a4b27d56d70f48665e4585a0b0fef43703ebe10a9e9063a1599928166d895c94d74b3e91da5d5c0d50d581d3bc
7
+ data.tar.gz: 4ff3c624983522c24a777c3fd409605d6a4c4f4b33c8158f5558c3b2f9969d5942f4f3fd2b66689b029a3d9375e0d17522e7e4a040ba8d130adaed0417965dba
data/.yardopts ADDED
@@ -0,0 +1,6 @@
1
+ -
2
+ CHANGELOG.md
3
+ CODE_OF_CONDUCT.md
4
+ CONTRIBUTING.md
5
+ LICENSE
6
+ USAGE.md
data/README.md CHANGED
@@ -48,4 +48,4 @@ To learn more about Webmention, see [indieweb.org/Webmention](https://indieweb.o
48
48
 
49
49
  ## License
50
50
 
51
- This project is freely available under the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0.html). See [LICENSE](https://github.com/indieweb/webmention-client-ruby/blob/main/LICENSE) for more details.
51
+ This project is freely available under the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0.html). See [LICENSE](LICENSE) for more details.
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Webmention
4
+ # A client interface to send and verify Webmention notifications.
4
5
  class Client
5
6
  # @return [Url]
6
7
  attr_reader :source_url
@@ -16,18 +17,18 @@ module Webmention
16
17
  # @example
17
18
  # Webmention::Client.new("https://jgarber.example/posts/100", vouch: "https://tantek.example/notes/1")
18
19
  #
20
+ # @see https://indieweb.org/Vouch
21
+ #
19
22
  # @param source [String, HTTP::URI, #to_s]
20
23
  # An absolute URL representing a source document.
21
24
  # @param vouch [String, HTTP::URI, #to_s]
22
25
  # An absolute URL representing a document vouching for the source document.
23
- # See https://indieweb.org/Vouch for additional details.
24
26
  def initialize(source, vouch: nil)
25
27
  @source_url = Url.new(source)
26
28
  @vouch_url = Url.new(vouch)
27
29
  end
28
30
 
29
- # @return [String]
30
- #
31
+ # @!visibility private
31
32
  # simplecov:disable
32
33
  def inspect
33
34
  "#<#{self.class}:#{format("%#0x", object_id)} " \
@@ -36,7 +37,7 @@ module Webmention
36
37
  end
37
38
  # simplecov:enable
38
39
 
39
- # Retrieve unique URLs mentioned by this client's source URL.
40
+ # Unique URLs mentioned by {source_url}.
40
41
  #
41
42
  # @example
42
43
  # client = Webmention::Client.new("https://jgarber.example/posts/100")
@@ -56,7 +57,7 @@ module Webmention
56
57
  .sort
57
58
  end
58
59
 
59
- # Send a webmention from this client's source URL to a target URL.
60
+ # Send a webmention from this client's {source_url} to a target URL.
60
61
  #
61
62
  # @example
62
63
  # client = Webmention::Client.new("https://jgarber.example/posts/100")
@@ -81,7 +82,7 @@ module Webmention
81
82
  ErrorResponse.new("No Webmention endpoint found for target URL #{target}", response.request)
82
83
  end
83
84
 
84
- # Send webmentions from this client's source URL to multiple target URLs.
85
+ # Send webmentions from {source_url} to multiple target URLs.
85
86
  #
86
87
  # @example
87
88
  # client = Webmention::Client.new("https://jgarber.example/posts/100")
@@ -96,10 +97,9 @@ module Webmention
96
97
  targets.map { |target| send_webmention(target) }
97
98
  end
98
99
 
99
- # Verify that this client's source URL links to a target URL.
100
+ # Verify that {source_url} links to a target URL.
100
101
  #
101
- # @param target [String, HTTP::URI, #to_s]
102
- # An absolute URL representing a target document.
102
+ # @param target (see #send_webmention)
103
103
  #
104
104
  # @raise (see Client#mentioned_urls)
105
105
  #
@@ -110,7 +110,7 @@ module Webmention
110
110
 
111
111
  private
112
112
 
113
- # @param target [String, HTTP::URI, #to_s]
113
+ # @param target (see #send_webmention)
114
114
  #
115
115
  # @return [Hash{Symbol => String}]
116
116
  def request_options_for(target)
@@ -1,6 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Webmention
4
+ # An interface to instances of the {Request} class.
5
+ #
6
+ # An {ErrorResponse} represents {Request}s that generated errors (e.g.
7
+ # connection error, SSL error) or that could not locate a Webmention endpoint.
8
+ # The nature of the error is captured in the {#message} instance method.
4
9
  class ErrorResponse
5
10
  # @return [String]
6
11
  attr_reader :message
@@ -10,11 +15,6 @@ module Webmention
10
15
 
11
16
  # Create a new {ErrorResponse}.
12
17
  #
13
- # Instances of this class represent HTTP requests that generated errors
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 {#message} instance
16
- # method.
17
- #
18
18
  # @api private
19
19
  #
20
20
  # @param message [String]
@@ -24,8 +24,7 @@ module Webmention
24
24
  @request = request
25
25
  end
26
26
 
27
- # @return [String]
28
- #
27
+ # @!visibility private
29
28
  # simplecov:disable
30
29
  def inspect
31
30
  "#<#{self.class}:#{format("%#0x", object_id)} " \
@@ -33,12 +32,16 @@ module Webmention
33
32
  end
34
33
  # simplecov:enable
35
34
 
35
+ # An {ErrorResponse} has no mentioned URLs.
36
+ #
36
37
  # @return [Set]
37
38
  def mentioned_urls
38
39
  Set.new
39
40
  end
40
41
 
41
- # @return [Boolean]
42
+ # An {ErrorResponse} is never okay!
43
+ #
44
+ # @return [false]
42
45
  def ok?
43
46
  false
44
47
  end
@@ -1,6 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Webmention
4
+ # An interface for executing HTTP requests and generating {Response}s and
5
+ # {ErrorResponse}s.
6
+ #
4
7
  # @api private
5
8
  class Request
6
9
  # Set defaults derived from Webmention specification examples.
@@ -13,7 +16,7 @@ module Webmention
13
16
  },
14
17
  headers: {
15
18
  accept: "*/*",
16
- user_agent: "Webmention Client (https://rubygems.org/gems/webmention)",
19
+ user_agent: "Mozilla/5.0 (compatible; WebmentionClient/1.0; +https://rubygems.org/gems/webmention)",
17
20
  },
18
21
  timeout_options: {
19
22
  connect_timeout: 5,
@@ -48,24 +51,20 @@ module Webmention
48
51
  # },
49
52
  # )
50
53
  #
54
+ # @see https://indieweb.org/Vouch
55
+ #
51
56
  # @param method [Symbol]
52
57
  # @param url [String]
53
- # @param options [Hash{Symbol => String}]
54
- # @option options [String] :source
55
- # An absolute URL representing a source document.
56
- # @option options [String] :target
57
- # An absolute URL representing a target document.
58
- # @option options [String] :vouch
59
- # An absolute URL representing a document vouching for the source document.
60
- # See https://indieweb.org/Vouch for additional details.
58
+ # @param options [Hash{Symbol => Hash{Symbol => String}}]
59
+ # @option options [Hash{Symbol => String}] :form
60
+ # A Hash of options to serialize as form-encoded.
61
61
  def initialize(method, url, **options)
62
62
  @method = method.to_sym
63
63
  @uri = HTTP::URI.parse(url.to_s)
64
64
  @options = options
65
65
  end
66
66
 
67
- # @return [String]
68
- #
67
+ # @!visibility private
69
68
  # simplecov:disable
70
69
  def inspect
71
70
  "#<#{self.class}:#{format("%#0x", object_id)} " \
@@ -74,7 +73,7 @@ module Webmention
74
73
  end
75
74
  # simplecov:enable
76
75
 
77
- # Submit the {Request}.
76
+ # Execute the {Request}.
78
77
  #
79
78
  # @return [Response, ErrorResponse]
80
79
  def perform
@@ -1,39 +1,50 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Webmention
4
+ # An interface to instances of the {Request} and `HTTP::Response` classes.
5
+ #
6
+ # A {Response} represents the results of a successful {Request}.
4
7
  class Response
5
8
  extend Forwardable
6
9
 
10
+ # Consider the first h-entry to be the authoritative content container when
11
+ # parsing a document for mentioned URLs. Fall back to the `<body>` element
12
+ # when no h-entry is found.
13
+ #
14
+ # @see http://microformats.org/wiki/h-entry
7
15
  PARSE_CONTEXT = [".h-entry .e-content", ".h-entry", "body"].freeze
16
+
8
17
  URI_REGEXP = URI::RFC2396_Parser.new.make_regexp(["http", "https"]).freeze
9
18
 
10
- private_constant :PARSE_CONTEXT
19
+ public_constant :PARSE_CONTEXT
11
20
  private_constant :URI_REGEXP
12
21
 
22
+ # The {Request} associated with this {Response}.
23
+ #
13
24
  # @return [Request]
14
25
  attr_reader :request
15
26
 
16
- # @!method
27
+ # @!method headers
17
28
  # @return [HTTP::Headers]
18
29
  def_delegator :@response, :headers
19
30
 
20
- # @!method
31
+ # @!method body
21
32
  # @return [HTTP::Response::Body]
22
33
  def_delegator :@response, :body
23
34
 
24
- # @!method
35
+ # @!method code
25
36
  # @return [Integer]
26
37
  def_delegator :@response, :code
27
38
 
28
- # @!method
39
+ # @!method reason
29
40
  # @return [String]
30
41
  def_delegator :@response, :reason
31
42
 
32
- # !@method
43
+ # @!method mime_type
33
44
  # @return [String]
34
45
  def_delegator :@response, :mime_type
35
46
 
36
- # !@method
47
+ # @!method uri
37
48
  # @return [HTTP::URI]
38
49
  def_delegator :@response, :uri
39
50
 
@@ -52,8 +63,7 @@ module Webmention
52
63
  @request = request
53
64
  end
54
65
 
55
- # @return [String]
56
- #
66
+ # @!visibility private
57
67
  # simplecov:disable
58
68
  def inspect
59
69
  "#<#{self.class}:#{format("%#0x", object_id)} " \
@@ -63,14 +73,20 @@ module Webmention
63
73
  end
64
74
  # simplecov:enable
65
75
 
66
- # Parse the response body for unique host names.
76
+ # Unique host names parsed from the response body.
77
+ #
78
+ # The returned `Set` contains the unique host names ("domain names") derived
79
+ # from the `Set` of {mentioned_urls}. Order is not guaranteed.
67
80
  #
68
81
  # @return [Set<String>]
69
82
  def mentioned_hosts
70
83
  @mentioned_hosts ||= Set.new(mentioned_urls.map { |url| HTTP::URI.parse(url).host })
71
84
  end
72
85
 
73
- # Parse the response body for mentioned URLs.
86
+ # Unique mentioned URLs parsed from the response body.
87
+ #
88
+ # The returned `Set` contains the unique URLs parsed from the
89
+ # {PARSE_CONTEXT}. Order is not guaranteed.
74
90
  #
75
91
  # @return [Set<String>]
76
92
  def mentioned_urls
@@ -83,7 +99,9 @@ module Webmention
83
99
  )
84
100
  end
85
101
 
86
- # @return [Boolean]
102
+ # A {Response} is always okay!
103
+ #
104
+ # @return [true]
87
105
  def ok?
88
106
  true
89
107
  end
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Webmention
4
+ # An interface representing a parsed URL and its {Response}.
5
+ #
4
6
  # @api private
5
7
  class Url
6
8
  extend Forwardable
@@ -19,8 +21,7 @@ module Webmention
19
21
  @uri = HTTP::URI.parse(url.to_s)
20
22
  end
21
23
 
22
- # @return [String]
23
- #
24
+ # @!visibility private
24
25
  # simplecov:disable
25
26
  def inspect
26
27
  "#<#{self.class}:#{format("%#0x", object_id)} " \
@@ -1,26 +1,27 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Webmention
4
+ # Verify that a source URL links to a target URL.
4
5
  class Verification
5
6
  # Create a new {Verification}.
6
7
  #
7
8
  # @api private
8
9
  #
10
+ # @see https://indieweb.org/Vouch
11
+ #
9
12
  # @param source_url [Url]
10
13
  # An {URL} representing a source document.
11
14
  # @param target_url [Url]
12
15
  # An {URL} representing a target document.
13
16
  # @param vouch_url [Url]
14
17
  # An {URL} representing a document vouching for the source document.
15
- # See https://indieweb.org/Vouch for additional details.
16
18
  def initialize(source_url, target_url, vouch_url: nil)
17
19
  @source_url = source_url
18
20
  @target_url = target_url
19
21
  @vouch_url = vouch_url
20
22
  end
21
23
 
22
- # @return [String]
23
- #
24
+ # @!visibility private
24
25
  # simplecov:disable
25
26
  def inspect
26
27
  "#<#{self.class}:#{format("%#0x", object_id)} " \
data/lib/webmention.rb CHANGED
@@ -14,6 +14,9 @@ require_relative "webmention/response"
14
14
  require_relative "webmention/error_response"
15
15
  require_relative "webmention/verification"
16
16
 
17
+ # Send and verify Webmention notifications.
18
+ #
19
+ # @see https://indieweb.org/Webmention
17
20
  module Webmention
18
21
  # Retrieve unique URLs mentioned by the provided URL.
19
22
  #
@@ -22,10 +25,9 @@ module Webmention
22
25
  #
23
26
  # @param url [String, HTTP::URI, #to_s] An absolute URL.
24
27
  #
25
- # @raise [Burly::UnsupportedMimeType]
26
- # Raised when response is of an unsupported MIME type.
28
+ # @raise (see Client#mentioned_urls)
27
29
  #
28
- # @return [Array<String>]
30
+ # @return (see Client#mentioned_urls)
29
31
  def self.mentioned_urls(url)
30
32
  Client.new(url).mentioned_urls
31
33
  end
@@ -42,15 +44,13 @@ module Webmention
42
44
  # target = "https://aaronpk.example/notes/1"
43
45
  # Webmention.send_webmention(source, target, vouch: "https://tantek.example/notes/1")
44
46
  #
45
- # @param source [String, HTTP::URI, #to_s]
46
- # An absolute URL representing a source document.
47
- # @param target [String, HTTP::URI, #to_s]
48
- # An absolute URL representing a target document.
49
- # @param vouch [String, HTTP::URI, #to_s]
50
- # An absolute URL representing a document vouching for the source document.
51
- # See https://indieweb.org/Vouch for additional details.
47
+ # @see https://indieweb.org/Vouch
48
+ #
49
+ # @param source (see Client#initialize)
50
+ # @param target (see Client#send_webmention)
51
+ # @param vouch (see Client#initialize)
52
52
  #
53
- # @return [Response, ErrorResponse]
53
+ # @return (see Client#send_webmention)
54
54
  def self.send_webmention(source, target, vouch: nil)
55
55
  Client.new(source, vouch: vouch).send_webmention(target)
56
56
  end
@@ -67,13 +67,9 @@ module Webmention
67
67
  # targets = ["https://aaronpk.example/notes/1", "https://adactio.example/notes/1"]
68
68
  # Webmention.send_webmentions(source, targets, vouch: "https://tantek.example/notes/1")
69
69
  #
70
- # @param source [String, HTTP::URI, #to_s]
71
- # An absolute URL representing a source document.
72
- # @param targets [Array<String, HTTP::URI, #to_s>]
73
- # An array of absolute URLs representing multiple target documents.
74
- # @param vouch [String, HTTP::URI, #to_s]
75
- # An absolute URL representing a document vouching for the source document.
76
- # See https://indieweb.org/Vouch for additional details.
70
+ # @see https://indieweb.org/Vouch
71
+ #
72
+ # @param (see .send_webmention)
77
73
  #
78
74
  # @return [Array<Response, ErrorResponse>]
79
75
  def self.send_webmentions(source, *targets, vouch: nil)
@@ -82,7 +78,7 @@ module Webmention
82
78
 
83
79
  # Verify that a source URL links to a target URL.
84
80
  #
85
- # @param (see Webmention.send_webmention)
81
+ # @param (see .send_webmention)
86
82
  #
87
83
  # @raise (see Client#mentioned_urls)
88
84
  #
data/webmention.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 = "webmention"
7
- spec.version = "10.0.0"
7
+ spec.version = "10.1.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 = "Apache-2.0"
15
15
 
16
16
  spec.files = Dir["lib/**/*"].reject { |f| File.directory?(f) }
17
- spec.files += ["LICENSE", "CHANGELOG.md", "CONTRIBUTING.md", "README.md", "USAGE.md"]
17
+ spec.files += [".yardopts", "LICENSE", "CHANGELOG.md", "CONTRIBUTING.md", "README.md", "USAGE.md"]
18
18
  spec.files += ["webmention.gemspec"]
19
19
 
20
20
  spec.require_paths = ["lib"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webmention
3
3
  version: !ruby/object:Gem::Version
4
- version: 10.0.0
4
+ version: 10.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Garber
@@ -72,6 +72,7 @@ executables: []
72
72
  extensions: []
73
73
  extra_rdoc_files: []
74
74
  files:
75
+ - ".yardopts"
75
76
  - CHANGELOG.md
76
77
  - CONTRIBUTING.md
77
78
  - LICENSE
@@ -90,11 +91,11 @@ licenses:
90
91
  - Apache-2.0
91
92
  metadata:
92
93
  bug_tracker_uri: https://github.com/indieweb/webmention-client-ruby/issues
93
- changelog_uri: https://github.com/indieweb/webmention-client-ruby/releases/tag/v10.0.0
94
- documentation_uri: https://rubydoc.info/gems/webmention/10.0.0
94
+ changelog_uri: https://github.com/indieweb/webmention-client-ruby/releases/tag/v10.1.0
95
+ documentation_uri: https://rubydoc.info/gems/webmention/10.1.0
95
96
  homepage_uri: https://github.com/indieweb/webmention-client-ruby
96
97
  rubygems_mfa_required: 'true'
97
- source_code_uri: https://github.com/indieweb/webmention-client-ruby/tree/v10.0.0
98
+ source_code_uri: https://github.com/indieweb/webmention-client-ruby/tree/v10.1.0
98
99
  rdoc_options: []
99
100
  require_paths:
100
101
  - lib