ruby-link-checker 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +3 -0
  3. data/CONTRIBUTING.md +125 -0
  4. data/Dangerfile +4 -0
  5. data/Gemfile +23 -0
  6. data/Gemfile.lock +162 -0
  7. data/LICENSE.md +22 -0
  8. data/README.md +279 -0
  9. data/RELEASING.md +60 -0
  10. data/Rakefile +18 -0
  11. data/benchmarks/check.rb +31 -0
  12. data/benchmarks/data/opensearch.org/links.txt +4270 -0
  13. data/benchmarks/data/opensearch.org/small.txt +100 -0
  14. data/coverage/assets/0.12.3/DataTables-1.10.20/images/sort_asc.png +0 -0
  15. data/coverage/assets/0.12.3/DataTables-1.10.20/images/sort_asc_disabled.png +0 -0
  16. data/coverage/assets/0.12.3/DataTables-1.10.20/images/sort_both.png +0 -0
  17. data/coverage/assets/0.12.3/DataTables-1.10.20/images/sort_desc.png +0 -0
  18. data/coverage/assets/0.12.3/DataTables-1.10.20/images/sort_desc_disabled.png +0 -0
  19. data/coverage/assets/0.12.3/application.css +1 -0
  20. data/coverage/assets/0.12.3/application.js +7 -0
  21. data/coverage/assets/0.12.3/colorbox/border.png +0 -0
  22. data/coverage/assets/0.12.3/colorbox/controls.png +0 -0
  23. data/coverage/assets/0.12.3/colorbox/loading.gif +0 -0
  24. data/coverage/assets/0.12.3/colorbox/loading_background.png +0 -0
  25. data/coverage/assets/0.12.3/favicon_green.png +0 -0
  26. data/coverage/assets/0.12.3/favicon_red.png +0 -0
  27. data/coverage/assets/0.12.3/favicon_yellow.png +0 -0
  28. data/coverage/assets/0.12.3/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  29. data/coverage/assets/0.12.3/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
  30. data/coverage/assets/0.12.3/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  31. data/coverage/assets/0.12.3/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  32. data/coverage/assets/0.12.3/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  33. data/coverage/assets/0.12.3/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  34. data/coverage/assets/0.12.3/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  35. data/coverage/assets/0.12.3/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  36. data/coverage/assets/0.12.3/images/ui-icons_222222_256x240.png +0 -0
  37. data/coverage/assets/0.12.3/images/ui-icons_2e83ff_256x240.png +0 -0
  38. data/coverage/assets/0.12.3/images/ui-icons_454545_256x240.png +0 -0
  39. data/coverage/assets/0.12.3/images/ui-icons_888888_256x240.png +0 -0
  40. data/coverage/assets/0.12.3/images/ui-icons_cd0a0a_256x240.png +0 -0
  41. data/coverage/assets/0.12.3/loading.gif +0 -0
  42. data/coverage/assets/0.12.3/magnify.png +0 -0
  43. data/coverage/index.html +14555 -0
  44. data/lib/ruby-link-checker/callbacks.rb +50 -0
  45. data/lib/ruby-link-checker/checker.rb +42 -0
  46. data/lib/ruby-link-checker/config.rb +41 -0
  47. data/lib/ruby-link-checker/errors/base_error.rb +8 -0
  48. data/lib/ruby-link-checker/errors/redirect_loop_error.rb +18 -0
  49. data/lib/ruby-link-checker/errors.rb +2 -0
  50. data/lib/ruby-link-checker/logger.rb +14 -0
  51. data/lib/ruby-link-checker/net/http/checker.rb +31 -0
  52. data/lib/ruby-link-checker/net/http/config.rb +35 -0
  53. data/lib/ruby-link-checker/net/http/result.rb +53 -0
  54. data/lib/ruby-link-checker/net/http.rb +3 -0
  55. data/lib/ruby-link-checker/result.rb +74 -0
  56. data/lib/ruby-link-checker/task.rb +20 -0
  57. data/lib/ruby-link-checker/tasks.rb +99 -0
  58. data/lib/ruby-link-checker/typhoeus/hydra/checker.rb +52 -0
  59. data/lib/ruby-link-checker/typhoeus/hydra/config.rb +35 -0
  60. data/lib/ruby-link-checker/typhoeus/hydra/result.rb +53 -0
  61. data/lib/ruby-link-checker/typhoeus/hydra.rb +3 -0
  62. data/lib/ruby-link-checker/version.rb +5 -0
  63. data/lib/ruby-link-checker.rb +13 -0
  64. data/lib/ruby_link_checker.rb +3 -0
  65. data/pkg/ruby-link-checker-0.1.0.gem +0 -0
  66. data/ruby-link-checker.gemspec +21 -0
  67. data/spec/fixtures/200.yml +65 -0
  68. data/spec/fixtures/301_200.yml +102 -0
  69. data/spec/fixtures/301_301.yml +114 -0
  70. data/spec/fixtures/301_400_301_200.yml +185 -0
  71. data/spec/fixtures/301_403.yml +78 -0
  72. data/spec/fixtures/404.yml +57 -0
  73. data/spec/fixtures/404_200.yml +89 -0
  74. data/spec/fixtures/404_404.yml +81 -0
  75. data/spec/fixtures/429_200.yml +135 -0
  76. data/spec/fixtures/429_429_200.yml +201 -0
  77. data/spec/ruby-link-checker/callbacks_spec.rb +43 -0
  78. data/spec/ruby-link-checker/checker_spec.rb +10 -0
  79. data/spec/ruby-link-checker/config_spec.rb +39 -0
  80. data/spec/ruby-link-checker/net/http/checker_spec.rb +61 -0
  81. data/spec/ruby-link-checker/typhoeus/hydra/checker_spec.rb +67 -0
  82. data/spec/ruby-link-checker/version_spec.rb +9 -0
  83. data/spec/spec_helper.rb +17 -0
  84. data/spec/support/config.rb +8 -0
  85. data/spec/support/link_checker.rb +322 -0
  86. data/spec/support/vcr.rb +13 -0
  87. data/spec/support/with_result.rb +15 -0
  88. data/spec/support/with_url.rb +14 -0
  89. metadata +144 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 3edc71cca9ca0e7f43a58cc4776886f4ae55f1ef1709901be7a1aad93bf15f28
4
+ data.tar.gz: e306860ec44ecc137ddcf3fe2a585e2448b4a48ac957276f4f749337b2a469da
5
+ SHA512:
6
+ metadata.gz: da986eb191a3016dcedeb64d554e0da5d14310591bf9f1772d82bfa3572ead7671d3d29c8c16ce8fcdfd8c0924f720f3478fb083dd3d306a5bfb6cb8a28b1859
7
+ data.tar.gz: eef0ee4b258053dd33bae73c71a9569719dad39cee2860e885d67a37dc1eedab215b03566de5b289e154d6cae81c78f8786f4bb08eaf15f5bf862062db1a1dee
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ ### 0.1.0 (2023-04-02)
2
+
3
+ * Initial public release - [@dblock](https://github.com/dblock).
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,125 @@
1
+ # Contributing to ruby-link-checker
2
+
3
+ This project is work of [many contributors](https://github.com/dblock/ruby-link-checker/graphs/contributors).
4
+
5
+ You're encouraged to submit [pull requests](https://github.com/dblock/ruby-link-checker/pulls), [propose features and discuss issues](https://github.com/dblock/ruby-link-checker/issues).
6
+
7
+ In the examples below, substitute your Github username for `contributor` in URLs.
8
+
9
+ ### Fork the Project
10
+
11
+ Fork the [project on Github](https://github.com/dblock/ruby-link-checker) and check out your copy.
12
+
13
+ ```
14
+ git clone https://github.com/contributor/ruby-link-checker.git
15
+ cd ruby-link-checker
16
+ git remote add upstream https://github.com/dblock/ruby-link-checker.git
17
+ ```
18
+
19
+ ### Bundle Install and Test
20
+
21
+ Ensure that you can build the project and run tests.
22
+
23
+ ```
24
+ bundle install
25
+ bundle exec rake
26
+ ```
27
+
28
+ ## Contribute Code
29
+
30
+ ### Create a Topic Branch
31
+
32
+ Make sure your fork is up-to-date and create a topic branch for your feature or bug fix.
33
+
34
+ ```
35
+ git checkout main
36
+ git pull upstream main
37
+ git checkout -b my-feature-branch
38
+ ```
39
+
40
+ ### Write Tests
41
+
42
+ Try to write a test that reproduces the problem you're trying to fix or describes a feature that you want to build. Add tests to [spec](spec).
43
+
44
+ We definitely appreciate pull requests that highlight or reproduce a problem, even without a fix.
45
+
46
+ ### Write Code
47
+
48
+ Implement your feature or bug fix.
49
+
50
+ Ruby style is enforced with [Rubocop](https://github.com/bbatsov/rubocop). Run `bundle exec rubocop` and fix any style issues highlighted, auto-correct issues when possible with `bundle exec rubocop -a`. To silence generally ingored issues, including line lengths or code complexity metrics, run `bundle exec rubocop --auto-gen-config`.
51
+
52
+ Make sure that `bundle exec rake` completes without errors.
53
+
54
+ ### Write Documentation
55
+
56
+ Document any external behavior in the [README](README.md).
57
+
58
+ ### Update Changelog
59
+
60
+ Add a line to [CHANGELOG](CHANGELOG.md) under *Next Release*. Don't remove *Your contribution here*.
61
+
62
+ Make it look like every other line, including a link to the issue being fixed, your name and link to your Github account.
63
+
64
+ ### Commit Changes
65
+
66
+ Make sure git knows your name and email address:
67
+
68
+ ```
69
+ git config --global user.name "Your Name"
70
+ git config --global user.email "contributor@example.com"
71
+ ```
72
+
73
+ Writing good commit logs is important. A commit log should describe what changed and why.
74
+
75
+ ```
76
+ git add ...
77
+ git commit
78
+ ```
79
+
80
+ ### Push
81
+
82
+ ```
83
+ git push origin my-feature-branch
84
+ ```
85
+
86
+ ### Make a Pull Request
87
+
88
+ Go to https://github.com/contributor/ruby-link-checker and select your feature branch. Click the 'Pull Request' button and fill out the form. Pull requests are usually reviewed within a few days.
89
+
90
+ ### Update CHANGELOG Again
91
+
92
+ Update the [CHANGELOG](CHANGELOG.md) with the pull request number. A typical entry looks as follows.
93
+
94
+ ```
95
+ * [#123](https://github.com/dblock/ruby-link-checker/pull/123): Reticulated splines - [@contributor](https://github.com/contributor).
96
+ ```
97
+
98
+ Amend your previous commit and force push the changes.
99
+
100
+ ```
101
+ git commit --amend
102
+ git push origin my-feature-branch -f
103
+ ```
104
+
105
+ ### Rebase
106
+
107
+ If you've been working on a change for a while, rebase with upstream/main.
108
+
109
+ ```
110
+ git fetch upstream
111
+ git rebase upstream/main
112
+ git push origin my-feature-branch -f
113
+ ```
114
+
115
+ ### Check on Your Pull Request
116
+
117
+ Go back to your pull request after a few minutes and see whether it passed muster with Travis-CI. Everything should look green, otherwise fix issues and amend your commit as described above.
118
+
119
+ ### Be Patient
120
+
121
+ It's likely that your change will not be merged and that the nitpicky maintainers will ask you to do more, or fix seemingly benign problems. Hang on there!
122
+
123
+ ## Thank You
124
+
125
+ Please do know that we really appreciate and value your time and work. We love you, really.
data/Dangerfile ADDED
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ changelog.check!
4
+ toc.check!
data/Gemfile ADDED
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'http://rubygems.org'
4
+
5
+ gemspec
6
+
7
+ gem 'rake'
8
+
9
+ group :development, :test do
10
+ gem 'danger'
11
+ gem 'danger-changelog', '0.6.1'
12
+ gem 'danger-toc', '0.2.0'
13
+ gem 'rspec', '~> 3.0'
14
+ gem 'rubocop', '~> 1.0'
15
+ gem 'rubocop-rake'
16
+ gem 'rubocop-rspec'
17
+ gem 'vcr'
18
+ gem 'webmock'
19
+ end
20
+
21
+ group :test do
22
+ gem 'simplecov', require: false
23
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,162 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ ruby-link-checker (0.1.0)
5
+
6
+ GEM
7
+ remote: http://rubygems.org/
8
+ specs:
9
+ activesupport (7.0.4.3)
10
+ concurrent-ruby (~> 1.0, >= 1.0.2)
11
+ i18n (>= 1.6, < 2)
12
+ minitest (>= 5.1)
13
+ tzinfo (~> 2.0)
14
+ addressable (2.8.1)
15
+ public_suffix (>= 2.0.2, < 6.0)
16
+ ast (2.4.2)
17
+ claide (1.1.0)
18
+ claide-plugins (0.9.2)
19
+ cork
20
+ nap
21
+ open4 (~> 1.3)
22
+ colored2 (3.1.2)
23
+ concurrent-ruby (1.2.2)
24
+ cork (0.3.0)
25
+ colored2 (~> 3.1)
26
+ crack (0.4.5)
27
+ rexml
28
+ danger (9.2.0)
29
+ claide (~> 1.0)
30
+ claide-plugins (>= 0.9.2)
31
+ colored2 (~> 3.1)
32
+ cork (~> 0.1)
33
+ faraday (>= 0.9.0, < 3.0)
34
+ faraday-http-cache (~> 2.0)
35
+ git (~> 1.7)
36
+ kramdown (~> 2.3)
37
+ kramdown-parser-gfm (~> 1.0)
38
+ no_proxy_fix
39
+ octokit (~> 5.0)
40
+ terminal-table (>= 1, < 4)
41
+ danger-changelog (0.6.1)
42
+ danger-plugin-api (~> 1.0)
43
+ danger-plugin-api (1.0.0)
44
+ danger (> 2.0)
45
+ danger-toc (0.2.0)
46
+ activesupport
47
+ danger-plugin-api (~> 1.0)
48
+ kramdown
49
+ diff-lcs (1.5.0)
50
+ docile (1.4.0)
51
+ ethon (0.16.0)
52
+ ffi (>= 1.15.0)
53
+ faraday (2.7.4)
54
+ faraday-net_http (>= 2.0, < 3.1)
55
+ ruby2_keywords (>= 0.0.4)
56
+ faraday-http-cache (2.4.1)
57
+ faraday (>= 0.8)
58
+ faraday-net_http (3.0.2)
59
+ ffi (1.15.5)
60
+ git (1.18.0)
61
+ addressable (~> 2.8)
62
+ rchardet (~> 1.8)
63
+ hashdiff (1.0.1)
64
+ i18n (1.12.0)
65
+ concurrent-ruby (~> 1.0)
66
+ json (2.6.3)
67
+ kramdown (2.4.0)
68
+ rexml
69
+ kramdown-parser-gfm (1.1.0)
70
+ kramdown (~> 2.0)
71
+ minitest (5.18.0)
72
+ nap (1.1.0)
73
+ no_proxy_fix (0.1.2)
74
+ octokit (5.6.1)
75
+ faraday (>= 1, < 3)
76
+ sawyer (~> 0.9)
77
+ open4 (1.3.4)
78
+ parallel (1.22.1)
79
+ parser (3.2.1.1)
80
+ ast (~> 2.4.1)
81
+ public_suffix (5.0.1)
82
+ rainbow (3.1.1)
83
+ rake (13.0.6)
84
+ rchardet (1.8.0)
85
+ regexp_parser (2.7.0)
86
+ rexml (3.2.5)
87
+ rspec (3.12.0)
88
+ rspec-core (~> 3.12.0)
89
+ rspec-expectations (~> 3.12.0)
90
+ rspec-mocks (~> 3.12.0)
91
+ rspec-core (3.12.1)
92
+ rspec-support (~> 3.12.0)
93
+ rspec-expectations (3.12.2)
94
+ diff-lcs (>= 1.2.0, < 2.0)
95
+ rspec-support (~> 3.12.0)
96
+ rspec-mocks (3.12.4)
97
+ diff-lcs (>= 1.2.0, < 2.0)
98
+ rspec-support (~> 3.12.0)
99
+ rspec-support (3.12.0)
100
+ rubocop (1.48.1)
101
+ json (~> 2.3)
102
+ parallel (~> 1.10)
103
+ parser (>= 3.2.0.0)
104
+ rainbow (>= 2.2.2, < 4.0)
105
+ regexp_parser (>= 1.8, < 3.0)
106
+ rexml (>= 3.2.5, < 4.0)
107
+ rubocop-ast (>= 1.26.0, < 2.0)
108
+ ruby-progressbar (~> 1.7)
109
+ unicode-display_width (>= 2.4.0, < 3.0)
110
+ rubocop-ast (1.28.0)
111
+ parser (>= 3.2.1.0)
112
+ rubocop-capybara (2.17.1)
113
+ rubocop (~> 1.41)
114
+ rubocop-rake (0.6.0)
115
+ rubocop (~> 1.0)
116
+ rubocop-rspec (2.19.0)
117
+ rubocop (~> 1.33)
118
+ rubocop-capybara (~> 2.17)
119
+ ruby-progressbar (1.13.0)
120
+ ruby2_keywords (0.0.5)
121
+ sawyer (0.9.2)
122
+ addressable (>= 2.3.5)
123
+ faraday (>= 0.17.3, < 3)
124
+ simplecov (0.22.0)
125
+ docile (~> 1.1)
126
+ simplecov-html (~> 0.11)
127
+ simplecov_json_formatter (~> 0.1)
128
+ simplecov-html (0.12.3)
129
+ simplecov_json_formatter (0.1.4)
130
+ terminal-table (3.0.2)
131
+ unicode-display_width (>= 1.1.1, < 3)
132
+ typhoeus (1.4.0)
133
+ ethon (>= 0.9.0)
134
+ tzinfo (2.0.6)
135
+ concurrent-ruby (~> 1.0)
136
+ unicode-display_width (2.4.2)
137
+ vcr (6.1.0)
138
+ webmock (3.18.1)
139
+ addressable (>= 2.8.0)
140
+ crack (>= 0.3.2)
141
+ hashdiff (>= 0.4.0, < 2.0.0)
142
+
143
+ PLATFORMS
144
+ arm64-darwin-21
145
+
146
+ DEPENDENCIES
147
+ danger
148
+ danger-changelog (= 0.6.1)
149
+ danger-toc (= 0.2.0)
150
+ rake
151
+ rspec (~> 3.0)
152
+ rubocop (~> 1.0)
153
+ rubocop-rake
154
+ rubocop-rspec
155
+ ruby-link-checker!
156
+ simplecov
157
+ typhoeus
158
+ vcr
159
+ webmock
160
+
161
+ BUNDLED WITH
162
+ 2.4.2
data/LICENSE.md ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) Daniel Doubrovkine and contributors.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,279 @@
1
+ Fast Ruby Link Checker
2
+ ======================
3
+
4
+ [![Gem Version](http://img.shields.io/gem/v/ruby-link-checker.svg)](http://badge.fury.io/rb/ruby-link-checker)
5
+ [![Build Status](https://github.com/dblock/ruby-link-checker/workflows/test/badge.svg?branch=main)](https://github.com/dblock/ruby-link-checker/actions)
6
+ [![Code Climate](https://codeclimate.com/github/dblock/ruby-link-checker.svg)](https://codeclimate.com/github/dblock/ruby-link-checker)
7
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/164f1e23fc706b6efa63/test_coverage)](https://codeclimate.com/github/dblock/ruby-link-checker/test_coverage)
8
+
9
+ A fast Ruby link checker with support for multiple HTTP libraries. Does not parse documents, just checks links. Fast. Anecdotal benchmarking on a M1 mac and T1 Internet yields ~50 URLs per second with `LinkChecker::Typhoeus::Hydra`.
10
+
11
+ ## Table of Contents
12
+
13
+ - [Usage](#usage)
14
+ - [Dependencies](#dependencies)
15
+ - [Basic Usage](#basic-usage)
16
+ - [Passing Options](#passing-options)
17
+ - [Checkers](#checkers)
18
+ - [LinkChecker::Typhoeus::Hydra](#linkcheckertyphoeushydra)
19
+ - [LinkChecker::Net::HTTP](#linkcheckernethttp)
20
+ - [Options](#options)
21
+ - [Retries](#retries)
22
+ - [Results](#results)
23
+ - [Methods](#methods)
24
+ - [Logger](#logger)
25
+ - [User-Agent](#user-agent)
26
+ - [Global Configuration](#global-configuration)
27
+ - [Callbacks and Events](#callbacks-and-events)
28
+ - [Contributing](#contributing)
29
+ - [Copyright and License](#copyright-and-license)
30
+
31
+ ## Usage
32
+
33
+ ### Dependencies
34
+
35
+ The [`LinkChecker::Typhoeus::Hydra`](lib/ruby-link-checker/typhoeus/hydra/checker.rb) link checker is recommended.
36
+
37
+ Add `typhoeus` and `ruby-link-checker` to your `Gemfile` and run `bundle install`.
38
+
39
+ ```ruby
40
+ gem 'typhoeus'
41
+ gem 'ruby-link-checker'
42
+ ```
43
+
44
+ ### Basic Usage
45
+
46
+ ```ruby
47
+ require 'typhoeus'
48
+ require 'ruby-link-checker'
49
+
50
+ # create a new checker instance
51
+ checker = LinkChecker::Typhoeus::Hydra::Checker.new
52
+
53
+ # queue URLs to check
54
+ links = [...]
55
+ links.each do |url|
56
+ checker.check url
57
+ end
58
+
59
+ # run the checks
60
+ checker.run
61
+
62
+ # display buckets of results
63
+ checker.results.each_pair do |bucket, results|
64
+ puts "#{bucket}: #{results.size}"
65
+ end
66
+ ```
67
+
68
+ ### Passing Options
69
+
70
+ You can pipe custom options through `check` and retrieve them in events as follows.
71
+
72
+ ```ruby
73
+ checker.check 'https://www.example.org', { location: 'page.html' }
74
+
75
+ checker.on :success do |result|
76
+ result.options # contains { location: 'page.html' }
77
+ end
78
+ ```
79
+
80
+ ### Checkers
81
+
82
+ #### [LinkChecker::Typhoeus::Hydra](lib/ruby-link-checker/typhoeus/hydra/checker.rb)
83
+
84
+ Fast link checker that uses [Typhoeus](https://typhoeus.github.io/).
85
+
86
+ ```ruby
87
+ require 'typhoeus'
88
+ require 'ruby-link-checker'
89
+
90
+ # create a new instance of a checker
91
+ checker = LinkChecker::Typhoeus::Hydra::Checker.new(
92
+ hydra: {
93
+ # lower than the Typhoeus default of 200, seems to start breaking around 50+
94
+ max_concurrency: 25
95
+ }
96
+ )
97
+
98
+ # log requests and response codes
99
+ checker.logger.level = Logger::INFO
100
+
101
+ links = [...] # array of URLs
102
+ links.each do |url|
103
+ checker.check url
104
+ end
105
+
106
+ # examine failures and errors as they come
107
+ checker.on :error, :failure do |result|
108
+ puts "FAIL: #{result}"
109
+ end
110
+
111
+ # execute Hydra#run, will block until all requests have completed
112
+ checker.run
113
+
114
+ # examine results
115
+ checker.results.each_pair do |bucket, results|
116
+ puts "#{bucket}: #{results.size}"
117
+ end
118
+ ```
119
+
120
+ You can pass `Typhoeus` timeout options into a new instance of a checker, or configure timeouts globally.
121
+
122
+ ```ruby
123
+ LinkChecker::Typhoeus::Hydra.configure do |config|
124
+ config.timeout = 5
125
+ config.connecttimeout = 10
126
+ end
127
+ ```
128
+
129
+ #### [LinkChecker::Net::HTTP](lib/ruby-link-checker/net/http/checker.rb)
130
+
131
+ Slow, sequential checker.
132
+
133
+ ```ruby
134
+ require 'net/http'
135
+ require 'ruby-link-checker'
136
+
137
+ # create a new instance of a checker
138
+ checker = LinkChecker::Net::HTTP::Checker.new
139
+
140
+ # log requests and response codes
141
+ checker.logger.level = Logger::INFO
142
+
143
+ links = [...] # array of URLs
144
+ links.each do |url|
145
+ checker.check url
146
+ end
147
+
148
+ # examine results
149
+ checker.results.each_pair do |bucket, results|
150
+ puts "#{bucket}: #{results.size}"
151
+ end
152
+ ```
153
+
154
+ You can pass `Net::HTTP` timeout options into a new instance of a checker, or configure timeouts globally.
155
+
156
+ ```ruby
157
+ LinkChecker::Net::HTTP.configure do |config|
158
+ config.read_timeout = 5
159
+ config.open_timeout = 10
160
+ end
161
+ ```
162
+
163
+ ### Options
164
+
165
+ #### Retries
166
+
167
+ By default link checkers do not retry. You can set a number of times to retry all errors and failures with `retries`.
168
+
169
+ ```ruby
170
+ checker = LinkChecker::Net::HTTP::Checker.new(retry: 1)
171
+ ```
172
+
173
+ #### Results
174
+
175
+ By default checkers collect results.
176
+
177
+ ```ruby
178
+ checker = LinkChecker::Net::HTTP::Checker.new(results: false)
179
+ ...
180
+ checker.run
181
+
182
+ checker.results # => { error: [...], failure: [...], success: [...] }
183
+ ```
184
+
185
+ You can disable this with `results: false`.
186
+
187
+ ```ruby
188
+ checker = LinkChecker::Net::HTTP::Checker.new(results: false)
189
+ ...
190
+ checker.run
191
+
192
+ checker.results # => nil
193
+ ```
194
+
195
+ #### Methods
196
+
197
+ By default checkers try a `HEAD` request, followed by a `GET` if `HEAD` fails. You can change this behavior by specifying other methods.
198
+
199
+ The following examples disables `GET` and only makes `HEAD` requests.
200
+
201
+ ```ruby
202
+ checker = LinkChecker::Net::HTTP::Checker.new(methods: %w[HEAD])
203
+ ```
204
+
205
+ #### Logger
206
+
207
+ Pass your own logger.
208
+
209
+ ```ruby
210
+ checker = LinkChecker::Net::HTTP::Checker.new(logger: Logger.new(STDOUT))
211
+ ```
212
+
213
+ #### User-Agent
214
+
215
+ Pass your own user-agent. Default is `Ruby Link Checker/x.y.z`.
216
+
217
+ ```ruby
218
+ checker = LinkChecker::Net::HTTP::Checker.new(user_agent: 'Custom Agent/1.0')
219
+ ```
220
+
221
+ ### Global Configuration
222
+
223
+ All options can also be configured globally.
224
+
225
+ ```ruby
226
+ LinkChecker.configure do |config|
227
+ config.user_agent = 'Custom Agent/1.0'
228
+ config.methods = ['HEAD', 'GET']
229
+ config.logger = ::Logger.new(STDOUT)
230
+ end
231
+ ```
232
+
233
+ ### Callbacks and Events
234
+
235
+ Events enable processing of results as they become available.
236
+
237
+ ```ruby
238
+ checker.on :result do |result|
239
+ puts result # any result
240
+ end
241
+
242
+ checker.on :error, :failure do |result|
243
+ puts result # error or failure
244
+ end
245
+ ```
246
+
247
+ Checkers support the following events.
248
+
249
+ | Event | Description |
250
+ |----------|----------------------------------------------------------------|
251
+ | :retry | A request is being retried on failure or error. |
252
+ | :result | A new result, any of success, failure, or error. |
253
+ | :success | A valid URL, usually a 2xx response from the server. |
254
+ | :failure | A failed URL, usually a 4xx or a 5xx response from the server. |
255
+ | :error | An error, such as an invalid URL or a network timeout. |
256
+
257
+ Events are called with results, which contain the following properties.
258
+
259
+ | Property | Description |
260
+ |-------------------|-----------------------------------------------------------------|
261
+ | :url | The original URL before redirects. |
262
+ | :result_url | The last URL, different from `url` in case of redirects. |
263
+ | :method | The result HTTP method. |
264
+ | :code | HTTP error code. |
265
+ | :request_headers | Request headers. |
266
+ | :redirect_to | A redirect URL in case of redirects. |
267
+ | :error | A raised error in case of errors. |
268
+
269
+ See [result.rb](lib/ruby-link-checker/result.rb) for more details.
270
+
271
+ ## Contributing
272
+
273
+ You're encouraged to contribute to ruby-link-checker. See [CONTRIBUTING](CONTRIBUTING.md) for details.
274
+
275
+ ## Copyright and License
276
+
277
+ Copyright (c) Daniel Doubrovkine and [Contributors](CHANGELOG.md).
278
+
279
+ This project is licensed under the [MIT License](LICENSE.md).
data/RELEASING.md ADDED
@@ -0,0 +1,60 @@
1
+ # Releasing ruby-link-checker
2
+
3
+ There are no hard rules about when to release ruby-link-checker. Release bug fixes frequently, features not so frequently and breaking API changes rarely.
4
+
5
+ ### Release
6
+
7
+ Run tests, check that all tests succeed locally.
8
+
9
+ ```
10
+ bundle install
11
+ rake
12
+ ```
13
+
14
+ Check that the last build succeeded.
15
+
16
+ Add a date to this release in [CHANGELOG.md](CHANGELOG.md).
17
+
18
+ ```
19
+ ### 0.2.2 (2015/7/10)
20
+ ```
21
+
22
+ Remove the line with "Your contribution here.", since there will be no more contributions to this release.
23
+
24
+ Commit your changes.
25
+
26
+ ```
27
+ git add README.md CHANGELOG.md lib/ruby-link-checker/version.rb
28
+ git commit -m "Preparing for release, 0.2.2."
29
+ ```
30
+
31
+ Release.
32
+
33
+ ```
34
+ $ rake release
35
+
36
+ ruby-link-checker 0.2.2 built to pkg/ruby-link-checker-0.2.2.gem.
37
+ Tagged v0.2.2.
38
+ Pushed git commits and tags.
39
+ Pushed ruby-link-checker 0.2.2 to rubygems.org.
40
+ ```
41
+
42
+ ### Prepare for the Next Version
43
+
44
+ Add the next release to [CHANGELOG.md](CHANGELOG.md).
45
+
46
+ ```
47
+ ### 0.2.3 (Next)
48
+
49
+ * Your contribution here.
50
+ ```
51
+
52
+ Increment the third version number in [lib/ruby-link-checker/version.rb](lib/ruby-link-checker/version.rb).
53
+
54
+ Commit your changes.
55
+
56
+ ```
57
+ git add CHANGELOG.md lib/ruby-link-checker/version.rb
58
+ git commit -m "Preparing for next development iteration, 0.2.3."
59
+ git push origin main
60
+ ```
data/Rakefile ADDED
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rubygems'
4
+ require 'bundler/gem_tasks'
5
+
6
+ Bundler.setup :default, :development
7
+
8
+ require 'rspec/core'
9
+ require 'rspec/core/rake_task'
10
+
11
+ RSpec::Core::RakeTask.new(:spec) do |spec|
12
+ spec.pattern = FileList['spec/**/*_spec.rb']
13
+ end
14
+
15
+ require 'rubocop/rake_task'
16
+ RuboCop::RakeTask.new(:rubocop)
17
+
18
+ task default: %i[rubocop spec]