webmention 0.1.6 → 1.0.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 +5 -5
- data/.editorconfig +10 -0
- data/.gitignore +31 -14
- data/.reek.yml +8 -0
- data/.rubocop +3 -0
- data/.rubocop.yml +30 -0
- data/.ruby-version +1 -0
- data/.simplecov +10 -0
- data/.travis.yml +13 -3
- data/CHANGELOG.md +18 -0
- data/CONTRIBUTING.md +37 -0
- data/LICENSE +13 -0
- data/README.md +77 -45
- data/Rakefile +18 -7
- data/lib/webmention.rb +23 -5
- data/lib/webmention/client.rb +24 -167
- data/lib/webmention/exceptions.rb +15 -0
- data/lib/webmention/http_request.rb +41 -0
- data/lib/webmention/parsers.rb +29 -0
- data/lib/webmention/parsers/html_parser.rb +73 -0
- data/lib/webmention/registerable.rb +11 -0
- data/lib/webmention/version.rb +1 -1
- data/webmention.gemspec +39 -30
- metadata +156 -69
- data/bin/webmention +0 -59
- data/example.rb +0 -20
- data/test/data/sample_html.rb +0 -125
- data/test/lib/webmention/crawl_test.rb +0 -23
- data/test/lib/webmention/discovery_test.rb +0 -124
- data/test/lib/webmention/mention_test.rb +0 -38
- data/test/lib/webmention/url_test.rb +0 -45
- data/test/lib/webmention/version_test.rb +0 -9
- data/test/test_helper.rb +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b1bde7851ec0309258c157929d3e7e53b640f253d97b7cd2b1ac68785afeb75e
|
4
|
+
data.tar.gz: b6af4fdee3e16035cbdc4479ecffb48d2685a29a4193a43c2145a348a9b95f4c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a2c9c9de6ac875786c3795849490c7ceab6e1323510f7bd905d10c971b171b2898a22ad3fbf21b9d08afc65fc859baa6bbcad676d393d6be06181006f32f545e
|
7
|
+
data.tar.gz: 70ec1f5ce90d1ac832ceceab666abd0a430fb73ee0a3728d08c826608526ff7e52bdc37351190a2bf38c7093e3641ec5be45d89de9d423c837b341153d68ae0c
|
data/.editorconfig
ADDED
data/.gitignore
CHANGED
@@ -1,17 +1,34 @@
|
|
1
1
|
*.gem
|
2
2
|
*.rbc
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/spec/examples.txt
|
9
|
+
/test/tmp/
|
10
|
+
/test/version_tmp/
|
11
|
+
/tmp/
|
12
|
+
|
13
|
+
# Used by dotenv library to load environment variables.
|
14
|
+
# .env
|
15
|
+
|
16
|
+
# Documentation cache and generated files:
|
17
|
+
/.yardoc/
|
18
|
+
/_yardoc/
|
19
|
+
/doc/
|
20
|
+
/rdoc/
|
21
|
+
|
22
|
+
# Environment normalization:
|
23
|
+
/.bundle/
|
24
|
+
/vendor/bundle
|
25
|
+
/lib/bundler/man/
|
26
|
+
|
27
|
+
# for a library or gem, you might want to ignore these files since the code is
|
28
|
+
# intended to run in multiple environments; otherwise, check them in:
|
6
29
|
Gemfile.lock
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
pkg
|
13
|
-
rdoc
|
14
|
-
spec/reports
|
15
|
-
test/tmp
|
16
|
-
test/version_tmp
|
17
|
-
tmp
|
30
|
+
# .ruby-version
|
31
|
+
# .ruby-gemset
|
32
|
+
|
33
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
34
|
+
.rvmrc
|
data/.reek.yml
ADDED
data/.rubocop
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require:
|
2
|
+
- rubocop-performance
|
3
|
+
|
4
|
+
Layout/AlignHash:
|
5
|
+
EnforcedColonStyle: table
|
6
|
+
EnforcedHashRocketStyle: table
|
7
|
+
|
8
|
+
Metrics/BlockLength:
|
9
|
+
Exclude:
|
10
|
+
- webmention.gemspec
|
11
|
+
- test/**/*
|
12
|
+
|
13
|
+
Metrics/LineLength:
|
14
|
+
Enabled: false
|
15
|
+
|
16
|
+
Naming/RescuedExceptionsVariableName:
|
17
|
+
PreferredName: exception
|
18
|
+
|
19
|
+
Style/Documentation:
|
20
|
+
Enabled: false
|
21
|
+
|
22
|
+
Style/FrozenStringLiteralComment:
|
23
|
+
Enabled: false
|
24
|
+
|
25
|
+
Style/SingleLineMethods:
|
26
|
+
Exclude:
|
27
|
+
- test/**/*
|
28
|
+
|
29
|
+
Style/SymbolArray:
|
30
|
+
Enabled: false
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.4.6
|
data/.simplecov
ADDED
data/.travis.yml
CHANGED
@@ -1,7 +1,17 @@
|
|
1
1
|
language: ruby
|
2
|
+
cache: bundler
|
2
3
|
rvm:
|
3
|
-
- 2.4.
|
4
|
-
- 2.
|
5
|
-
- 2.
|
4
|
+
- 2.4.6
|
5
|
+
- 2.5.5
|
6
|
+
- 2.6.3
|
7
|
+
before_install:
|
8
|
+
- gem update --system
|
9
|
+
- gem update bundler
|
10
|
+
before_script:
|
11
|
+
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
12
|
+
- chmod +x ./cc-test-reporter
|
13
|
+
- ./cc-test-reporter before-build
|
14
|
+
after_script:
|
15
|
+
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
|
6
16
|
notifications:
|
7
17
|
email: false
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
## 1.0.0 / 2019-07-03
|
4
|
+
|
5
|
+
### Breaking Changes
|
6
|
+
|
7
|
+
For an instance of the `Webmention::Client` class:
|
8
|
+
|
9
|
+
- The `send_mention` no longer accepts the `full_response` argument. When a Webmention endpoint is found, the method returns an `HTTP::Response` object. Otherwise, the method returns `nil`.
|
10
|
+
- The `send_mentions` method is renamed to `send_all_mentions` and now returns a Hash whose keys are URLs and values are `HTTP::Response` objects (or `nil` when no Webmention endpoint is found at the given URL).
|
11
|
+
- The `mentioned_url` method returns an Array of URLs mentioned within given URL's first `.h-entry` (if one exists). Otherwise, it returns a list of all URLs within the given URL's `<body>`.
|
12
|
+
|
13
|
+
### Development Changes
|
14
|
+
|
15
|
+
- Removes [Bundler](https://bundler.io) as a dependency (5e1662d)
|
16
|
+
- Updates project Ruby to 2.4.6 (the latest 2.4.x release at this time) (b53a400)
|
17
|
+
- Add the [Reek](https://github.com/troessner/reek) code smell detector (eb314dc)
|
18
|
+
- Adds binstubs for more easily running common development tools (8899a22)
|
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# Contributing to webmention-client-ruby
|
2
|
+
|
3
|
+
There are a couple ways you can help improve webmention-client-ruby:
|
4
|
+
|
5
|
+
1. Fix an existing [issue][issues] and submit a [pull request][pulls].
|
6
|
+
1. Review open [pull requests][pulls].
|
7
|
+
1. Report a new [issue][issues]. _Only do this after you've made sure the behavior or problem you're observing isn't already documented in an open issue._
|
8
|
+
|
9
|
+
## Getting Started
|
10
|
+
|
11
|
+
webmention-client-ruby is developed using Ruby 2.4.6 and is additionally tested against Ruby 2.5.5 and 2.6.3 using [Travis CI](https://travis-ci.org/indieweb/webmention-client-ruby).
|
12
|
+
|
13
|
+
Before making changes to webmention-client-ruby, you'll want to install Ruby 2.4.6. 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.6 using your method of choice, install the project's gems by running:
|
14
|
+
|
15
|
+
```sh
|
16
|
+
bundle install
|
17
|
+
```
|
18
|
+
|
19
|
+
## Making Changes
|
20
|
+
|
21
|
+
1. Fork and clone the project's repo.
|
22
|
+
1. Install development dependencies as outlined above.
|
23
|
+
1. Create a feature branch for the code changes you're looking to make: `git checkout -b my-new-feature`.
|
24
|
+
1. _Write some code!_
|
25
|
+
1. If your changes would benefit from testing, add the necessary tests and verify everything passes by running `bundle exec rspec`.
|
26
|
+
1. Commit your changes: `git commit -am 'Add some new feature or fix some issue'`. _(See [this excellent article](https://chris.beams.io/posts/git-commit/) for tips on writing useful Git commit messages.)_
|
27
|
+
1. Push the branch to your fork: `git push -u origin my-new-feature`.
|
28
|
+
1. Create a new [pull request][pulls] and we'll review your changes.
|
29
|
+
|
30
|
+
## Code Style
|
31
|
+
|
32
|
+
Code formatting conventions are defined in the `.editorconfig` file which uses the [EditorConfig](http://editorconfig.org) syntax. There are [plugins for a variety of editors](http://editorconfig.org/#download) that utilize the settings in the `.editorconfig` file. We recommended you install the EditorConfig plugin for your editor of choice.
|
33
|
+
|
34
|
+
Your bug fix or feature addition won't be rejected if it runs afoul of any (or all) of these guidelines, but following the guidelines will definitely make everyone's lives a little easier.
|
35
|
+
|
36
|
+
[issues]: https://github.com/indieweb/webmention-client-ruby/issues
|
37
|
+
[pulls]: https://github.com/indieweb/webmention-client-ruby/pulls
|
data/LICENSE
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Copyright 2013 by Aaron Parecki
|
2
|
+
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
you may not use this file except in compliance with the License.
|
5
|
+
You may obtain a copy of the License at
|
6
|
+
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
See the License for the specific language governing permissions and
|
13
|
+
limitations under the License.
|
data/README.md
CHANGED
@@ -1,78 +1,110 @@
|
|
1
|
-
|
2
|
-
=================
|
1
|
+
# webmention-client-ruby
|
3
2
|
|
4
|
-
A Ruby gem for sending [
|
3
|
+
**A Ruby gem for sending [Webmention](https://indieweb.org/Webmention) notifications.**
|
5
4
|
|
6
|
-
[](https://rubygems.org/gems/webmention)
|
6
|
+
[](https://rubygems.org/gems/webmention)
|
7
|
+
[](https://travis-ci.org/indieweb/webmention-client-ruby)
|
8
|
+
[](https://codeclimate.com/github/indieweb/webmention-client-ruby)
|
9
|
+
[](https://codeclimate.com/github/indieweb/webmention-client-ruby/code)
|
7
10
|
|
8
|
-
|
9
|
-
------------
|
11
|
+
## Key Features
|
10
12
|
|
11
|
-
|
13
|
+
- Crawls a given URL for mentioned URLs.
|
14
|
+
- Performs [endpoint discovery](https://www.w3.org/TR/webmention/#sender-discovers-receiver-webmention-endpoint) on mentioned URLs.
|
15
|
+
- Sends webmentions to mentioned URLs.
|
12
16
|
|
17
|
+
## Getting Started
|
13
18
|
|
14
|
-
|
15
|
-
-----
|
19
|
+
Before installing and using webmention-client-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).
|
16
20
|
|
17
|
-
|
21
|
+
webmention-client-ruby is developed using Ruby 2.4.6 and is additionally tested against Ruby 2.5.5 and 2.6.3 using [Travis CI](https://travis-ci.org/indieweb/webmention-client-ruby).
|
22
|
+
|
23
|
+
## Installation
|
24
|
+
|
25
|
+
If you're using [Bundler](https://bundler.io) to manage gem dependencies, add webmention-client-ruby to your project's Gemfile:
|
18
26
|
|
19
27
|
```ruby
|
20
|
-
|
21
|
-
sent = client.send_mentions
|
28
|
+
source 'https://rubygems.org'
|
22
29
|
|
23
|
-
|
30
|
+
gem 'webmention'
|
24
31
|
```
|
25
32
|
|
26
|
-
|
27
|
-
mentions to each. This is accomplished by doing a HEAD request and looking at the headers
|
28
|
-
for supported servers, if none are found, then it searches the body of the page.
|
33
|
+
…and then run:
|
29
34
|
|
30
|
-
|
35
|
+
```sh
|
36
|
+
bundle install
|
37
|
+
```
|
31
38
|
|
32
|
-
|
39
|
+
## Usage
|
40
|
+
|
41
|
+
With webmention-client-ruby added to your project's `Gemfile` and installed, you may send a webmention from a source URL to a target URL:
|
33
42
|
|
34
43
|
```ruby
|
35
|
-
|
44
|
+
require 'webmention'
|
36
45
|
|
37
|
-
source =
|
38
|
-
target =
|
46
|
+
source = 'https://source.example.com/post/100' # A post on your website
|
47
|
+
target = 'https://target.example.com/post/100' # A post on someone else's website
|
39
48
|
|
40
|
-
|
41
|
-
Webmention::Client.send_mention endpoint, source, target
|
42
|
-
end
|
49
|
+
Webmention.send_mention(source, target) # => #<HTTP::Response/1.1 200 OK {…}>
|
43
50
|
```
|
44
51
|
|
45
|
-
|
46
|
-
|
52
|
+
If no Webmention endpoint is found for a given source URL, the `send_mention` method will return `nil`.
|
53
|
+
|
54
|
+
**Note:** `HTTP::Response` objects may return a variety of status codes that will vary depending on the endpoint's capabilities and the success or failure of the request. See [the Webmention spec](https://www.w3.org/TR/webmention/) for more on status codes on their implications.
|
47
55
|
|
48
|
-
|
56
|
+
### Sending multiple webmentions
|
49
57
|
|
50
|
-
|
51
|
-
|
58
|
+
To send webmentions to all URLs mentioned within a source URL's [h-entry](http://microformats.org/wiki/h-entry):
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
require 'webmention'
|
62
|
+
|
63
|
+
client = Webmention.client('https://source.example.com/post/100')
|
64
|
+
|
65
|
+
client.mentioned_urls # => Array
|
66
|
+
client.send_all_mentions # => Hash
|
52
67
|
```
|
53
68
|
|
54
|
-
This will
|
69
|
+
This example will crawl `https://source.example.com/post/100`, parse its markup for the first h-entry, perform endpoint discovery on mentioned URLs, and attempt to send webmentions to those URLs.
|
70
|
+
|
71
|
+
**Note:** If no h-entry is found at the provided source URL, the `send_all_mentions` method will search the source URL's `<body>` for mentioned URLs.
|
72
|
+
|
73
|
+
The `send_all_mentions` method returns a hash of mentioned URLs and the associated HTTP response (an [`HTTP::Response` object](https://github.com/httprb/http/wiki/Response-Handling)):
|
74
|
+
|
75
|
+
```ruby
|
76
|
+
{
|
77
|
+
'https://target.example.com/post/100' => #<HTTP::Response/1.1 200 OK {…}>,
|
78
|
+
'https://target.example.com/post/101' => #<HTTP::Response/1.1 200 OK {…}>
|
79
|
+
}
|
80
|
+
```
|
81
|
+
|
82
|
+
### Exception Handling
|
83
|
+
|
84
|
+
There are several exceptions that may be raised by webmention-client-ruby's underlying dependencies. These errors are raised as subclasses of `WebmentionClientError` (which itself is a subclass of `StandardError`).
|
85
|
+
|
86
|
+
From [sporkmonger/addressable](https://github.com/sporkmonger/addressable):
|
87
|
+
|
88
|
+
- `Webmention::Client::InvalidURIError`
|
89
|
+
|
90
|
+
From [httprb/http](https://github.com/httprb/http):
|
55
91
|
|
92
|
+
- `Webmention::Client::ConnectionError`
|
93
|
+
- `Webmention::Client::TimeoutError`
|
94
|
+
- `Webmention::Client::TooManyRedirectsError`
|
56
95
|
|
57
|
-
Webmention
|
58
|
-
----------
|
96
|
+
webmention-client-ruby will also raise a `Webmention::Client::UnsupportedMimeTypeError` when encountering an `HTTP::Response` instance with an unsupported MIME type.
|
59
97
|
|
60
|
-
|
98
|
+
## Contributing
|
61
99
|
|
100
|
+
Interested in helping improve webmention-client-ruby? Awesome! Your help is greatly appreciated. See [CONTRIBUTING.md](https://github.com/indieweb/webmention-client-ruby/blob/master/CONTRIBUTING.md) for details.
|
62
101
|
|
63
|
-
|
64
|
-
-------
|
102
|
+
## Acknowledgments
|
65
103
|
|
66
|
-
|
104
|
+
webmention-client-ruby is written and maintained by [Aaron Parecki](https://aaronparecki.com) ([@aaronpk](https://github.com/aaronpk)) and [Nat Welch](https://natwelch.com) ([@icco](https://github.com/icco)) with help from [these additional contributors](https://github.com/indieweb/webmention-client-ruby/graphs/contributors).
|
67
105
|
|
68
|
-
|
69
|
-
you may not use this file except in compliance with the License.
|
70
|
-
You may obtain a copy of the License at
|
106
|
+
To learn more about Webmention, see [indieweb.org/Webmention](https://indieweb.org/Webmention) and [webmention.net](https://webmention.net).
|
71
107
|
|
72
|
-
|
108
|
+
## License
|
73
109
|
|
74
|
-
|
75
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
76
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
77
|
-
See the License for the specific language governing permissions and
|
78
|
-
limitations under the License.
|
110
|
+
webmention-client-ruby 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/master/LICENSE) for more details.
|
data/Rakefile
CHANGED
@@ -1,10 +1,21 @@
|
|
1
1
|
require 'bundler/gem_tasks'
|
2
|
+
|
2
3
|
require 'rake/testtask'
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
t.
|
4
|
+
require 'reek/rake/task'
|
5
|
+
require 'rubocop/rake_task'
|
6
|
+
|
7
|
+
Rake::TestTask.new(:test) do |t|
|
8
|
+
t.libs << 'test'
|
9
|
+
t.libs << 'lib'
|
10
|
+
t.test_files = FileList['test/**/*_test.rb']
|
8
11
|
end
|
9
|
-
|
10
|
-
|
12
|
+
|
13
|
+
Reek::Rake::Task.new do |task|
|
14
|
+
task.fail_on_error = false
|
15
|
+
end
|
16
|
+
|
17
|
+
RuboCop::RakeTask.new do |task|
|
18
|
+
task.fail_on_error = false
|
19
|
+
end
|
20
|
+
|
21
|
+
task default: [:rubocop, :reek, :test]
|
data/lib/webmention.rb
CHANGED
@@ -1,9 +1,27 @@
|
|
1
|
-
require '
|
2
|
-
require '
|
1
|
+
require 'absolutely'
|
2
|
+
require 'addressable/uri'
|
3
|
+
require 'http'
|
4
|
+
require 'indieweb/endpoints'
|
3
5
|
require 'nokogiri'
|
4
|
-
require 'open-uri'
|
5
|
-
require 'set'
|
6
|
-
require 'uri'
|
7
6
|
|
8
7
|
require 'webmention/version'
|
8
|
+
require 'webmention/exceptions'
|
9
|
+
|
9
10
|
require 'webmention/client'
|
11
|
+
require 'webmention/http_request'
|
12
|
+
require 'webmention/registerable'
|
13
|
+
|
14
|
+
require 'webmention/parsers'
|
15
|
+
require 'webmention/parsers/html_parser'
|
16
|
+
|
17
|
+
module Webmention
|
18
|
+
class << self
|
19
|
+
def client(source)
|
20
|
+
Client.new(source)
|
21
|
+
end
|
22
|
+
|
23
|
+
def send_mention(source, target)
|
24
|
+
client(source).send_mention(target)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|