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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: fb054d8a144253225b03c07b8cb1b70e78b01c5d
4
- data.tar.gz: a73bd416adcbcd7c3aac45eb3fc053cb2a2296f8
2
+ SHA256:
3
+ metadata.gz: b1bde7851ec0309258c157929d3e7e53b640f253d97b7cd2b1ac68785afeb75e
4
+ data.tar.gz: b6af4fdee3e16035cbdc4479ecffb48d2685a29a4193a43c2145a348a9b95f4c
5
5
  SHA512:
6
- metadata.gz: 792d42a1dea5a5be92f1550753688699ddd4da47a166ed52fa09463cae5ce2c5264fc924cc10bb585f3f5eb84a2f7283805db44f11f82b5f6e3833e51da63bba
7
- data.tar.gz: f8dd7faaa37ea1de848ccdb6b40dc737707a18c2f93a412d6ea48c2be8ae34058ca887506b3c84f42b93aed89835940003d944f6409e88bc842f6ce321aa2f62
6
+ metadata.gz: a2c9c9de6ac875786c3795849490c7ceab6e1323510f7bd905d10c971b171b2898a22ad3fbf21b9d08afc65fc859baa6bbcad676d393d6be06181006f32f545e
7
+ data.tar.gz: 70ec1f5ce90d1ac832ceceab666abd0a430fb73ee0a3728d08c826608526ff7e52bdc37351190a2bf38c7093e3641ec5be45d89de9d423c837b341153d68ae0c
@@ -0,0 +1,10 @@
1
+ # EditorConfig is awesome: https://EditorConfig.org
2
+ root = true
3
+
4
+ [*]
5
+ charset = utf-8
6
+ end_of_line = lf
7
+ insert_final_newline = true
8
+ indent_size = 2
9
+ indent_style = space
10
+ trim_trailing_whitespace = true
data/.gitignore CHANGED
@@ -1,17 +1,34 @@
1
1
  *.gem
2
2
  *.rbc
3
- .bundle
4
- .config
5
- .yardoc
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
- InstalledFiles
8
- _yardoc
9
- coverage
10
- doc/
11
- lib/bundler/man
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
@@ -0,0 +1,8 @@
1
+ detectors:
2
+ DuplicateMethodCall:
3
+ max_calls: 3
4
+ IrresponsibleModule:
5
+ enabled: false
6
+
7
+ exclude_paths:
8
+ - vendor/
@@ -0,0 +1,3 @@
1
+ --display-style-guide
2
+ --extra-details
3
+ --parallel
@@ -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
@@ -0,0 +1 @@
1
+ 2.4.6
@@ -0,0 +1,10 @@
1
+ require 'simplecov-console'
2
+
3
+ SimpleCov.start do
4
+ add_filter '/test/'
5
+
6
+ formatter SimpleCov::Formatter::MultiFormatter.new([
7
+ SimpleCov::Formatter::Console,
8
+ SimpleCov::Formatter::HTMLFormatter
9
+ ])
10
+ end
@@ -1,7 +1,17 @@
1
1
  language: ruby
2
+ cache: bundler
2
3
  rvm:
3
- - 2.4.1
4
- - 2.3.4
5
- - 2.2.7
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
@@ -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)
@@ -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
- Webmention Client
2
- =================
1
+ # webmention-client-ruby
3
2
 
4
- A Ruby gem for sending [webmention](http://indiewebcamp.com/webmention) (and [pingback](http://indiewebcamp.com/pingback)) notifications.
3
+ **A Ruby gem for sending [Webmention](https://indieweb.org/Webmention) notifications.**
5
4
 
6
- [![Build Status](https://travis-ci.org/indieweb/mention-client-ruby.png?branch=master)](https://travis-ci.org/indieweb/mention-client-ruby)
5
+ [![Gem](https://img.shields.io/gem/v/webmention.svg?style=for-the-badge)](https://rubygems.org/gems/webmention)
6
+ [![Downloads](https://img.shields.io/gem/dt/webmention.svg?style=for-the-badge)](https://rubygems.org/gems/webmention)
7
+ [![Build](https://img.shields.io/travis/indieweb/webmention-client-ruby/master.svg?style=for-the-badge)](https://travis-ci.org/indieweb/webmention-client-ruby)
8
+ [![Maintainability](https://img.shields.io/codeclimate/maintainability/indieweb/webmention-client-ruby.svg?style=for-the-badge)](https://codeclimate.com/github/indieweb/webmention-client-ruby)
9
+ [![Coverage](https://img.shields.io/codeclimate/c/indieweb/webmention-client-ruby.svg?style=for-the-badge)](https://codeclimate.com/github/indieweb/webmention-client-ruby/code)
7
10
 
8
- Installation
9
- ------------
11
+ ## Key Features
10
12
 
11
- gem install webmention
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
- Usage
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
- ### Send webmentions to all links on a page
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
- client = Webmention::Client.new url
21
- sent = client.send_mentions
28
+ source 'https://rubygems.org'
22
29
 
23
- puts "Sent #{sent} mentions"
30
+ gem 'webmention'
24
31
  ```
25
32
 
26
- This will find all absolute links on the page at `url` and will attempt to send
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
- After finding either webmention or pingback endpoints, the request is sent to each.
35
+ ```sh
36
+ bundle install
37
+ ```
31
38
 
32
- ### Send webmention to a specific URL
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
- # Discover the webmention endpoint of a target and send the mention
44
+ require 'webmention'
36
45
 
37
- source = "http://source.example.com/post/100" # For example, your page
38
- target = "http://indiewebcamp.com/" # The page you linked to
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
- if endpoint = Webmention::Client.supports_webmention?(target)
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
- Command Line Utility
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
- For testing or for sending webmentions manually, you can use the command-line utility provided.
56
+ ### Sending multiple webmentions
49
57
 
50
- ```bash
51
- $ webmention http://source.example.com/post/100
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 look for an [h-entry](http://indiewebcamp.com/h-entry) on the given URL and attempt to send webmentions to each URL in the entry.
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
- To learn more about Webmention, see [webmention.org](http://webmention.org) and [indiewebcamp.com/webmention](http://indiewebcamp.com/webmention).
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
- License
64
- -------
102
+ ## Acknowledgments
65
103
 
66
- Copyright 2013 by Aaron Parecki
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
- Licensed under the Apache License, Version 2.0 (the "License");
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
- http://www.apache.org/licenses/LICENSE-2.0
108
+ ## License
73
109
 
74
- Unless required by applicable law or agreed to in writing, software
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
- Rake::TestTask.new do |t|
5
- t.libs << 'lib/webmention'
6
- t.test_files = FileList['test/lib/webmention/*_test.rb']
7
- t.verbose = true
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
- task :default => :test
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]
@@ -1,9 +1,27 @@
1
- require 'json'
2
- require 'httparty'
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