indieweb-endpoints 0.5.0 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.reek.yml +2 -0
- data/.ruby-version +1 -1
- data/.travis.yml +5 -3
- data/CHANGELOG.md +34 -13
- data/CONTRIBUTING.md +2 -2
- data/README.md +14 -7
- data/indieweb-endpoints.gemspec +10 -9
- data/lib/indieweb/endpoints.rb +12 -11
- data/lib/indieweb/endpoints/client.rb +5 -1
- data/lib/indieweb/endpoints/concerns/registerable.rb +15 -0
- data/lib/indieweb/endpoints/parsers.rb +12 -96
- data/lib/indieweb/endpoints/parsers/redirect_uri_parser.rb +2 -36
- data/lib/indieweb/endpoints/parsers/webmention_parser.rb +5 -14
- data/lib/indieweb/endpoints/services/http_request_service.rb +39 -0
- data/lib/indieweb/endpoints/services/response_body_parser_service.rb +14 -0
- data/lib/indieweb/endpoints/services/response_headers_parser_service.rb +16 -0
- data/lib/indieweb/endpoints/version.rb +1 -1
- metadata +38 -22
- data/lib/indieweb/endpoints/http_request.rb +0 -29
- data/lib/indieweb/endpoints/registerable.rb +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d0f792d375c1f3a3bd75d775b83bafba558576b43fdcd55a4f2f6609631776d1
|
4
|
+
data.tar.gz: 285dd5905c4305c91a922575d97f579b03b29cb20e6037051ab7e2c420d5d9f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ff2be853683341b8da8c3aa35db8dc423e1d0a046fe892230e8704a4e86d6a9b0d8cdae5f355df758937ea4159de1eb992d0b3cbba46083356013f66660e47be
|
7
|
+
data.tar.gz: 0033ebce96813205b2c70ef9f57348e3fb6b07374e55eb519c1937680c1337d36dd4bb58ca9d200f34bc7c9e5cccd866b242f8f596a09fb515ed088c4843b4d8
|
data/.reek.yml
CHANGED
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.4.
|
1
|
+
2.4.7
|
data/.travis.yml
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
language: ruby
|
2
2
|
rvm:
|
3
|
-
- 2.4
|
4
|
-
- 2.5
|
5
|
-
- 2.6
|
3
|
+
- 2.4
|
4
|
+
- 2.5
|
5
|
+
- 2.6
|
6
6
|
cache:
|
7
7
|
- bundler
|
8
8
|
before_install:
|
@@ -14,3 +14,5 @@ before_script:
|
|
14
14
|
- ./cc-test-reporter before-build
|
15
15
|
after_script:
|
16
16
|
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
|
17
|
+
notifications:
|
18
|
+
email: false
|
data/CHANGELOG.md
CHANGED
@@ -1,29 +1,50 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 1.0.2 / 2019-08-31
|
4
|
+
|
5
|
+
- Update WebMock and Addressable gems (298da63)
|
6
|
+
- Update development dependencies (5663e3a)
|
7
|
+
|
8
|
+
## 1.0.1 / 2019-07-17
|
9
|
+
|
10
|
+
- Safely combine, flatten, and compact result set (5f2d9c5)
|
11
|
+
|
12
|
+
## 1.0.0 / 2019-07-08
|
13
|
+
|
14
|
+
- Refactor gem code using service objects approach (78511d7 and 9d2fee0)
|
15
|
+
|
16
|
+
## 0.7.0 / 2019-07-03
|
17
|
+
|
18
|
+
- Update runtime and development dependencies (d99214b and 7692ab3)
|
19
|
+
|
20
|
+
## 0.6.0 / 2019-06-15
|
21
|
+
|
22
|
+
- Update Parser-related classes to resolve #2
|
23
|
+
|
3
24
|
## 0.5.0 / 2019-05-09
|
4
25
|
|
5
|
-
- Add support for Microsub endpoint discovery (
|
6
|
-
- Refactor parsers to ignore URLs with fragments (
|
7
|
-
- Rescue `NoMethodError` (for `nil`) and `TypeError` (for non-`String`) (
|
8
|
-
- Raise `ArgumentError` if url scheme is not `http` or `https` (
|
9
|
-
- Shorten up User Agent string (
|
10
|
-
- Refactor `HTTPRequest` class using specification defaults (
|
26
|
+
- Add support for Microsub endpoint discovery (5e81d9f)
|
27
|
+
- Refactor parsers to ignore URLs with fragments (797b376)
|
28
|
+
- Rescue `NoMethodError` (for `nil`) and `TypeError` (for non-`String`) (e33522e)
|
29
|
+
- Raise `ArgumentError` if url scheme is not `http` or `https` (8eb1b1a)
|
30
|
+
- Shorten up User Agent string (f9717b4)
|
31
|
+
- Refactor `HTTPRequest` class using specification defaults (feef2ba)
|
11
32
|
|
12
33
|
## 0.4.0 / 2019-05-01
|
13
34
|
|
14
|
-
- Add `IndieWeb::Endpoints.client` method (
|
15
|
-
- Rename base `Error` class to `IndieWebEndpointsError` (
|
16
|
-
- Add `HttpRequest` class (
|
35
|
+
- Add `IndieWeb::Endpoints.client` method (c4d42d0)
|
36
|
+
- Rename base `Error` class to `IndieWebEndpointsError` (d6d6f98)
|
37
|
+
- Add `HttpRequest` class (7864cbd)
|
17
38
|
|
18
39
|
## 0.3.0 / 2019-04-30
|
19
40
|
|
20
|
-
- `IndieWeb::Endpoints::Client#endpoints` returns an `OpenStruct` instead of a `Hash` (
|
41
|
+
- `IndieWeb::Endpoints::Client#endpoints` returns an `OpenStruct` instead of a `Hash` (c209b0b).
|
21
42
|
|
22
43
|
## 0.2.0 / 2019-04-25
|
23
44
|
|
24
|
-
- Subclass exceptions under `IndieWeb::Endpoints::Error` (
|
25
|
-
- Refactor parsers and `Registerable` module (
|
26
|
-
- Refactor Client#response method (
|
45
|
+
- Subclass exceptions under `IndieWeb::Endpoints::Error` (667eec7)
|
46
|
+
- Refactor parsers and `Registerable` module (3b96858)
|
47
|
+
- Refactor `Client#response` method (c36fda3)
|
27
48
|
|
28
49
|
## 0.1.0 / 2019-04-24
|
29
50
|
|
data/CONTRIBUTING.md
CHANGED
@@ -8,9 +8,9 @@ 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 2.4.
|
11
|
+
indieweb-endpoints-ruby is developed using Ruby 2.4.7 and is additionally tested against Ruby 2.5 and 2.6 using [Travis CI](https://travis-ci.com/indieweb/indieweb-endpoints-ruby).
|
12
12
|
|
13
|
-
Before making changes to indieweb-endpoints-ruby, you'll want to install Ruby 2.4.
|
13
|
+
Before making changes to indieweb-endpoints-ruby, you'll want to install Ruby 2.4.7. It's recommended that you use 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). Once you've installed Ruby 2.4.7 using your method of choice, install the project's gems by running:
|
14
14
|
|
15
15
|
```sh
|
16
16
|
bundle install
|
data/README.md
CHANGED
@@ -18,7 +18,7 @@
|
|
18
18
|
|
19
19
|
Before installing and using indieweb-endpoints-ruby, you'll want to have [Ruby](https://www.ruby-lang.org) 2.4 (or newer) installed. It's recommended that you use 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).
|
20
20
|
|
21
|
-
indieweb-endpoints-ruby is developed using Ruby 2.4.
|
21
|
+
indieweb-endpoints-ruby is developed using Ruby 2.4.7 and is additionally tested against Ruby 2.5 and 2.6 using [Travis CI](https://travis-ci.com/indieweb/indieweb-endpoints-ruby).
|
22
22
|
|
23
23
|
## Installation
|
24
24
|
|
@@ -47,10 +47,10 @@ require 'indieweb/endpoints'
|
|
47
47
|
|
48
48
|
endpoints = IndieWeb::Endpoints.get('https://aaronparecki.com')
|
49
49
|
|
50
|
-
puts endpoints # => #<OpenStruct
|
50
|
+
puts endpoints # => #<OpenStruct authorization_endpoint="https://aaronparecki.com/auth", 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">
|
51
51
|
```
|
52
52
|
|
53
|
-
This example will search `https://aaronparecki.com` for valid IndieAuth, Micropub, and Webmention endpoints. In this case, the program returns an `OpenStruct` with the following attributes:
|
53
|
+
This example will search `https://aaronparecki.com` for valid IndieAuth, Micropub, and Webmention endpoints. In this case, the program returns an `OpenStruct` with the following attributes (represented below as a `Hash`):
|
54
54
|
|
55
55
|
```ruby
|
56
56
|
{
|
@@ -72,11 +72,18 @@ Should the need arise, you may work with the `IndieWeb::Endpoints::Client` class
|
|
72
72
|
```ruby
|
73
73
|
require 'indieweb/endpoints'
|
74
74
|
|
75
|
-
client = IndieWeb::Endpoints.
|
75
|
+
client = IndieWeb::Endpoints::Client.new('https://aaronparecki.com')
|
76
76
|
|
77
|
-
puts client.response
|
78
|
-
|
79
|
-
|
77
|
+
puts client.response # => #<HTTP::Response/1.1 200 OK {…}>
|
78
|
+
|
79
|
+
endpoints = client.endpoints
|
80
|
+
|
81
|
+
puts endpoints.authorization_endpoint # => 'https://aaronparecki.com/auth'
|
82
|
+
puts endpoints.micropub # => 'https://aaronparecki.com/micropub'
|
83
|
+
puts endpoints.microsub # => 'https://aperture.p3k.io/microsub/1'
|
84
|
+
puts endpoints.redirect_uri # => nil
|
85
|
+
puts endpoints.token_endpoint # => 'https://aaronparecki.com/auth/token'
|
86
|
+
puts endpoints.webmention # => 'https://webmention.io/aaronpk/webmention'
|
80
87
|
```
|
81
88
|
|
82
89
|
### Exception Handling
|
data/indieweb-endpoints.gemspec
CHANGED
@@ -28,15 +28,16 @@ Gem::Specification.new do |spec|
|
|
28
28
|
spec.add_development_dependency 'rake', '~> 12.3'
|
29
29
|
spec.add_development_dependency 'reek', '~> 5.4'
|
30
30
|
spec.add_development_dependency 'rspec', '~> 3.8'
|
31
|
-
spec.add_development_dependency 'rubocop', '~> 0.
|
32
|
-
spec.add_development_dependency 'rubocop-performance', '~> 1.
|
33
|
-
spec.add_development_dependency 'rubocop-rspec', '~> 1.
|
34
|
-
spec.add_development_dependency 'simplecov', '~> 0.
|
35
|
-
spec.add_development_dependency 'simplecov-console', '~> 0.
|
36
|
-
spec.add_development_dependency 'webmock', '~> 3.
|
37
|
-
|
38
|
-
spec.add_runtime_dependency 'absolutely', '~>
|
39
|
-
spec.add_runtime_dependency 'addressable', '~> 2.
|
31
|
+
spec.add_development_dependency 'rubocop', '~> 0.74.0'
|
32
|
+
spec.add_development_dependency 'rubocop-performance', '~> 1.4'
|
33
|
+
spec.add_development_dependency 'rubocop-rspec', '~> 1.35'
|
34
|
+
spec.add_development_dependency 'simplecov', '~> 0.17.0'
|
35
|
+
spec.add_development_dependency 'simplecov-console', '~> 0.5.0'
|
36
|
+
spec.add_development_dependency 'webmock', '~> 3.7'
|
37
|
+
|
38
|
+
spec.add_runtime_dependency 'absolutely', '~> 3.0'
|
39
|
+
spec.add_runtime_dependency 'addressable', '~> 2.7'
|
40
40
|
spec.add_runtime_dependency 'http', '~> 5.0.0.pre'
|
41
|
+
spec.add_runtime_dependency 'link-header-parser', '~> 0.2.0'
|
41
42
|
spec.add_runtime_dependency 'nokogiri', '~> 1.10'
|
42
43
|
end
|
data/lib/indieweb/endpoints.rb
CHANGED
@@ -1,16 +1,23 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
|
1
3
|
require 'absolutely'
|
2
4
|
require 'addressable/uri'
|
3
5
|
require 'http'
|
6
|
+
require 'link-header-parser'
|
4
7
|
require 'nokogiri'
|
5
8
|
|
6
9
|
require 'indieweb/endpoints/version'
|
7
10
|
require 'indieweb/endpoints/exceptions'
|
8
11
|
|
9
|
-
require 'indieweb/endpoints/
|
10
|
-
|
11
|
-
require 'indieweb/endpoints/
|
12
|
+
require 'indieweb/endpoints/concerns/registerable'
|
13
|
+
|
14
|
+
require 'indieweb/endpoints/services/http_request_service'
|
15
|
+
require 'indieweb/endpoints/services/response_body_parser_service'
|
16
|
+
require 'indieweb/endpoints/services/response_headers_parser_service'
|
12
17
|
|
18
|
+
require 'indieweb/endpoints/client'
|
13
19
|
require 'indieweb/endpoints/parsers'
|
20
|
+
|
14
21
|
require 'indieweb/endpoints/parsers/authorization_endpoint_parser'
|
15
22
|
require 'indieweb/endpoints/parsers/micropub_parser'
|
16
23
|
require 'indieweb/endpoints/parsers/microsub_parser'
|
@@ -20,14 +27,8 @@ require 'indieweb/endpoints/parsers/webmention_parser'
|
|
20
27
|
|
21
28
|
module IndieWeb
|
22
29
|
module Endpoints
|
23
|
-
|
24
|
-
|
25
|
-
Client.new(url)
|
26
|
-
end
|
27
|
-
|
28
|
-
def get(url)
|
29
|
-
client(url).endpoints
|
30
|
-
end
|
30
|
+
def self.get(url)
|
31
|
+
Client.new(url).endpoints
|
31
32
|
end
|
32
33
|
end
|
33
34
|
end
|
@@ -1,11 +1,9 @@
|
|
1
1
|
module IndieWeb
|
2
2
|
module Endpoints
|
3
3
|
module Parsers
|
4
|
-
extend Registerable
|
4
|
+
extend Concerns::Registerable
|
5
5
|
|
6
6
|
class BaseParser
|
7
|
-
attr_reader :response
|
8
|
-
|
9
7
|
def initialize(response)
|
10
8
|
raise ArgumentError, "response must be an HTTP::Response (given #{response.class.name})" unless response.is_a?(HTTP::Response)
|
11
9
|
|
@@ -13,111 +11,29 @@ module IndieWeb
|
|
13
11
|
end
|
14
12
|
|
15
13
|
def results
|
16
|
-
|
14
|
+
mapped_results.shift
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
attr_reader :response
|
17
20
|
|
18
|
-
|
21
|
+
def mapped_results
|
22
|
+
@mapped_results ||= results_from_http_request.map { |endpoint| Absolutely.to_abs(base: response.uri.to_s, relative: endpoint) }.uniq.sort
|
19
23
|
rescue Absolutely::InvalidURIError => exception
|
20
24
|
raise InvalidURIError, exception
|
21
25
|
end
|
22
26
|
|
23
|
-
private
|
24
|
-
|
25
27
|
def results_from_body
|
26
|
-
|
28
|
+
@results_from_body ||= Services::ResponseBodyParserService.new.parse(response, self.class.identifier)
|
27
29
|
end
|
28
30
|
|
29
31
|
def results_from_headers
|
30
|
-
|
32
|
+
@results_from_headers ||= Services::ResponseHeadersParserService.new.parse(response, self.class.identifier)
|
31
33
|
end
|
32
34
|
|
33
35
|
def results_from_http_request
|
34
|
-
@results_from_http_request ||= results_from_headers
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
class LinkElementParser
|
39
|
-
attr_reader :identifier, :response
|
40
|
-
|
41
|
-
def initialize(response, identifier)
|
42
|
-
@response = response
|
43
|
-
@identifier = identifier
|
44
|
-
end
|
45
|
-
|
46
|
-
def results
|
47
|
-
link_element['href'] if response_is_html && link_element
|
48
|
-
end
|
49
|
-
|
50
|
-
private
|
51
|
-
|
52
|
-
def doc
|
53
|
-
@doc ||= Nokogiri::HTML(response.body.to_s)
|
54
|
-
end
|
55
|
-
|
56
|
-
def link_element
|
57
|
-
# Return first `link` element with valid `rel` attribute
|
58
|
-
# https://www.w3.org/TR/indieauth/#discovery-1
|
59
|
-
# https://www.w3.org/TR/micropub/#endpoint-discovery
|
60
|
-
@link_element ||= link_elements.shift
|
61
|
-
end
|
62
|
-
|
63
|
-
def link_elements
|
64
|
-
@link_elements ||= doc.css(link_elements_css_selector)
|
65
|
-
end
|
66
|
-
|
67
|
-
def link_elements_css_selector
|
68
|
-
@link_elements_css_selector ||= %(link[rel~="#{identifier}"][href]:not([href*="#"]))
|
69
|
-
end
|
70
|
-
|
71
|
-
def response_is_html
|
72
|
-
@response_is_html ||= response.mime_type == 'text/html'
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
class LinkHeaderParser
|
77
|
-
# Ultra-orthodox pattern matching allowed values in Link header `rel` parameter
|
78
|
-
# https://tools.ietf.org/html/rfc8288#section-3.3
|
79
|
-
REGEXP_REG_REL_TYPE_PATTERN = '[a-z\d][a-z\d\-\.]*'.freeze
|
80
|
-
|
81
|
-
# Liberal pattern capturing a string of text (excepting the octothorp) between angle brackets
|
82
|
-
# https://tools.ietf.org/html/rfc5988#section-5.1
|
83
|
-
REGEXP_TARGET_URI_PATTERN = '^<(.[^#]*)>;'.freeze
|
84
|
-
|
85
|
-
attr_reader :identifier, :response
|
86
|
-
|
87
|
-
def initialize(response, identifier)
|
88
|
-
@response = response
|
89
|
-
@identifier = identifier
|
90
|
-
end
|
91
|
-
|
92
|
-
def results
|
93
|
-
return unless link_header
|
94
|
-
|
95
|
-
endpoint_match_data = link_header.match(/#{REGEXP_TARGET_URI_PATTERN}/)
|
96
|
-
|
97
|
-
return endpoint_match_data[1] if endpoint_match_data
|
98
|
-
end
|
99
|
-
|
100
|
-
private
|
101
|
-
|
102
|
-
def discrete_link_headers
|
103
|
-
# Split Link headers with multiple values, flatten the resulting array, and strip whitespace
|
104
|
-
# https://webmention.rocks/test/19
|
105
|
-
@discrete_link_headers ||= response.headers.get('link').map { |header| header.split(',') }.flatten.map(&:strip)
|
106
|
-
end
|
107
|
-
|
108
|
-
def link_header
|
109
|
-
@link_header ||= link_headers.shift
|
110
|
-
end
|
111
|
-
|
112
|
-
def link_headers
|
113
|
-
# Reduce Link headers to those with valid `rel` attribute
|
114
|
-
@link_headers ||= discrete_link_headers.find_all { |header| header.match?(/#{REGEXP_TARGET_URI_PATTERN}\s*#{regexp_rel_paramater_pattern}/) }
|
115
|
-
end
|
116
|
-
|
117
|
-
def regexp_rel_paramater_pattern
|
118
|
-
# Ultra-orthodox pattern matching Link header `rel` parameter including a matching identifier value
|
119
|
-
# https://www.w3.org/TR/webmention/#sender-discovers-receiver-webmention-endpoint
|
120
|
-
@regexp_rel_paramater_pattern ||= %(rel="?(?:#{REGEXP_REG_REL_TYPE_PATTERN}+\s)?#{identifier}(?:\s#{REGEXP_REG_REL_TYPE_PATTERN})?"?)
|
36
|
+
@results_from_http_request ||= [results_from_headers, results_from_body].flatten.compact
|
121
37
|
end
|
122
38
|
end
|
123
39
|
end
|
@@ -9,43 +9,9 @@ module IndieWeb
|
|
9
9
|
Parsers.register(self)
|
10
10
|
|
11
11
|
def results
|
12
|
-
return unless
|
12
|
+
return unless mapped_results.any?
|
13
13
|
|
14
|
-
|
15
|
-
rescue Absolutely::InvalidURIError => exception
|
16
|
-
raise InvalidURIError, exception
|
17
|
-
end
|
18
|
-
|
19
|
-
private
|
20
|
-
|
21
|
-
def results_from_body
|
22
|
-
RedirectUriLinkElementParser.new(response, self.class.identifier).results
|
23
|
-
end
|
24
|
-
|
25
|
-
def results_from_headers
|
26
|
-
RedirectUriLinkHeaderParser.new(response, self.class.identifier).results
|
27
|
-
end
|
28
|
-
|
29
|
-
def results_from_http_request
|
30
|
-
@results_from_http_request ||= [results_from_headers, results_from_body].flatten.compact
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
class RedirectUriLinkElementParser < LinkElementParser
|
35
|
-
def results
|
36
|
-
link_elements.map { |element| element['href'] } if response_is_html && link_elements.any?
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
class RedirectUriLinkHeaderParser < LinkHeaderParser
|
41
|
-
def results
|
42
|
-
return unless link_headers.any?
|
43
|
-
|
44
|
-
link_headers.map do |header|
|
45
|
-
endpoint_match_data = header.match(REGEXP_TARGET_URI_PATTERN)
|
46
|
-
|
47
|
-
endpoint_match_data[1] if endpoint_match_data
|
48
|
-
end
|
14
|
+
mapped_results
|
49
15
|
end
|
50
16
|
end
|
51
17
|
end
|
@@ -10,22 +10,13 @@ module IndieWeb
|
|
10
10
|
|
11
11
|
private
|
12
12
|
|
13
|
-
def
|
14
|
-
|
13
|
+
def results_for_node(node)
|
14
|
+
Services::ResponseBodyParserService.new.parse(response, self.class.identifier, node)
|
15
15
|
end
|
16
|
-
end
|
17
|
-
|
18
|
-
class WebmentionLinkElementParser < LinkElementParser
|
19
|
-
private
|
20
16
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
@link_element ||= link_elements.find { |element| %w[a link].include?(element.name) }
|
25
|
-
end
|
26
|
-
|
27
|
-
def link_elements_css_selector
|
28
|
-
@link_elements_css_selector ||= %([rel~="#{identifier}"][href]:not([href*="#"]))
|
17
|
+
# https://www.w3.org/TR/webmention/#sender-discovers-receiver-webmention-endpoint
|
18
|
+
def results_from_body
|
19
|
+
@results_from_body ||= [results_for_node('link'), results_for_node('a')].flatten.compact
|
29
20
|
end
|
30
21
|
end
|
31
22
|
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module IndieWeb
|
2
|
+
module Endpoints
|
3
|
+
module Services
|
4
|
+
class HttpRequestService
|
5
|
+
# Defaults derived from Webmention specification examples
|
6
|
+
# https://www.w3.org/TR/webmention/#limits-on-get-requests
|
7
|
+
HTTP_CLIENT_OPTS = {
|
8
|
+
follow: {
|
9
|
+
max_hops: 20
|
10
|
+
},
|
11
|
+
headers: {
|
12
|
+
accept: '*/*',
|
13
|
+
user_agent: 'IndieWeb Endpoint Discovery (https://rubygems.org/gems/indieweb-endpoints)'
|
14
|
+
},
|
15
|
+
timeout_options: {
|
16
|
+
connect_timeout: 5,
|
17
|
+
read_timeout: 5
|
18
|
+
}
|
19
|
+
}.freeze
|
20
|
+
|
21
|
+
def initialize
|
22
|
+
@client = HTTP::Client.new(HTTP_CLIENT_OPTS)
|
23
|
+
end
|
24
|
+
|
25
|
+
def get(uri)
|
26
|
+
client.request(:get, uri)
|
27
|
+
rescue HTTP::ConnectionError,
|
28
|
+
HTTP::TimeoutError,
|
29
|
+
HTTP::Redirector::TooManyRedirectsError => exception
|
30
|
+
raise IndieWeb::Endpoints.const_get(exception.class.name.split('::').last), exception
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
attr_accessor :client
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module IndieWeb
|
2
|
+
module Endpoints
|
3
|
+
module Services
|
4
|
+
class ResponseBodyParserService
|
5
|
+
def parse(response, identifier, node = 'link')
|
6
|
+
return unless response.mime_type == 'text/html'
|
7
|
+
|
8
|
+
# Reject endpoints that contain a fragment identifier
|
9
|
+
Nokogiri::HTML(response.body.to_s).css(%(#{node}[rel~="#{identifier}"][href]:not([href*="#"]))).map { |element| element['href'] }
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module IndieWeb
|
2
|
+
module Endpoints
|
3
|
+
module Services
|
4
|
+
class ResponseHeadersParserService
|
5
|
+
def parse(response, identifier)
|
6
|
+
headers = LinkHeaderParser.parse(response.headers.get('link'), base: response.uri.to_s).by_relation_type[identifier]
|
7
|
+
|
8
|
+
return unless headers
|
9
|
+
|
10
|
+
# Reject endpoints that contain a fragment identifier
|
11
|
+
headers.reject { |header| Addressable::URI.parse(header.target_uri).fragment }.map(&:target_uri)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: indieweb-endpoints
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Garber
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-08-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -58,112 +58,112 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 0.
|
61
|
+
version: 0.74.0
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 0.
|
68
|
+
version: 0.74.0
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rubocop-performance
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '1.
|
75
|
+
version: '1.4'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '1.
|
82
|
+
version: '1.4'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: rubocop-rspec
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '1.
|
89
|
+
version: '1.35'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '1.
|
96
|
+
version: '1.35'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: simplecov
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: 0.
|
103
|
+
version: 0.17.0
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: 0.
|
110
|
+
version: 0.17.0
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: simplecov-console
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
115
|
- - "~>"
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: 0.
|
117
|
+
version: 0.5.0
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
122
|
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version: 0.
|
124
|
+
version: 0.5.0
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: webmock
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
129
|
- - "~>"
|
130
130
|
- !ruby/object:Gem::Version
|
131
|
-
version: '3.
|
131
|
+
version: '3.7'
|
132
132
|
type: :development
|
133
133
|
prerelease: false
|
134
134
|
version_requirements: !ruby/object:Gem::Requirement
|
135
135
|
requirements:
|
136
136
|
- - "~>"
|
137
137
|
- !ruby/object:Gem::Version
|
138
|
-
version: '3.
|
138
|
+
version: '3.7'
|
139
139
|
- !ruby/object:Gem::Dependency
|
140
140
|
name: absolutely
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
142
142
|
requirements:
|
143
143
|
- - "~>"
|
144
144
|
- !ruby/object:Gem::Version
|
145
|
-
version: '
|
145
|
+
version: '3.0'
|
146
146
|
type: :runtime
|
147
147
|
prerelease: false
|
148
148
|
version_requirements: !ruby/object:Gem::Requirement
|
149
149
|
requirements:
|
150
150
|
- - "~>"
|
151
151
|
- !ruby/object:Gem::Version
|
152
|
-
version: '
|
152
|
+
version: '3.0'
|
153
153
|
- !ruby/object:Gem::Dependency
|
154
154
|
name: addressable
|
155
155
|
requirement: !ruby/object:Gem::Requirement
|
156
156
|
requirements:
|
157
157
|
- - "~>"
|
158
158
|
- !ruby/object:Gem::Version
|
159
|
-
version: '2.
|
159
|
+
version: '2.7'
|
160
160
|
type: :runtime
|
161
161
|
prerelease: false
|
162
162
|
version_requirements: !ruby/object:Gem::Requirement
|
163
163
|
requirements:
|
164
164
|
- - "~>"
|
165
165
|
- !ruby/object:Gem::Version
|
166
|
-
version: '2.
|
166
|
+
version: '2.7'
|
167
167
|
- !ruby/object:Gem::Dependency
|
168
168
|
name: http
|
169
169
|
requirement: !ruby/object:Gem::Requirement
|
@@ -178,6 +178,20 @@ dependencies:
|
|
178
178
|
- - "~>"
|
179
179
|
- !ruby/object:Gem::Version
|
180
180
|
version: 5.0.0.pre
|
181
|
+
- !ruby/object:Gem::Dependency
|
182
|
+
name: link-header-parser
|
183
|
+
requirement: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - "~>"
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: 0.2.0
|
188
|
+
type: :runtime
|
189
|
+
prerelease: false
|
190
|
+
version_requirements: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
192
|
+
- - "~>"
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: 0.2.0
|
181
195
|
- !ruby/object:Gem::Dependency
|
182
196
|
name: nokogiri
|
183
197
|
requirement: !ruby/object:Gem::Requirement
|
@@ -219,8 +233,8 @@ files:
|
|
219
233
|
- indieweb-endpoints.gemspec
|
220
234
|
- lib/indieweb/endpoints.rb
|
221
235
|
- lib/indieweb/endpoints/client.rb
|
236
|
+
- lib/indieweb/endpoints/concerns/registerable.rb
|
222
237
|
- lib/indieweb/endpoints/exceptions.rb
|
223
|
-
- lib/indieweb/endpoints/http_request.rb
|
224
238
|
- lib/indieweb/endpoints/parsers.rb
|
225
239
|
- lib/indieweb/endpoints/parsers/authorization_endpoint_parser.rb
|
226
240
|
- lib/indieweb/endpoints/parsers/micropub_parser.rb
|
@@ -228,14 +242,16 @@ files:
|
|
228
242
|
- lib/indieweb/endpoints/parsers/redirect_uri_parser.rb
|
229
243
|
- lib/indieweb/endpoints/parsers/token_endpoint_parser.rb
|
230
244
|
- lib/indieweb/endpoints/parsers/webmention_parser.rb
|
231
|
-
- lib/indieweb/endpoints/
|
245
|
+
- lib/indieweb/endpoints/services/http_request_service.rb
|
246
|
+
- lib/indieweb/endpoints/services/response_body_parser_service.rb
|
247
|
+
- lib/indieweb/endpoints/services/response_headers_parser_service.rb
|
232
248
|
- lib/indieweb/endpoints/version.rb
|
233
249
|
homepage: https://github.com/indieweb/indieweb-endpoints-ruby
|
234
250
|
licenses:
|
235
251
|
- MIT
|
236
252
|
metadata:
|
237
253
|
bug_tracker_uri: https://github.com/indieweb/indieweb-endpoints-ruby/issues
|
238
|
-
changelog_uri: https://github.com/indieweb/indieweb-endpoints-ruby/blob/
|
254
|
+
changelog_uri: https://github.com/indieweb/indieweb-endpoints-ruby/blob/v1.0.2/CHANGELOG.md
|
239
255
|
post_install_message:
|
240
256
|
rdoc_options: []
|
241
257
|
require_paths:
|
@@ -254,7 +270,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
254
270
|
- !ruby/object:Gem::Version
|
255
271
|
version: '0'
|
256
272
|
requirements: []
|
257
|
-
rubygems_version: 3.0.
|
273
|
+
rubygems_version: 3.0.6
|
258
274
|
signing_key:
|
259
275
|
specification_version: 4
|
260
276
|
summary: Discover a URL’s IndieAuth, Micropub, Microsub, and Webmention endpoints.
|
@@ -1,29 +0,0 @@
|
|
1
|
-
module IndieWeb
|
2
|
-
module Endpoints
|
3
|
-
class HttpRequest
|
4
|
-
# Defaults derived from Webmention specification examples
|
5
|
-
# https://www.w3.org/TR/webmention/#limits-on-get-requests
|
6
|
-
HTTP_CLIENT_OPTS = {
|
7
|
-
follow: {
|
8
|
-
max_hops: 20
|
9
|
-
},
|
10
|
-
headers: {
|
11
|
-
accept: '*/*',
|
12
|
-
user_agent: 'IndieWeb Endpoint Discovery (https://rubygems.org/gems/indieweb-endpoints)'
|
13
|
-
},
|
14
|
-
timeout_options: {
|
15
|
-
connect_timeout: 5,
|
16
|
-
read_timeout: 5
|
17
|
-
}
|
18
|
-
}.freeze
|
19
|
-
|
20
|
-
def self.get(uri)
|
21
|
-
HTTP::Client.new(HTTP_CLIENT_OPTS).request(:get, uri)
|
22
|
-
rescue HTTP::ConnectionError,
|
23
|
-
HTTP::TimeoutError,
|
24
|
-
HTTP::Redirector::TooManyRedirectsError => exception
|
25
|
-
raise IndieWeb::Endpoints.const_get(exception.class.name.split('::').last), exception
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|