webmention 0.1.5 → 0.1.6
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 +7 -0
- data/.travis.yml +3 -3
- data/lib/webmention/client.rb +32 -11
- data/lib/webmention/version.rb +1 -1
- data/test/data/sample_html.rb +39 -0
- data/test/lib/webmention/discovery_test.rb +38 -2
- data/test/lib/webmention/url_test.rb +14 -0
- data/webmention.gemspec +3 -3
- metadata +29 -47
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: fb054d8a144253225b03c07b8cb1b70e78b01c5d
|
4
|
+
data.tar.gz: a73bd416adcbcd7c3aac45eb3fc053cb2a2296f8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 792d42a1dea5a5be92f1550753688699ddd4da47a166ed52fa09463cae5ce2c5264fc924cc10bb585f3f5eb84a2f7283805db44f11f82b5f6e3833e51da63bba
|
7
|
+
data.tar.gz: f8dd7faaa37ea1de848ccdb6b40dc737707a18c2f93a412d6ea48c2be8ae34058ca887506b3c84f42b93aed89835940003d944f6409e88bc842f6ce321aa2f62
|
data/.travis.yml
CHANGED
data/lib/webmention/client.rb
CHANGED
@@ -69,6 +69,9 @@ module Webmention
|
|
69
69
|
:target => target,
|
70
70
|
}
|
71
71
|
|
72
|
+
# Ensure the endpoint is an absolute URL
|
73
|
+
endpoint = absolute_endpoint endpoint, target
|
74
|
+
|
72
75
|
begin
|
73
76
|
response = HTTParty.post(endpoint, {
|
74
77
|
:body => data
|
@@ -105,7 +108,7 @@ module Webmention
|
|
105
108
|
})
|
106
109
|
|
107
110
|
# First check the HTTP Headers
|
108
|
-
if !response.headers['Link'].nil?
|
111
|
+
if !response.headers['Link'].nil?
|
109
112
|
endpoint = self.discover_webmention_endpoint_from_header response.headers['Link']
|
110
113
|
return endpoint if endpoint
|
111
114
|
end
|
@@ -129,25 +132,29 @@ module Webmention
|
|
129
132
|
|
130
133
|
def self.discover_webmention_endpoint_from_html html
|
131
134
|
doc = Nokogiri::HTML(html)
|
132
|
-
if !doc.css('[rel
|
133
|
-
doc.css('[rel
|
134
|
-
elsif !doc.css('[rel="http://webmention.org/"]').empty?
|
135
|
-
doc.css('[rel="http://webmention.org/"]').attribute("href").value
|
136
|
-
elsif !doc.css('[rel="http://webmention.org"]').empty?
|
137
|
-
doc.css('[rel="http://webmention.org"]').attribute("href").value
|
135
|
+
if !doc.css('[rel~="webmention"]').css('[href]').empty?
|
136
|
+
doc.css('[rel~="webmention"]').css('[href]').attribute("href").value
|
137
|
+
elsif !doc.css('[rel="http://webmention.org/"]').css('[href]').empty?
|
138
|
+
doc.css('[rel="http://webmention.org/"]').css('[href]').attribute("href").value
|
139
|
+
elsif !doc.css('[rel="http://webmention.org"]').css('[href]').empty?
|
140
|
+
doc.css('[rel="http://webmention.org"]').css('[href]').attribute("href").value
|
138
141
|
else
|
139
142
|
false
|
140
143
|
end
|
141
144
|
end
|
142
145
|
|
143
146
|
def self.discover_webmention_endpoint_from_header header
|
144
|
-
if matches = header.match(%r{<(
|
147
|
+
if matches = header.match(%r{<([^>]+)>; rel="[^"]*\s?webmention\s?[^"]*"})
|
148
|
+
return matches[1]
|
149
|
+
elsif matches = header.match(%r{<([^>]+)>; rel=webmention})
|
150
|
+
return matches[1]
|
151
|
+
elsif matches = header.match(%r{rel="[^"]*\s?webmention\s?[^"]*"; <([^>]+)>})
|
145
152
|
return matches[1]
|
146
|
-
elsif matches = header.match(%r{rel=
|
153
|
+
elsif matches = header.match(%r{rel=webmention; <([^>]+)>})
|
147
154
|
return matches[1]
|
148
|
-
elsif matches = header.match(%r{<(
|
155
|
+
elsif matches = header.match(%r{<([^>]+)>; rel="http://webmention\.org/?"})
|
149
156
|
return matches[1]
|
150
|
-
elsif matches = header.match(%r{rel="http://webmention\.org/?"; <(
|
157
|
+
elsif matches = header.match(%r{rel="http://webmention\.org/?"; <([^>]+)>})
|
151
158
|
return matches[1]
|
152
159
|
end
|
153
160
|
return false
|
@@ -165,5 +172,19 @@ module Webmention
|
|
165
172
|
|
166
173
|
return (url.is_a? URI::HTTP or url.is_a? URI::HTTPS)
|
167
174
|
end
|
175
|
+
|
176
|
+
# Public: Takes an endpoint and ensures an absolute URL is returned
|
177
|
+
#
|
178
|
+
# endpoint - Endpoint which may be an absolute or relative URL
|
179
|
+
# url - URL of the webmention
|
180
|
+
#
|
181
|
+
# Returns original endpoint if it is already an absolute URL; constructs
|
182
|
+
# new absolute URL using relative endpoint if not
|
183
|
+
def self.absolute_endpoint endpoint, url
|
184
|
+
unless Webmention::Client.valid_http_url? endpoint
|
185
|
+
endpoint = URI.join(url, endpoint).to_s
|
186
|
+
end
|
187
|
+
endpoint
|
188
|
+
end
|
168
189
|
end
|
169
190
|
end
|
data/lib/webmention/version.rb
CHANGED
data/test/data/sample_html.rb
CHANGED
@@ -82,5 +82,44 @@ class SampleData
|
|
82
82
|
</html>
|
83
83
|
eos
|
84
84
|
end
|
85
|
+
|
86
|
+
def self.rel_webmention_relative_with_path
|
87
|
+
<<-eos
|
88
|
+
<html>
|
89
|
+
<head>
|
90
|
+
<link href="/example/webmention" rel="webmention">
|
91
|
+
</head>
|
92
|
+
</html>
|
93
|
+
eos
|
94
|
+
end
|
85
95
|
|
96
|
+
def self.rel_webmention_relative_without_path
|
97
|
+
<<-eos
|
98
|
+
<html>
|
99
|
+
<head>
|
100
|
+
<link href="webmention.php" rel="webmention">
|
101
|
+
</head>
|
102
|
+
</html>
|
103
|
+
eos
|
104
|
+
end
|
105
|
+
|
106
|
+
def self.link_tag_multiple_rel_values
|
107
|
+
<<-eos
|
108
|
+
<html>
|
109
|
+
<head>
|
110
|
+
<link href="http://webmention.io/example/webmention" rel="webmention foo bar">
|
111
|
+
</head>
|
112
|
+
</html>
|
113
|
+
eos
|
114
|
+
end
|
115
|
+
|
116
|
+
def self.empty_link_tag_no_href
|
117
|
+
<<-eos
|
118
|
+
<html>
|
119
|
+
<head>
|
120
|
+
<link href="" rel="webmention">
|
121
|
+
</head>
|
122
|
+
</html>
|
123
|
+
eos
|
124
|
+
end
|
86
125
|
end
|
@@ -36,14 +36,22 @@ describe Webmention::Client do
|
|
36
36
|
end
|
37
37
|
|
38
38
|
describe "#discover_webmention_endpoint_from_string" do
|
39
|
-
it "should find rel
|
39
|
+
it "should find rel=\"webmention\" followed by href in header" do
|
40
40
|
Webmention::Client.discover_webmention_endpoint_from_header('rel="webmention"; <http://webmention.io/example/webmention>').must_equal "http://webmention.io/example/webmention"
|
41
41
|
end
|
42
42
|
|
43
|
-
it "should find
|
43
|
+
it "should find rel=webmention followed by href in header" do
|
44
|
+
Webmention::Client.discover_webmention_endpoint_from_header('rel=webmention; <http://webmention.io/example/webmention>').must_equal "http://webmention.io/example/webmention"
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should find href followed by rel=\"webmention\" in header" do
|
44
48
|
Webmention::Client.discover_webmention_endpoint_from_header('<http://webmention.io/example/webmention>; rel="webmention"').must_equal "http://webmention.io/example/webmention"
|
45
49
|
end
|
46
50
|
|
51
|
+
it "should find href followed by rel=webmention in header" do
|
52
|
+
Webmention::Client.discover_webmention_endpoint_from_header('<http://webmention.io/example/webmention>; rel=webmention').must_equal "http://webmention.io/example/webmention"
|
53
|
+
end
|
54
|
+
|
47
55
|
it "should find rel=http://webmention.org followed by href in header" do
|
48
56
|
Webmention::Client.discover_webmention_endpoint_from_header('rel="http://webmention.org"; <http://webmention.io/example/webmention>').must_equal "http://webmention.io/example/webmention"
|
49
57
|
end
|
@@ -83,6 +91,34 @@ describe Webmention::Client do
|
|
83
91
|
it "should find href followed by rel=http://webmention.org/ in html" do
|
84
92
|
Webmention::Client.discover_webmention_endpoint_from_html(SampleData.rel_href_webmention_org_slash).must_equal "http://webmention.io/example/webmention"
|
85
93
|
end
|
94
|
+
|
95
|
+
it "should find rel=webmention followed by relative href with path in header" do
|
96
|
+
Webmention::Client.discover_webmention_endpoint_from_header('</example/webmention>; rel="http://webmention.org"').must_equal "/example/webmention"
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should find rel=webmention followed by relative href with path in html" do
|
100
|
+
Webmention::Client.discover_webmention_endpoint_from_html(SampleData.rel_webmention_relative_with_path).must_equal "/example/webmention"
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should find rel=webmention followed by relative href without path in header" do
|
104
|
+
Webmention::Client.discover_webmention_endpoint_from_header('<webmention.php>; rel="http://webmention.org"').must_equal "webmention.php"
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should find rel=webmention followed by relative href without path in html" do
|
108
|
+
Webmention::Client.discover_webmention_endpoint_from_html(SampleData.rel_webmention_relative_without_path).must_equal "webmention.php"
|
109
|
+
end
|
110
|
+
|
111
|
+
it "should find webmention in a link tag among multiple rel values" do
|
112
|
+
Webmention::Client.discover_webmention_endpoint_from_html(SampleData.link_tag_multiple_rel_values).must_equal "http://webmention.io/example/webmention"
|
113
|
+
end
|
114
|
+
|
115
|
+
it "should find webmention in a link header among multiple rel values" do
|
116
|
+
Webmention::Client.discover_webmention_endpoint_from_header('<http://webmention.io/example/webmention>; rel="webmention foo bar"').must_equal "http://webmention.io/example/webmention"
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should find rel=webmention in a link tag with an empty href" do
|
120
|
+
Webmention::Client.discover_webmention_endpoint_from_html(SampleData.empty_link_tag_no_href).must_equal ""
|
121
|
+
end
|
86
122
|
end
|
87
123
|
|
88
124
|
end
|
@@ -28,4 +28,18 @@ describe Webmention::Client do
|
|
28
28
|
end
|
29
29
|
end
|
30
30
|
end
|
31
|
+
|
32
|
+
describe "#absolute_endpoint" do
|
33
|
+
it "should expand an endpoint url with a path to an absolute url based on the webmention url" do
|
34
|
+
Webmention::Client.absolute_endpoint('/webmention', 'http://webmention.io/example/1').must_equal "http://webmention.io/webmention"
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should expand an endpoint url without a path to an absolute url based on the webmention url" do
|
38
|
+
Webmention::Client.absolute_endpoint('webmention.php', 'http://webmention.io/example/1').must_equal "http://webmention.io/example/webmention.php"
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should take an empty endpoint url and return the webmention url" do
|
42
|
+
Webmention::Client.absolute_endpoint('', 'http://webmention.io/example/1').must_equal "http://webmention.io/example/1"
|
43
|
+
end
|
44
|
+
end
|
31
45
|
end
|
data/webmention.gemspec
CHANGED
@@ -5,7 +5,7 @@ require 'webmention/version'
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = 'webmention'
|
7
7
|
s.version = Webmention::VERSION
|
8
|
-
s.date = '
|
8
|
+
s.date = '2017-06-27'
|
9
9
|
s.homepage = 'https://github.com/indieweb/mention-client-ruby'
|
10
10
|
s.summary = 'A gem for sending webmention (and pingback) notifications'
|
11
11
|
s.authors = [
|
@@ -24,10 +24,10 @@ Gem::Specification.new do |s|
|
|
24
24
|
|
25
25
|
s.add_dependency 'json'
|
26
26
|
s.add_dependency 'nokogiri'
|
27
|
-
s.add_dependency 'httparty', '~> 0.
|
27
|
+
s.add_dependency 'httparty', '~> 0.15.5'
|
28
28
|
s.add_dependency 'link_header', '~> 0.0.8'
|
29
29
|
|
30
|
-
s.add_development_dependency 'bundler'
|
30
|
+
s.add_development_dependency 'bundler'
|
31
31
|
s.add_development_dependency 'rake'
|
32
32
|
s.add_development_dependency 'minitest'
|
33
33
|
s.add_development_dependency 'webmock'
|
metadata
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: webmention
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
5
|
-
prerelease:
|
4
|
+
version: 0.1.6
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Aaron Parecki
|
@@ -10,134 +9,118 @@ authors:
|
|
10
9
|
autorequire:
|
11
10
|
bindir: bin
|
12
11
|
cert_chain: []
|
13
|
-
date:
|
12
|
+
date: 2017-06-27 00:00:00.000000000 Z
|
14
13
|
dependencies:
|
15
14
|
- !ruby/object:Gem::Dependency
|
16
15
|
name: json
|
17
16
|
requirement: !ruby/object:Gem::Requirement
|
18
|
-
none: false
|
19
17
|
requirements:
|
20
|
-
- -
|
18
|
+
- - ">="
|
21
19
|
- !ruby/object:Gem::Version
|
22
20
|
version: '0'
|
23
21
|
type: :runtime
|
24
22
|
prerelease: false
|
25
23
|
version_requirements: !ruby/object:Gem::Requirement
|
26
|
-
none: false
|
27
24
|
requirements:
|
28
|
-
- -
|
25
|
+
- - ">="
|
29
26
|
- !ruby/object:Gem::Version
|
30
27
|
version: '0'
|
31
28
|
- !ruby/object:Gem::Dependency
|
32
29
|
name: nokogiri
|
33
30
|
requirement: !ruby/object:Gem::Requirement
|
34
|
-
none: false
|
35
31
|
requirements:
|
36
|
-
- -
|
32
|
+
- - ">="
|
37
33
|
- !ruby/object:Gem::Version
|
38
34
|
version: '0'
|
39
35
|
type: :runtime
|
40
36
|
prerelease: false
|
41
37
|
version_requirements: !ruby/object:Gem::Requirement
|
42
|
-
none: false
|
43
38
|
requirements:
|
44
|
-
- -
|
39
|
+
- - ">="
|
45
40
|
- !ruby/object:Gem::Version
|
46
41
|
version: '0'
|
47
42
|
- !ruby/object:Gem::Dependency
|
48
43
|
name: httparty
|
49
44
|
requirement: !ruby/object:Gem::Requirement
|
50
|
-
none: false
|
51
45
|
requirements:
|
52
|
-
- - ~>
|
46
|
+
- - "~>"
|
53
47
|
- !ruby/object:Gem::Version
|
54
|
-
version: 0.
|
48
|
+
version: 0.15.5
|
55
49
|
type: :runtime
|
56
50
|
prerelease: false
|
57
51
|
version_requirements: !ruby/object:Gem::Requirement
|
58
|
-
none: false
|
59
52
|
requirements:
|
60
|
-
- - ~>
|
53
|
+
- - "~>"
|
61
54
|
- !ruby/object:Gem::Version
|
62
|
-
version: 0.
|
55
|
+
version: 0.15.5
|
63
56
|
- !ruby/object:Gem::Dependency
|
64
57
|
name: link_header
|
65
58
|
requirement: !ruby/object:Gem::Requirement
|
66
|
-
none: false
|
67
59
|
requirements:
|
68
|
-
- - ~>
|
60
|
+
- - "~>"
|
69
61
|
- !ruby/object:Gem::Version
|
70
62
|
version: 0.0.8
|
71
63
|
type: :runtime
|
72
64
|
prerelease: false
|
73
65
|
version_requirements: !ruby/object:Gem::Requirement
|
74
|
-
none: false
|
75
66
|
requirements:
|
76
|
-
- - ~>
|
67
|
+
- - "~>"
|
77
68
|
- !ruby/object:Gem::Version
|
78
69
|
version: 0.0.8
|
79
70
|
- !ruby/object:Gem::Dependency
|
80
71
|
name: bundler
|
81
72
|
requirement: !ruby/object:Gem::Requirement
|
82
|
-
none: false
|
83
73
|
requirements:
|
84
|
-
- -
|
74
|
+
- - ">="
|
85
75
|
- !ruby/object:Gem::Version
|
86
|
-
version: '
|
76
|
+
version: '0'
|
87
77
|
type: :development
|
88
78
|
prerelease: false
|
89
79
|
version_requirements: !ruby/object:Gem::Requirement
|
90
|
-
none: false
|
91
80
|
requirements:
|
92
|
-
- -
|
81
|
+
- - ">="
|
93
82
|
- !ruby/object:Gem::Version
|
94
|
-
version: '
|
83
|
+
version: '0'
|
95
84
|
- !ruby/object:Gem::Dependency
|
96
85
|
name: rake
|
97
86
|
requirement: !ruby/object:Gem::Requirement
|
98
|
-
none: false
|
99
87
|
requirements:
|
100
|
-
- -
|
88
|
+
- - ">="
|
101
89
|
- !ruby/object:Gem::Version
|
102
90
|
version: '0'
|
103
91
|
type: :development
|
104
92
|
prerelease: false
|
105
93
|
version_requirements: !ruby/object:Gem::Requirement
|
106
|
-
none: false
|
107
94
|
requirements:
|
108
|
-
- -
|
95
|
+
- - ">="
|
109
96
|
- !ruby/object:Gem::Version
|
110
97
|
version: '0'
|
111
98
|
- !ruby/object:Gem::Dependency
|
112
99
|
name: minitest
|
113
100
|
requirement: !ruby/object:Gem::Requirement
|
114
|
-
none: false
|
115
101
|
requirements:
|
116
|
-
- -
|
102
|
+
- - ">="
|
117
103
|
- !ruby/object:Gem::Version
|
118
104
|
version: '0'
|
119
105
|
type: :development
|
120
106
|
prerelease: false
|
121
107
|
version_requirements: !ruby/object:Gem::Requirement
|
122
|
-
none: false
|
123
108
|
requirements:
|
124
|
-
- -
|
109
|
+
- - ">="
|
125
110
|
- !ruby/object:Gem::Version
|
126
111
|
version: '0'
|
127
112
|
- !ruby/object:Gem::Dependency
|
128
113
|
name: webmock
|
129
114
|
requirement: !ruby/object:Gem::Requirement
|
130
|
-
none: false
|
131
115
|
requirements:
|
132
|
-
- -
|
116
|
+
- - ">="
|
133
117
|
- !ruby/object:Gem::Version
|
134
118
|
version: '0'
|
135
119
|
type: :development
|
136
120
|
prerelease: false
|
137
121
|
version_requirements: !ruby/object:Gem::Requirement
|
138
|
-
none: false
|
139
122
|
requirements:
|
140
|
-
- -
|
123
|
+
- - ">="
|
141
124
|
- !ruby/object:Gem::Version
|
142
125
|
version: '0'
|
143
126
|
description:
|
@@ -147,8 +130,8 @@ executables:
|
|
147
130
|
extensions: []
|
148
131
|
extra_rdoc_files: []
|
149
132
|
files:
|
150
|
-
- .gitignore
|
151
|
-
- .travis.yml
|
133
|
+
- ".gitignore"
|
134
|
+
- ".travis.yml"
|
152
135
|
- Gemfile
|
153
136
|
- README.md
|
154
137
|
- Rakefile
|
@@ -167,27 +150,26 @@ files:
|
|
167
150
|
- webmention.gemspec
|
168
151
|
homepage: https://github.com/indieweb/mention-client-ruby
|
169
152
|
licenses: []
|
153
|
+
metadata: {}
|
170
154
|
post_install_message:
|
171
155
|
rdoc_options: []
|
172
156
|
require_paths:
|
173
157
|
- lib
|
174
158
|
required_ruby_version: !ruby/object:Gem::Requirement
|
175
|
-
none: false
|
176
159
|
requirements:
|
177
|
-
- -
|
160
|
+
- - ">="
|
178
161
|
- !ruby/object:Gem::Version
|
179
162
|
version: 1.9.3
|
180
163
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
181
|
-
none: false
|
182
164
|
requirements:
|
183
|
-
- -
|
165
|
+
- - ">="
|
184
166
|
- !ruby/object:Gem::Version
|
185
167
|
version: '0'
|
186
168
|
requirements: []
|
187
169
|
rubyforge_project:
|
188
|
-
rubygems_version:
|
170
|
+
rubygems_version: 2.5.2
|
189
171
|
signing_key:
|
190
|
-
specification_version:
|
172
|
+
specification_version: 4
|
191
173
|
summary: A gem for sending webmention (and pingback) notifications
|
192
174
|
test_files:
|
193
175
|
- test/data/sample_html.rb
|