webmention-verification 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2132738467e12670eb219ec7c13dd036ecf6f66c1ac9d140dbc2ae5c923bab8e
4
- data.tar.gz: 6c7ae3453d6d6f49d636232da018296b79653742e006fae38759d25ab97ff7d8
3
+ metadata.gz: 66b22219ff7225b01af23a17fea1b9e1eaa7a0030f277aaab6eae432431d2985
4
+ data.tar.gz: 9a07439c13437f0abe28e6a39476c62f8e4404626e16562a75e7b072e712b988
5
5
  SHA512:
6
- metadata.gz: 1c179c019d4ef0f934c80971f8c025389cab04f3e4bd1f53989e596e82b426049ed02e63f7a98cd643c55be76ba31d8c29e3170f26783c308048c27332a07429
7
- data.tar.gz: bd29c4d92f5906acbca29055c1aa68f4e122dc7766046acbe31b457932baf2aa8e4d8a47cf6dd58207ed7d508224e42f464c3ef2da541be104a113aa0dcc1e29
6
+ metadata.gz: 93120d7e665aca4d13616f94edbee5f7953edb8a0abb7e4a3f0c900c07da5597cf2f89da39b001132bf6daf17dbee7f70342a669d29390a0dc94b64c22db7abd
7
+ data.tar.gz: e741360306cbdbace9ab13d6bc17d5b2437b031a0b453b142024707b656aee7807d60122d7d3ff89ce3be2a562b691106e424de95530d42d26d0dc141009674e
data/.rubocop.yml CHANGED
@@ -4,6 +4,7 @@ require:
4
4
 
5
5
  Layout/AlignHash:
6
6
  EnforcedColonStyle: table
7
+ EnforcedHashRocketStyle: table
7
8
 
8
9
  Metrics/BlockLength:
9
10
  Exclude:
data/.travis.yml CHANGED
@@ -2,7 +2,7 @@ language: ruby
2
2
  rvm:
3
3
  - 2.4.6
4
4
  - 2.5.5
5
- - 2.6.2
5
+ - 2.6.3
6
6
  cache:
7
7
  - bundler
8
8
  before_install:
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.1.0 / 2019-05-01
4
+
5
+ - Add `Webmention::Verification.client` method.
6
+ - Rename base `Error` class to `WebmentionVerificationError` ([0eb3a9a](https://github.com/jgarber623/webmention-verification-ruby/commit/0eb3a9a)).
7
+ - Add `HttpRequest` class ([c7602c9](https://github.com/jgarber623/webmention-verification-ruby/commit/c7602c9)).
8
+
3
9
  ## 1.0.0 / 2019-04-25
4
10
 
5
11
  - Use pre-release HTTP gem (see @httprb/http#489) ([bdcfdad](https://github.com/jgarber623/webmention-verification-ruby/commit/bdcfdad)).
data/CONTRIBUTING.md CHANGED
@@ -8,7 +8,7 @@ There are a couple ways you can help improve webmention-verification-ruby:
8
8
 
9
9
  ## Getting Started
10
10
 
11
- webmention-verification-ruby is developed using Ruby 2.4.6 and is additionally tested against Ruby 2.5.5 and 2.6.2 using [Travis CI](https://travis-ci.com/jgarber623/webmention-verification-ruby).
11
+ webmention-verification-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.com/jgarber623/webmention-verification-ruby).
12
12
 
13
13
  Before making changes to webmention-verification-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
14
 
data/README.md CHANGED
@@ -18,7 +18,7 @@
18
18
 
19
19
  Before installing and using webmention-verification-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
- webmention-verification-ruby is developed using Ruby 2.4.6 and is additionally tested against Ruby 2.5.5 and 2.6.2 using [Travis CI](https://travis-ci.com/jgarber623/webmention-verification-ruby).
21
+ webmention-verification-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.com/jgarber623/webmention-verification-ruby).
22
22
 
23
23
  ## Installation
24
24
 
@@ -50,14 +50,14 @@ target = 'https://target.example.com/post/100'
50
50
 
51
51
  verified = Webmention::Verification.verified?(source, target)
52
52
 
53
- puts verified # returns Boolean
53
+ puts verified # => Boolean true or false
54
54
  ```
55
55
 
56
56
  This example assumes that you've received a webmention from `https://source.example.com/post/100` (the "source") to your URL, `https://target.example.com/post/100` (the "target"). The above code will return `true` if the source URL links to your target URL and `false` if it doesn't.
57
57
 
58
58
  ### Advanced Usage
59
59
 
60
- Should the need arise, you may work directly with the `Webmention::Verification::Client` class:
60
+ Should the need arise, you may work with the `Webmention::Verification::Client` class:
61
61
 
62
62
  ```ruby
63
63
  require 'webmention/verification'
@@ -65,17 +65,17 @@ require 'webmention/verification'
65
65
  source = 'https://source.example.com/post/100'
66
66
  target = 'https://target.example.com/post/100'
67
67
 
68
- client = Webmention::Verification::Client.new(source, target)
68
+ client = Webmention::Verification.client(source, target)
69
69
 
70
- puts client.source # returns String: 'https://source.example.com/post/100'
71
- puts client.target # returns String: 'https://target.example.com/post/100'
70
+ puts client.source # => 'https://source.example.com/post/100'
71
+ puts client.target # => 'https://target.example.com/post/100'
72
72
 
73
- puts client.source_uri # returns Addressable::URI
74
- puts client.target_uri # returns Addressable::URI
73
+ puts client.source_uri # => #<Addressable::URI>
74
+ puts client.target_uri # => #<Addressable::URI>
75
75
 
76
- puts client.response # returns HTTP::Response
76
+ puts client.response # => #<HTTP::Response>
77
77
 
78
- puts client.verified? # returns Boolean
78
+ puts client.verified? # => Boolean true or false
79
79
  ```
80
80
 
81
81
  **By default, webmention-verification-ruby will strictly match URLs.** You may disable strict matching which allows webmention-verification-ruby to match both `http://` and `https://` URLs. This is useful for matching webmentions your website may have received before it was available exclusively via HTTPS.
@@ -88,9 +88,9 @@ require 'webmention/verification'
88
88
  source = 'https://source.example.com/post/100'
89
89
  target = 'https://target.example.com/post/100'
90
90
 
91
- client = Webmention::Verification::Client.new(source, target, strict: false)
91
+ client = Webmention::Verification.client(source, target, strict: false)
92
92
 
93
- puts client.verified? # returns Boolean
93
+ puts client.verified? # => Boolean true or false
94
94
  ```
95
95
 
96
96
  The above example will match either `https://source.example.com/post/100` _or_ `http://source.example.com/post/100` in the target URL.
@@ -131,15 +131,15 @@ target = 'https://target.example.com/post/100'
131
131
 
132
132
  verifier = Webmention::Verification::Verifiers::HtmlVerifier.new(response, target)
133
133
 
134
- verifier.verified? # returns Boolean
135
- verifier.results # returns Array
134
+ verifier.verified? # => Boolean true or false
135
+ verifier.results # => Array
136
136
  ```
137
137
 
138
138
  In the example above, `verifier.results` will return an array of HTML elements that link to the provided target URL. An empty array will be returned if no elements linking to the target URL are found in the source URL.
139
139
 
140
140
  ### Exception Handling
141
141
 
142
- There are several exceptions that may be raised by webmention-verification-ruby's underlying dependencies. These errors are raised as subclasses of `Webmention::Verification::Error` (which itself is a subclass of `StandardError`).
142
+ There are several exceptions that may be raised by webmention-verification-ruby's underlying dependencies. These errors are raised as subclasses of `WebmentionVerificationError` (which itself is a subclass of `StandardError`).
143
143
 
144
144
  From [sporkmonger/addressable](https://github.com/sporkmonger/addressable):
145
145
 
data/Rakefile CHANGED
@@ -4,8 +4,14 @@ require 'reek/rake/task'
4
4
  require 'rspec/core/rake_task'
5
5
  require 'rubocop/rake_task'
6
6
 
7
- Reek::Rake::Task.new
7
+ Reek::Rake::Task.new do |task|
8
+ task.fail_on_error = false
9
+ end
10
+
8
11
  RSpec::Core::RakeTask.new
9
- RuboCop::RakeTask.new
12
+
13
+ RuboCop::RakeTask.new do |task|
14
+ task.fail_on_error = false
15
+ end
10
16
 
11
17
  task default: [:rubocop, :reek, :spec]
@@ -1,12 +1,14 @@
1
+ require 'json'
2
+
1
3
  require 'addressable/uri'
2
4
  require 'http'
3
- require 'json'
4
5
  require 'nokogiri'
5
6
 
6
7
  require 'webmention/verification/version'
7
8
  require 'webmention/verification/exceptions'
8
9
 
9
10
  require 'webmention/verification/client'
11
+ require 'webmention/verification/http_request'
10
12
  require 'webmention/verification/registerable'
11
13
 
12
14
  require 'webmention/verification/verifiers'
@@ -16,8 +18,14 @@ require 'webmention/verification/verifiers/plaintext_verifier'
16
18
 
17
19
  module Webmention
18
20
  module Verification
19
- def self.verified?(source, target)
20
- Client.new(source, target).verified?
21
+ class << self
22
+ def client(*args)
23
+ Client.new(*args)
24
+ end
25
+
26
+ def verified?(*args)
27
+ client(*args).verified?
28
+ end
21
29
  end
22
30
  end
23
31
  end
@@ -1,11 +1,6 @@
1
1
  module Webmention
2
2
  module Verification
3
3
  class Client
4
- HTTP_HEADERS_OPTS = {
5
- accept: '*/*',
6
- user_agent: 'Webmention Verification Client (https://rubygems.org/gems/webmention-verification)'
7
- }.freeze
8
-
9
4
  attr_reader :source, :target
10
5
 
11
6
  def initialize(source, target, **options)
@@ -21,11 +16,7 @@ module Webmention
21
16
  end
22
17
 
23
18
  def response
24
- @response ||= HTTP.follow.headers(HTTP_HEADERS_OPTS).timeout(connect: 10, read: 10).get(source_uri)
25
- rescue HTTP::ConnectionError,
26
- HTTP::TimeoutError,
27
- HTTP::Redirector::TooManyRedirectsError => exception
28
- raise Webmention::Verification.const_get(exception.class.name.split('::').last), exception
19
+ @response ||= HttpRequest.get(source_uri)
29
20
  end
30
21
 
31
22
  def source_uri
@@ -1,17 +1,17 @@
1
1
  module Webmention
2
2
  module Verification
3
- class Error < StandardError; end
3
+ class WebmentionVerificationError < StandardError; end
4
4
 
5
- class ArgumentError < Error; end
5
+ class ArgumentError < WebmentionVerificationError; end
6
6
 
7
- class ConnectionError < Error; end
7
+ class ConnectionError < WebmentionVerificationError; end
8
8
 
9
- class InvalidURIError < Error; end
9
+ class InvalidURIError < WebmentionVerificationError; end
10
10
 
11
- class TimeoutError < Error; end
11
+ class TimeoutError < WebmentionVerificationError; end
12
12
 
13
- class TooManyRedirectsError < Error; end
13
+ class TooManyRedirectsError < WebmentionVerificationError; end
14
14
 
15
- class UnsupportedMimeTypeError < Error; end
15
+ class UnsupportedMimeTypeError < WebmentionVerificationError; end
16
16
  end
17
17
  end
@@ -0,0 +1,18 @@
1
+ module Webmention
2
+ module Verification
3
+ class HttpRequest
4
+ HTTP_HEADERS_OPTS = {
5
+ accept: '*/*',
6
+ user_agent: 'Webmention Verification Client (https://rubygems.org/gems/webmention-verification)'
7
+ }.freeze
8
+
9
+ def self.get(uri)
10
+ HTTP.follow.headers(HTTP_HEADERS_OPTS).timeout(connect: 10, read: 10).get(uri)
11
+ rescue HTTP::ConnectionError,
12
+ HTTP::TimeoutError,
13
+ HTTP::Redirector::TooManyRedirectsError => exception
14
+ raise Webmention::Verification.const_get(exception.class.name.split('::').last), exception
15
+ end
16
+ end
17
+ end
18
+ end
@@ -1,5 +1,5 @@
1
1
  module Webmention
2
2
  module Verification
3
- VERSION = '1.0.0'.freeze
3
+ VERSION = '1.1.0'.freeze
4
4
  end
5
5
  end
@@ -3,6 +3,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
 
4
4
  require 'webmention/verification/version'
5
5
 
6
+ # rubocop:disable Metrics/BlockLength
6
7
  Gem::Specification.new do |spec|
7
8
  spec.required_ruby_version = ['>= 2.4', '< 2.7']
8
9
 
@@ -20,10 +21,15 @@ Gem::Specification.new do |spec|
20
21
 
21
22
  spec.require_paths = ['lib']
22
23
 
24
+ spec.metadata = {
25
+ 'bug_tracker_uri' => "#{spec.homepage}/issues",
26
+ 'changelog_uri' => "#{spec.homepage}/blob/v#{spec.version}/CHANGELOG.md"
27
+ }
28
+
23
29
  spec.add_development_dependency 'rake', '~> 12.3'
24
30
  spec.add_development_dependency 'reek', '~> 5.4'
25
31
  spec.add_development_dependency 'rspec', '~> 3.8'
26
- spec.add_development_dependency 'rubocop', '~> 0.67.2'
32
+ spec.add_development_dependency 'rubocop', '~> 0.68.1'
27
33
  spec.add_development_dependency 'rubocop-performance', '~> 1.1'
28
34
  spec.add_development_dependency 'rubocop-rspec', '~> 1.32'
29
35
  spec.add_development_dependency 'simplecov', '~> 0.16.1'
@@ -34,3 +40,4 @@ Gem::Specification.new do |spec|
34
40
  spec.add_runtime_dependency 'http', '~> 5.0.0.pre'
35
41
  spec.add_runtime_dependency 'nokogiri', '~> 1.10'
36
42
  end
43
+ # rubocop:enable Metrics/BlockLength
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webmention-verification
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.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: 2019-04-26 00:00:00.000000000 Z
11
+ date: 2019-05-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 0.67.2
61
+ version: 0.68.1
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.67.2
68
+ version: 0.68.1
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rubocop-performance
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -203,6 +203,7 @@ files:
203
203
  - lib/webmention/verification.rb
204
204
  - lib/webmention/verification/client.rb
205
205
  - lib/webmention/verification/exceptions.rb
206
+ - lib/webmention/verification/http_request.rb
206
207
  - lib/webmention/verification/registerable.rb
207
208
  - lib/webmention/verification/verifiers.rb
208
209
  - lib/webmention/verification/verifiers/html_verifier.rb
@@ -213,7 +214,9 @@ files:
213
214
  homepage: https://github.com/jgarber623/webmention-verification-ruby
214
215
  licenses:
215
216
  - MIT
216
- metadata: {}
217
+ metadata:
218
+ bug_tracker_uri: https://github.com/jgarber623/webmention-verification-ruby/issues
219
+ changelog_uri: https://github.com/jgarber623/webmention-verification-ruby/blob/v1.1.0/CHANGELOG.md
217
220
  post_install_message:
218
221
  rdoc_options: []
219
222
  require_paths: