webmention-endpoint 0.3.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +6 -9
- data/lib/webmention/endpoint.rb +3 -1
- data/lib/webmention/endpoint/client.rb +21 -0
- data/lib/webmention/endpoint/discover.rb +7 -30
- data/lib/webmention/endpoint/response.rb +29 -0
- data/lib/webmention/endpoint/version.rb +1 -1
- data/webmention-endpoint.gemspec +1 -1
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0d245a49f0a3fe53fdee075040a00815e6165d6c
|
4
|
+
data.tar.gz: '09cde84455b4cc0652c4f02f7f76ba2c1e50092f'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 91b061d760180be8fda3aa7ce5a879309d63ce1c71131ac7f4affc88b2b9956d6f8f9d3f73e857d97f5182a30f84ce179fa878eb84a3187c07e94f911b6b7610
|
7
|
+
data.tar.gz: ed7b10de7d833d3178e6d9e4b08e65b5b40dd3f7195e87e0a046b627ae1d94b1c5a96924906938e9169a24a12e7f50eb87a9bd2dfe1358f6944862ee7a7431df
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 1.0.0 / 2018-07-17
|
4
|
+
|
5
|
+
- Adds new `Webmention::Endpoint::Client` and `Webmention::Endpoint::Response` classes and refactors `Webmention::Endpoint::Discover` API ([a05d041](https://github.com/jgarber623/webmention-endpoint-ruby/commit/a05d041)).
|
6
|
+
- Updates specs ([706f39b](https://github.com/jgarber623/webmention-endpoint-ruby/commit/706f39b)) and documentation ([7110b8c](https://github.com/jgarber623/webmention-endpoint-ruby/commit/7110b8c)).
|
7
|
+
|
3
8
|
## 0.3.1 / 2018-07-05
|
4
9
|
|
5
10
|
- Updates [Absolutely](https://github.com/jgarber623/absolutely) to v1.1.0 ([4a62800](https://github.com/jgarber623/webmention-endpoint-ruby/commit/4a62800)).
|
data/README.md
CHANGED
@@ -11,7 +11,7 @@
|
|
11
11
|
|
12
12
|
## Key Features
|
13
13
|
|
14
|
-
- Compliant with [Section 3.1.2](https://www.w3.org/TR/webmention/#sender-discovers-receiver-webmention-endpoint) of [the W3C's Webmention
|
14
|
+
- Compliant with [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/).
|
15
15
|
- Passes all Endpoint Discovery tests on [webmention.rocks](https://webmention.rocks).
|
16
16
|
- Supports Ruby 2.4 and newer.
|
17
17
|
|
@@ -51,7 +51,7 @@ endpoint = Webmention::Endpoint.discover('https://webmention.rocks/test/1')
|
|
51
51
|
puts endpoint # returns String: 'https://webmention.rocks/test/1/webmention'
|
52
52
|
```
|
53
53
|
|
54
|
-
This example will search `https://webmention.rocks/test/1` for a valid Webmention endpoint in accordance with the rules described in [the W3C's Webmention
|
54
|
+
This example will search `https://webmention.rocks/test/1` for a valid Webmention endpoint in accordance with the rules described in [the W3C's Webmention Recommendation](https://www.w3.org/TR/webmention/#sender-discovers-receiver-webmention-endpoint). In this case, the program returns a string: `https://webmention.rocks/test/1/webmention`.
|
55
55
|
|
56
56
|
If no endpoint is discovered at the provided URL, the program will return `nil`:
|
57
57
|
|
@@ -65,18 +65,15 @@ puts endpoint.nil? # returns Boolean: true
|
|
65
65
|
|
66
66
|
### Advanced Usage
|
67
67
|
|
68
|
-
Should the need arise, you may work directly with the `Webmention::Endpoint::
|
68
|
+
Should the need arise, you may work directly with the `Webmention::Endpoint::Client` class:
|
69
69
|
|
70
70
|
```ruby
|
71
71
|
require 'webmention/endpoint'
|
72
72
|
|
73
|
-
|
73
|
+
client = Webmention::Endpoint::Client.new('https://webmention.rocks/test/1')
|
74
74
|
|
75
|
-
puts
|
76
|
-
puts
|
77
|
-
|
78
|
-
puts discoverer.uri # returns Addressable::URI
|
79
|
-
puts discoverer.response # returns HTTP::Response
|
75
|
+
puts client.response # returns HTTP::Response
|
76
|
+
puts client.endpoint # returns String: 'https://webmention.rocks/test/1/webmention'
|
80
77
|
```
|
81
78
|
|
82
79
|
### Exception Handling
|
data/lib/webmention/endpoint.rb
CHANGED
@@ -5,12 +5,14 @@ require 'nokogiri'
|
|
5
5
|
|
6
6
|
require 'webmention/endpoint/version'
|
7
7
|
require 'webmention/endpoint/error'
|
8
|
+
require 'webmention/endpoint/client'
|
8
9
|
require 'webmention/endpoint/discover'
|
10
|
+
require 'webmention/endpoint/response'
|
9
11
|
|
10
12
|
module Webmention
|
11
13
|
module Endpoint
|
12
14
|
def self.discover(url)
|
13
|
-
|
15
|
+
Client.new(url).endpoint
|
14
16
|
end
|
15
17
|
end
|
16
18
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Webmention
|
2
|
+
module Endpoint
|
3
|
+
class Client
|
4
|
+
def initialize(url)
|
5
|
+
raise ArgumentError, "url must be a String (given #{url.class.name})" unless url.is_a?(String)
|
6
|
+
|
7
|
+
@uri = Addressable::URI.parse(url)
|
8
|
+
rescue Addressable::URI::InvalidURIError => error
|
9
|
+
raise InvalidURIError, error
|
10
|
+
end
|
11
|
+
|
12
|
+
def endpoint
|
13
|
+
@endpoint ||= Discover.new(response).endpoint
|
14
|
+
end
|
15
|
+
|
16
|
+
def response
|
17
|
+
@response ||= Response.new(@uri).response
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -1,11 +1,6 @@
|
|
1
1
|
module Webmention
|
2
2
|
module Endpoint
|
3
3
|
class Discover
|
4
|
-
HTTP_HEADERS_OPTS = {
|
5
|
-
accept: '*/*',
|
6
|
-
user_agent: 'Webmention Endpoint Discovery (https://rubygems.org/gems/webmention-endpoint)'
|
7
|
-
}.freeze
|
8
|
-
|
9
4
|
# Ultra-orthodox pattern matching allowed values in Link header `rel` parameter
|
10
5
|
# https://tools.ietf.org/html/rfc8288#section-3.3
|
11
6
|
REGEXP_REG_REL_TYPE_PATTERN = '[a-z\d][a-z\d\-\.]*'.freeze
|
@@ -18,44 +13,26 @@ module Webmention
|
|
18
13
|
# https://www.w3.org/TR/webmention/#sender-discovers-receiver-webmention-endpoint-p-1
|
19
14
|
REGEXP_WEBMENTION_REL_PATTERN = /(?:;|\s)rel="?(?:#{REGEXP_REG_REL_TYPE_PATTERN}+\s)?webmention(?:\s#{REGEXP_REG_REL_TYPE_PATTERN})?"?/
|
20
15
|
|
21
|
-
|
22
|
-
|
23
|
-
def initialize(url)
|
24
|
-
raise ArgumentError, "url must be a String (given #{url.class.name})" unless url.is_a?(String)
|
16
|
+
def initialize(response)
|
17
|
+
raise ArgumentError, "response must be an HTTP::Response (given #{response.class.name})" unless response.is_a?(HTTP::Response)
|
25
18
|
|
26
|
-
@
|
27
|
-
@uri = Addressable::URI.parse(url)
|
28
|
-
rescue Addressable::URI::InvalidURIError => error
|
29
|
-
raise InvalidURIError, error
|
19
|
+
@response = response
|
30
20
|
end
|
31
21
|
|
32
22
|
def endpoint
|
33
23
|
return unless endpoint_from_http_request
|
34
24
|
|
35
|
-
@endpoint ||= Absolutely.to_absolute_uri(base:
|
25
|
+
@endpoint ||= Absolutely.to_absolute_uri(base: @response.uri.to_s, relative: endpoint_from_http_request)
|
36
26
|
rescue Absolutely::InvalidURIError => error
|
37
27
|
raise InvalidURIError, error
|
38
28
|
end
|
39
29
|
|
40
|
-
def response
|
41
|
-
@response ||= HTTP.follow.headers(HTTP_HEADERS_OPTS).timeout(
|
42
|
-
connect: 10,
|
43
|
-
read: 10
|
44
|
-
).get(uri)
|
45
|
-
rescue HTTP::ConnectionError => error
|
46
|
-
raise ConnectionError, error
|
47
|
-
rescue HTTP::TimeoutError => error
|
48
|
-
raise TimeoutError, error
|
49
|
-
rescue HTTP::Redirector::TooManyRedirectsError => error
|
50
|
-
raise TooManyRedirectsError, error
|
51
|
-
end
|
52
|
-
|
53
30
|
private
|
54
31
|
|
55
32
|
def endpoint_from_body
|
56
|
-
return unless response.mime_type == 'text/html'
|
33
|
+
return unless @response.mime_type == 'text/html'
|
57
34
|
|
58
|
-
doc = Nokogiri::HTML(response.body.to_s)
|
35
|
+
doc = Nokogiri::HTML(@response.body.to_s)
|
59
36
|
|
60
37
|
# Search response body for first `a` or `link` element with valid `rel` and `href` attributes
|
61
38
|
link_element = doc.css('[rel~="webmention"][href]').select { |element| %w[a link].include?(element.name) }.shift
|
@@ -64,7 +41,7 @@ module Webmention
|
|
64
41
|
end
|
65
42
|
|
66
43
|
def endpoint_from_headers
|
67
|
-
link_headers = response.headers.get('link')
|
44
|
+
link_headers = @response.headers.get('link')
|
68
45
|
|
69
46
|
return unless link_headers
|
70
47
|
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Webmention
|
2
|
+
module Endpoint
|
3
|
+
class Response
|
4
|
+
HTTP_HEADERS_OPTS = {
|
5
|
+
accept: '*/*',
|
6
|
+
user_agent: 'Webmention Endpoint Discovery (https://rubygems.org/gems/webmention-endpoint)'
|
7
|
+
}.freeze
|
8
|
+
|
9
|
+
def initialize(uri)
|
10
|
+
raise ArgumentError, "uri must be an Addressable::URI (given #{uri.class.name})" unless uri.is_a?(Addressable::URI)
|
11
|
+
|
12
|
+
@uri = uri
|
13
|
+
end
|
14
|
+
|
15
|
+
def response
|
16
|
+
@response ||= HTTP.follow.headers(HTTP_HEADERS_OPTS).timeout(
|
17
|
+
connect: 10,
|
18
|
+
read: 10
|
19
|
+
).get(@uri)
|
20
|
+
rescue HTTP::ConnectionError => error
|
21
|
+
raise ConnectionError, error
|
22
|
+
rescue HTTP::TimeoutError => error
|
23
|
+
raise TimeoutError, error
|
24
|
+
rescue HTTP::Redirector::TooManyRedirectsError => error
|
25
|
+
raise TooManyRedirectsError, error
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/webmention-endpoint.gemspec
CHANGED
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_development_dependency 'bundler', '~> 1.16', '>= 1.16.2'
|
24
24
|
spec.add_development_dependency 'rake', '~> 12.3', '>= 12.3.1'
|
25
25
|
spec.add_development_dependency 'rspec', '~> 3.7'
|
26
|
-
spec.add_development_dependency 'rubocop', '~> 0.
|
26
|
+
spec.add_development_dependency 'rubocop', '~> 0.58.0'
|
27
27
|
spec.add_development_dependency 'rubocop-rspec', '~> 1.27'
|
28
28
|
spec.add_development_dependency 'simplecov', '~> 0.16.1'
|
29
29
|
spec.add_development_dependency 'simplecov-console', '~> 0.4.2'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: webmention-endpoint
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Garber
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-07-
|
11
|
+
date: 2018-07-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -70,14 +70,14 @@ dependencies:
|
|
70
70
|
requirements:
|
71
71
|
- - "~>"
|
72
72
|
- !ruby/object:Gem::Version
|
73
|
-
version: 0.
|
73
|
+
version: 0.58.0
|
74
74
|
type: :development
|
75
75
|
prerelease: false
|
76
76
|
version_requirements: !ruby/object:Gem::Requirement
|
77
77
|
requirements:
|
78
78
|
- - "~>"
|
79
79
|
- !ruby/object:Gem::Version
|
80
|
-
version: 0.
|
80
|
+
version: 0.58.0
|
81
81
|
- !ruby/object:Gem::Dependency
|
82
82
|
name: rubocop-rspec
|
83
83
|
requirement: !ruby/object:Gem::Requirement
|
@@ -210,8 +210,10 @@ files:
|
|
210
210
|
- README.md
|
211
211
|
- Rakefile
|
212
212
|
- lib/webmention/endpoint.rb
|
213
|
+
- lib/webmention/endpoint/client.rb
|
213
214
|
- lib/webmention/endpoint/discover.rb
|
214
215
|
- lib/webmention/endpoint/error.rb
|
216
|
+
- lib/webmention/endpoint/response.rb
|
215
217
|
- lib/webmention/endpoint/version.rb
|
216
218
|
- webmention-endpoint.gemspec
|
217
219
|
homepage: https://github.com/jgarber623/webmention-endpoint-ruby
|