indieweb-endpoints 9.1.0 → 10.0.1

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: da8f18ac80e24b04e834e41ef4ec959cc26c3496b888de60c92d518fb89bbc78
4
- data.tar.gz: 64a2117a77c161ab5d4c5b616c4fe1685406ea58218ade5af72eb2998048f402
3
+ metadata.gz: 8f81df133c4d630c9b7d5fb2531c0518e19d2f4f0ad054fbb7175c34ace1ccb4
4
+ data.tar.gz: b5538c271d836b84f9b12a01f64e6c5f8476c485308dbe14403ae784ed8a0a5d
5
5
  SHA512:
6
- metadata.gz: 54fdc8310a995d36c8f46e8926790bafd8352a5db02e32144a4d4ce074258bc5c7ca80cc9778d910a522749f4b9807eb5cd202465ee8d811ca5ee4d4aa6311f7
7
- data.tar.gz: 1d36d41eccca9f32ccecd622bc739915af4af9f61596fabf48d994e4d6f741ae4c8013a064c9b908917bf6896ac4ad291df8a90e882f074a3b1a12dbcc23b76b
6
+ metadata.gz: f9b9b03ac7dca3260be3f2b50aab57c178b821f492783bf90977fa0b7987e6664e61e5a739dea743ed29fb4e880daa9bafda3ef55f039e7879c0b988398190a0
7
+ data.tar.gz: 46ab372866988e7ae8f8c04e51c5ca0c74a66ee93f61eba68dc1c703642f6c8867675bd9cbf0192ad36ef0e8d62f77224cde504e9fabdaa2101a2c537c683048
data/README.md CHANGED
@@ -10,11 +10,11 @@
10
10
 
11
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/).
12
12
  - Passes all Endpoint Discovery tests on [webmention.rocks](https://webmention.rocks).
13
- - Supports Ruby 2.6 and newer.
13
+ - Supports Ruby 2.7 and newer.
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.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.
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 [rbenv](https://github.com/rbenv/rbenv), [chruby](https://github.com/postmodern/chruby), or [rvm](https://github.com/rvm/rvm) is recommended.
18
18
 
19
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).
20
20
 
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  Gem::Specification.new do |spec|
4
- spec.required_ruby_version = ">= 2.6"
4
+ spec.required_ruby_version = ">= 2.7"
5
5
 
6
6
  spec.name = "indieweb-endpoints"
7
- spec.version = "9.1.0"
7
+ spec.version = "10.0.1"
8
8
  spec.authors = ["Jason Garber"]
9
9
  spec.email = ["jason@sixtwothree.org"]
10
10
 
@@ -29,6 +29,6 @@ Gem::Specification.new do |spec|
29
29
  }
30
30
 
31
31
  spec.add_dependency "http", "~> 5.2"
32
- spec.add_dependency "link-header-parser", "~> 6.1"
33
- spec.add_dependency "nokogiri", ">= 1.13"
32
+ spec.add_dependency "link-header-parser", "~> 7.0", ">= 7.0.1"
33
+ spec.add_dependency "nokogiri-html-ext", "~> 1.4"
34
34
  end
@@ -3,13 +3,6 @@
3
3
  module IndieWeb
4
4
  module Endpoints
5
5
  class Client
6
- HTTP_HEADERS_OPTS = {
7
- accept: "*/*",
8
- user_agent: "IndieWeb Endpoint Discovery (https://rubygems.org/gems/indieweb-endpoints)",
9
- }.freeze
10
-
11
- private_constant :HTTP_HEADERS_OPTS
12
-
13
6
  # Create a new client with a URL to parse for IndieWeb endpoints.
14
7
  #
15
8
  # @example
@@ -19,15 +12,20 @@ module IndieWeb
19
12
  #
20
13
  # @raise [InvalidURIError]
21
14
  def initialize(url)
22
- @uri = HTTP::URI.parse(url.to_s)
15
+ @uri = HTTP::URI.parse(url)
23
16
  rescue Addressable::URI::InvalidURIError => e
24
17
  raise InvalidURIError, e
25
18
  end
26
19
 
20
+ # :nocov:
27
21
  # @return [String]
28
22
  def inspect
29
- %(#<#{self.class.name}:#{format("%#0x", object_id)} uri: "#{uri}">)
23
+ format "#<%<class>s:%<id>#0x @uri=%<uri>s",
24
+ class: self.class,
25
+ id: object_id << 1,
26
+ uri: uri.inspect
30
27
  end
28
+ # :nocov:
31
29
 
32
30
  # A Hash of the discovered IndieWeb endpoints from the provided URL.
33
31
  #
@@ -36,17 +34,18 @@ module IndieWeb
36
34
  @endpoints ||= Parser.new(response).to_h
37
35
  end
38
36
 
39
- # The {HTTP::Response} object returned by the provided URL.
37
+ # The +HTTP::Response+ object.
40
38
  #
41
39
  # @return [HTTP::Response]
42
40
  #
43
41
  # @raise [HttpError, SSLError]
44
42
  def response
45
- @response ||= HTTP
46
- .follow(max_hops: 20)
47
- .headers(HTTP_HEADERS_OPTS)
48
- .timeout(connect: 5, read: 5)
49
- .get(uri)
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)
50
49
  rescue HTTP::Error => e
51
50
  raise HttpError, e
52
51
  rescue OpenSSL::SSL::SSLError => e
@@ -57,6 +56,11 @@ module IndieWeb
57
56
 
58
57
  # @return [HTTP::URI]
59
58
  attr_reader :uri
59
+
60
+ # @return [String]
61
+ def user_agent
62
+ "Mozilla/5.0 (compatible; IndieWebEndpointsDiscovery/1.0; +https://rubygems.org/gems/indieweb-endpoints)"
63
+ end
60
64
  end
61
65
  end
62
66
  end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module IndieWeb
4
+ module Endpoints
5
+ class Error < StandardError; end
6
+
7
+ class HttpError < Error; end
8
+
9
+ class InvalidURIError < Error; end
10
+
11
+ class SSLError < Error; end
12
+ end
13
+ end
@@ -16,17 +16,12 @@ module IndieWeb
16
16
  #
17
17
  # @raise [InvalidURIError]
18
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 }
19
+ results = (matches_from_headers(identifier) + matches_from_body(identifier, node_names)).compact
23
20
 
24
21
  results.uniq!
25
22
  results.sort!
26
23
 
27
24
  results
28
- rescue Addressable::URI::InvalidURIError => e
29
- raise InvalidURIError, e
30
25
  end
31
26
 
32
27
  # @param (see #matches)
@@ -56,30 +51,37 @@ module IndieWeb
56
51
 
57
52
  # @return [Nokogiri::HTML5::Document]
58
53
  def body
59
- @body ||= Nokogiri::HTML5(response.body)
54
+ @body ||= Nokogiri::HTML5(response.body, response.uri).resolve_relative_urls!
60
55
  end
61
56
 
62
57
  # @return [Hash{Symbol => Array<LinkHeaderParser::LinkHeader>}]
63
58
  def headers
64
- @headers ||= LinkHeaderParser.parse(response.headers.get("link"), base: response.uri).group_by_relation_type
59
+ @headers ||= LinkHeaderParser.parse(response.headers.get("link"), base_uri: response.uri).group_by_relation_type
65
60
  end
66
61
 
62
+ # Reject URLs with fragment identifiers per the IndieAuth specification.
63
+ #
64
+ # @param identifier [String, #to_s]
65
+ # @param node_names [Array<String, #to_s>]
66
+ #
67
67
  # @return [Array<String>]
68
68
  def matches_from_body(identifier, node_names)
69
69
  return [] unless response.mime_type == "text/html"
70
70
 
71
- # Reject endpoints that contain a fragment identifier.
72
- selectors = node_names.map { |node| %(#{node}[rel~="#{identifier}"][href]:not([href*="#"])) }.join(",")
73
-
74
- body.css(selectors).map { |element| element["href"] }
71
+ body
72
+ .css(*node_names.map { |node| %(#{node}[rel~="#{identifier}"][href]:not([href*="#"]) / @href) })
73
+ .map(&:value)
75
74
  end
76
75
 
76
+ # Reject URLs with fragment identifiers per the IndieAuth specification.
77
+ #
78
+ # @param identifier [String, #to_sym]
79
+ #
77
80
  # @return [Array<String>]
78
81
  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)
82
+ Array(headers[identifier]).filter_map do |header|
83
+ header.target_uri unless HTTP::URI.parse(header.target_uri).fragment
84
+ end
83
85
  end
84
86
  end
85
87
  end
@@ -2,21 +2,15 @@
2
2
 
3
3
  require "http"
4
4
  require "link-header-parser"
5
- require "nokogiri"
5
+ require "nokogiri/html-ext"
6
+
7
+ require_relative "endpoints/exceptions"
6
8
 
7
9
  require_relative "endpoints/client"
8
10
  require_relative "endpoints/parser"
9
11
 
10
12
  module IndieWeb
11
13
  module Endpoints
12
- class Error < StandardError; end
13
-
14
- class HttpError < Error; end
15
-
16
- class InvalidURIError < Error; end
17
-
18
- class SSLError < Error; end
19
-
20
14
  # Discover a URL's IndieAuth, Micropub, Microsub, and Webmention endpoints.
21
15
  #
22
16
  # Convenience method for {Client#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: 9.1.0
4
+ version: 10.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Garber
@@ -29,28 +29,34 @@ dependencies:
29
29
  requirements:
30
30
  - - "~>"
31
31
  - !ruby/object:Gem::Version
32
- version: '6.1'
32
+ version: '7.0'
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: 7.0.1
33
36
  type: :runtime
34
37
  prerelease: false
35
38
  version_requirements: !ruby/object:Gem::Requirement
36
39
  requirements:
37
40
  - - "~>"
38
41
  - !ruby/object:Gem::Version
39
- version: '6.1'
42
+ version: '7.0'
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: 7.0.1
40
46
  - !ruby/object:Gem::Dependency
41
- name: nokogiri
47
+ name: nokogiri-html-ext
42
48
  requirement: !ruby/object:Gem::Requirement
43
49
  requirements:
44
- - - ">="
50
+ - - "~>"
45
51
  - !ruby/object:Gem::Version
46
- version: '1.13'
52
+ version: '1.4'
47
53
  type: :runtime
48
54
  prerelease: false
49
55
  version_requirements: !ruby/object:Gem::Requirement
50
56
  requirements:
51
- - - ">="
57
+ - - "~>"
52
58
  - !ruby/object:Gem::Version
53
- version: '1.13'
59
+ version: '1.4'
54
60
  description: Discover a URL’s IndieAuth, Micropub, Microsub, and Webmention endpoints.
55
61
  email:
56
62
  - jason@sixtwothree.org
@@ -66,17 +72,18 @@ files:
66
72
  - indieweb-endpoints.gemspec
67
73
  - lib/indieweb/endpoints.rb
68
74
  - lib/indieweb/endpoints/client.rb
75
+ - lib/indieweb/endpoints/exceptions.rb
69
76
  - lib/indieweb/endpoints/parser.rb
70
77
  homepage: https://github.com/indieweb/indieweb-endpoints-ruby
71
78
  licenses:
72
79
  - MIT
73
80
  metadata:
74
81
  bug_tracker_uri: https://github.com/indieweb/indieweb-endpoints-ruby/issues
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
82
+ changelog_uri: https://github.com/indieweb/indieweb-endpoints-ruby/releases/tag/v10.0.1
83
+ documentation_uri: https://rubydoc.info/gems/indieweb-endpoints/10.0.1
77
84
  homepage_uri: https://github.com/indieweb/indieweb-endpoints-ruby
78
85
  rubygems_mfa_required: 'true'
79
- source_code_uri: https://github.com/indieweb/indieweb-endpoints-ruby/tree/v9.1.0
86
+ source_code_uri: https://github.com/indieweb/indieweb-endpoints-ruby/tree/v10.0.1
80
87
  rdoc_options: []
81
88
  require_paths:
82
89
  - lib
@@ -84,7 +91,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
84
91
  requirements:
85
92
  - - ">="
86
93
  - !ruby/object:Gem::Version
87
- version: '2.6'
94
+ version: '2.7'
88
95
  required_rubygems_version: !ruby/object:Gem::Requirement
89
96
  requirements:
90
97
  - - ">="