indieweb-endpoints 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 0c45996ba696d87124c8c764fce951197377fccfa3bf84d30ed702b3a27df610
4
+ data.tar.gz: 562c474fa0079dfc5d6cbd8286e1a8c5cb169d1f54ede4404bfab2cec854a0bf
5
+ SHA512:
6
+ metadata.gz: 4417010c2a25d2bb07f8e59f63cd3aa31149aaa5dda33391fba11b7ef1d90d1acb2cd8e642dcf38086a6016027159914941d8dd69fb7f9beae7fe30b6b1cc2db
7
+ data.tar.gz: 43da9e43bb391e7e2ecf999d1bb21dd3776c005037a746230d65066c67dad68883f1397fa2e46c812daec21bd80df006e24620a4608e06774787d08705b81981
@@ -0,0 +1,14 @@
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
11
+
12
+ [*.md]
13
+ indent_size = 4
14
+ indent_style = tab
@@ -0,0 +1 @@
1
+ * jgarber623
@@ -0,0 +1,34 @@
1
+ *.gem
2
+ *.rbc
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:
29
+ Gemfile.lock
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,6 @@
1
+ detectors:
2
+ IrresponsibleModule:
3
+ enabled: false
4
+
5
+ exclude_paths:
6
+ - vendor/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --order random
2
+ --require spec_helper
@@ -0,0 +1,3 @@
1
+ --display-style-guide
2
+ --extra-details
3
+ --parallel
@@ -0,0 +1,29 @@
1
+ require:
2
+ - rubocop-performance
3
+ - rubocop-rspec
4
+
5
+ AllCops:
6
+ NewCops: enable
7
+
8
+ Layout/LineLength:
9
+ Enabled: false
10
+
11
+ Metrics/BlockLength:
12
+ Exclude:
13
+ - spec/**/*.rb
14
+
15
+ Naming/RescuedExceptionsVariableName:
16
+ PreferredName: exception
17
+
18
+ RSpec/FilePath:
19
+ Exclude:
20
+ - spec/lib/indieweb/**/*_spec.rb
21
+
22
+ Style/Documentation:
23
+ Enabled: false
24
+
25
+ Style/FrozenStringLiteralComment:
26
+ Enabled: false
27
+
28
+ Style/SymbolArray:
29
+ Enabled: false
@@ -0,0 +1 @@
1
+ 2.5.8
@@ -0,0 +1,13 @@
1
+ require 'simplecov-console'
2
+
3
+ formatters = [SimpleCov::Formatter::HTMLFormatter]
4
+
5
+ # rubocop:disable Style/IfUnlessModifier
6
+ if RSpec.configuration.files_to_run.length > 1
7
+ formatters << SimpleCov::Formatter::Console
8
+ end
9
+ # rubocop:enable Style/IfUnlessModifier
10
+
11
+ SimpleCov.start do
12
+ formatter SimpleCov::Formatter::MultiFormatter.new(formatters)
13
+ end
@@ -0,0 +1,15 @@
1
+ dist: bionic
2
+ language: ruby
3
+ rvm:
4
+ - 2.5
5
+ - 2.6
6
+ - 2.7
7
+ cache: bundler
8
+ before_script:
9
+ - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
10
+ - chmod +x ./cc-test-reporter
11
+ - ./cc-test-reporter before-build
12
+ after_script:
13
+ - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
14
+ notifications:
15
+ email: false
@@ -0,0 +1,75 @@
1
+ # Changelog
2
+
3
+ ## 4.0.0 / 2020-07-21
4
+
5
+ - **Breaking change:** Return a Hash of endpoints instead of an OpenStruct (15dc387)
6
+ - Update [link-header-parser](https://rubygems.org/gems/link-header-parser) dependency to v2.0.0 (2255e6b)
7
+ - **Breaking change:** Update development Ruby version to 2.5.8 and minimum Ruby version to 2.5 (dd5a142)
8
+ - Refactor response headers/body parsers into a single class (ee02da3)
9
+ - Refactor `IndieWeb::Endpoints::Client` and remove `HttpRequestService` (2732616)
10
+ - Add offending url to exception message (#5) (4bf7a54)
11
+
12
+ ## 3.0.0 / 2020-05-14
13
+
14
+ - Update Absolutely and LinkHeaderParser dependencies (9e0a64a)
15
+ - Move development dependencies to `Gemfile` (67067f3)
16
+ - Update development Ruby version to 2.4.10 (f5430f9)
17
+
18
+ ## 2.0.0 / 2020-01-25
19
+
20
+ - Downgrade HTTP gem version constraint to ~> 4.3 (cb63230)
21
+
22
+ ## 1.1.0 / 2020-01-20
23
+
24
+ - Expand supported Ruby versions to include 2.7 (ae63ed0)
25
+ - Update project Ruby version to 2.4.9 (e576ad6)
26
+
27
+ ## 1.0.2 / 2019-08-31
28
+
29
+ - Update WebMock and Addressable gems (298da63)
30
+ - Update development dependencies (5663e3a)
31
+
32
+ ## 1.0.1 / 2019-07-17
33
+
34
+ - Safely combine, flatten, and compact result set (5f2d9c5)
35
+
36
+ ## 1.0.0 / 2019-07-08
37
+
38
+ - Refactor gem code using service objects approach (78511d7 and 9d2fee0)
39
+
40
+ ## 0.7.0 / 2019-07-03
41
+
42
+ - Update runtime and development dependencies (d99214b and 7692ab3)
43
+
44
+ ## 0.6.0 / 2019-06-15
45
+
46
+ - Update Parser-related classes to resolve #2
47
+
48
+ ## 0.5.0 / 2019-05-09
49
+
50
+ - Add support for Microsub endpoint discovery (5e81d9f)
51
+ - Refactor parsers to ignore URLs with fragments (797b376)
52
+ - Rescue `NoMethodError` (for `nil`) and `TypeError` (for non-`String`) (e33522e)
53
+ - Raise `ArgumentError` if url scheme is not `http` or `https` (8eb1b1a)
54
+ - Shorten up User Agent string (f9717b4)
55
+ - Refactor `HTTPRequest` class using specification defaults (feef2ba)
56
+
57
+ ## 0.4.0 / 2019-05-01
58
+
59
+ - Add `IndieWeb::Endpoints.client` method (c4d42d0)
60
+ - Rename base `Error` class to `IndieWebEndpointsError` (d6d6f98)
61
+ - Add `HttpRequest` class (7864cbd)
62
+
63
+ ## 0.3.0 / 2019-04-30
64
+
65
+ - `IndieWeb::Endpoints::Client#endpoints` returns an `OpenStruct` instead of a `Hash` (c209b0b).
66
+
67
+ ## 0.2.0 / 2019-04-25
68
+
69
+ - Subclass exceptions under `IndieWeb::Endpoints::Error` (667eec7)
70
+ - Refactor parsers and `Registerable` module (3b96858)
71
+ - Refactor `Client#response` method (c36fda3)
72
+
73
+ ## 0.1.0 / 2019-04-24
74
+
75
+ - Initial release!
@@ -0,0 +1,3 @@
1
+ # Code of Conduct
2
+
3
+ By contributing to and participating in the development of indieweb-endpoints-ruby, you acknowledge that you have read and agree to the [IndieWeb Code of Conduct](https://indieweb.org/code-of-conduct).
@@ -0,0 +1,37 @@
1
+ # Contributing to indieweb-endpoints-ruby
2
+
3
+ There are a couple ways you can help improve indieweb-endpoints-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
+ indieweb-endpoints-ruby is developed using Ruby 2.5.8 and is additionally tested against Ruby 2.6 and 2.7 using [Travis CI](https://travis-ci.com/indieweb/indieweb-endpoints-ruby).
12
+
13
+ Before making changes to indieweb-endpoints-ruby, you'll want to install Ruby 2.5.8. 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.5.8 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/indieweb-endpoints-ruby/issues
37
+ [pulls]: https://github.com/indieweb/indieweb-endpoints-ruby/pulls
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in indieweb-endpoints.gemspec
4
+ gemspec
5
+
6
+ gem 'pry-byebug', '~> 3.9'
7
+ gem 'rake', '~> 13.0'
8
+ gem 'reek', '~> 6.0'
9
+ gem 'rspec', '~> 3.9'
10
+ gem 'rubocop', '~> 0.88.0'
11
+ gem 'rubocop-performance', '~> 1.7'
12
+ gem 'rubocop-rspec', '~> 1.42'
13
+ gem 'simplecov', '~> 0.18.5'
14
+ gem 'simplecov-console', '~> 0.7.2'
15
+ gem 'webmock', '~> 3.8'
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 Jason Garber
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,99 @@
1
+ # indieweb-endpoints-ruby
2
+
3
+ **A Ruby gem for discovering a URL's [IndieAuth](https://indieweb.org/IndieAuth), [Micropub](https://indieweb.org/Micropub), [Microsub](https://indieweb.org/Microsub), and [Webmention](https://indieweb.org/Webmention) endpoints.**
4
+
5
+ [![Gem](https://img.shields.io/gem/v/indieweb-endpoints.svg?style=for-the-badge)](https://rubygems.org/gems/indieweb-endpoints)
6
+ [![Downloads](https://img.shields.io/gem/dt/indieweb-endpoints.svg?style=for-the-badge)](https://rubygems.org/gems/indieweb-endpoints)
7
+ [![Build](https://img.shields.io/travis/com/indieweb/indieweb-endpoints-ruby/master.svg?style=for-the-badge)](https://travis-ci.com/indieweb/indieweb-endpoints-ruby)
8
+ [![Maintainability](https://img.shields.io/codeclimate/maintainability/indieweb/indieweb-endpoints-ruby.svg?style=for-the-badge)](https://codeclimate.com/github/indieweb/indieweb-endpoints-ruby)
9
+ [![Coverage](https://img.shields.io/codeclimate/c/indieweb/indieweb-endpoints-ruby.svg?style=for-the-badge)](https://codeclimate.com/github/indieweb/indieweb-endpoints-ruby/code)
10
+
11
+ ## Key Features
12
+
13
+ - Compliant with [Section 4.1](https://www.w3.org/TR/indieauth/#discovery-by-clients) and [Section 4.2.2](https://www.w3.org/TR/indieauth/#redirect-url) of [the W3C's IndieAuth Working Group Note](https://www.w3.org/TR/indieauth/), [Section 5.3](https://www.w3.org/TR/micropub/#endpoint-discovery) of [the W3C's Micropub Recommendation](https://www.w3.org/TR/micropub/), and [Section 3.1.2](https://www.w3.org/TR/webmention/#sender-discovers-receiver-webmention-endpoint) of [the W3C's Webmention Recommendation](https://www.w3.org/TR/webmention/).
14
+ - Passes all Endpoint Discovery tests on [webmention.rocks](https://webmention.rocks).
15
+ - Supports Ruby 2.5 and newer.
16
+
17
+ ## Getting Started
18
+
19
+ Before installing and using indieweb-endpoints-ruby, you'll want to have [Ruby](https://www.ruby-lang.org) 2.5 (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
+
21
+ indieweb-endpoints-ruby is developed using Ruby 2.5.8 and is additionally tested against Ruby 2.6 and 2.7 using [Travis CI](https://travis-ci.com/indieweb/indieweb-endpoints-ruby).
22
+
23
+ ## Installation
24
+
25
+ If you're using [Bundler](https://bundler.io), add indieweb-endpoints-ruby to your project's `Gemfile`:
26
+
27
+ ```ruby
28
+ source 'https://rubygems.org'
29
+
30
+ gem 'indieweb-endpoints'
31
+ ```
32
+
33
+ …and hop over to your command prompt and run…
34
+
35
+ ```sh
36
+ $ bundle install
37
+ ```
38
+
39
+ ## Usage
40
+
41
+ ### Basic Usage
42
+
43
+ With indieweb-endpoints-ruby added to your project's `Gemfile` and installed, you may discover a URL's IndieWeb-relevant endpoints by doing:
44
+
45
+ ```ruby
46
+ require 'indieweb/endpoints'
47
+
48
+ IndieWeb::Endpoints.get('https://aaronparecki.com')
49
+ #=> { authorization_endpoint: "https://aaronparecki.com/auth", micropub: "https://aaronparecki.com/micropub", microsub: "https://aperture.p3k.io/microsub/1", redirect_uri: nil, token_endpoint: "https://aaronparecki.com/auth/token", webmention: "https://webmention.io/aaronpk/webmention" }
50
+ ```
51
+
52
+ This example will search `https://aaronparecki.com` for valid IndieAuth, Micropub, and Webmention endpoints and return a `Hash` of results. Each key in the returned `Hash` will have a value of either a `String` representing a URL or `nil`. The `redirect_uri` key's value will be either an `Array` or `nil` since a given URL may register multiple callback URLs.
53
+
54
+ ### Advanced Usage
55
+
56
+ Should the need arise, you may work with the `IndieWeb::Endpoints::Client` class:
57
+
58
+ ```ruby
59
+ require 'indieweb/endpoints'
60
+
61
+ client = IndieWeb::Endpoints::Client.new('https://aaronparecki.com')
62
+ #=> #<IndieWeb::Endpoints::Client url: "https://aaronparecki.com">
63
+
64
+ client.response
65
+ #=> #<HTTP::Response/1.1 200 OK {…}>
66
+
67
+ client.endpoints
68
+ #=> { authorization_endpoint: "https://aaronparecki.com/auth", micropub: "https://aaronparecki.com/micropub", microsub: "https://aperture.p3k.io/microsub/1", redirect_uri: nil, token_endpoint: "https://aaronparecki.com/auth/token", webmention: "https://webmention.io/aaronpk/webmention" }
69
+ ```
70
+
71
+ ### Exception Handling
72
+
73
+ There are several exceptions that may be raised by indieweb-endpoints-ruby's underlying dependencies. These errors are raised as subclasses of `IndieWebEndpointsError` (which itself is a subclass of `StandardError`).
74
+
75
+ From [jgarber623/absolutely](https://github.com/jgarber623/absolutely) and [sporkmonger/addressable](https://github.com/sporkmonger/addressable):
76
+
77
+ - `IndieWeb::Endpoints::InvalidURIError`
78
+
79
+ From [httprb/http](https://github.com/httprb/http):
80
+
81
+ - `IndieWeb::Endpoints::ConnectionError`
82
+ - `IndieWeb::Endpoints::TimeoutError`
83
+ - `IndieWeb::Endpoints::TooManyRedirectsError`
84
+
85
+ ## Contributing
86
+
87
+ Interested in helping improve indieweb-endpoints-ruby? Awesome! Your help is greatly appreciated. See [CONTRIBUTING.md](https://github.com/indieweb/indieweb-endpoints-ruby/blob/master/CONTRIBUTING.md) for details.
88
+
89
+ By contributing to and participating in the development of indieweb-endpoints-ruby, you acknowledge that you have read and agree to the [IndieWeb Code of Conduct](https://indieweb.org/code-of-conduct).
90
+
91
+ ## Acknowledgments
92
+
93
+ indieweb-endpoints-ruby wouldn't exist without IndieAuth, Micropub, and Webmention and the hard work put in by everyone involved in the [IndieWeb](https://indieweb.org) movement. Additionally, the comprehensive Webmention Endpoint Discovery test suite at [webmention.rocks](https://webmention.rocks) was invaluable in the development of this Ruby gem.
94
+
95
+ indieweb-endpoints-ruby is written and maintained by [Jason Garber](https://sixtwothree.org).
96
+
97
+ ## License
98
+
99
+ indieweb-endpoints-ruby is freely available under the [MIT License](https://opensource.org/licenses/MIT). Use it, learn from it, fork it, improve it, change it, tailor it to your needs.
@@ -0,0 +1,17 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ require 'reek/rake/task'
4
+ require 'rspec/core/rake_task'
5
+ require 'rubocop/rake_task'
6
+
7
+ Reek::Rake::Task.new do |task|
8
+ task.fail_on_error = false
9
+ end
10
+
11
+ RSpec::Core::RakeTask.new
12
+
13
+ RuboCop::RakeTask.new do |task|
14
+ task.fail_on_error = false
15
+ end
16
+
17
+ task default: [:rubocop, :reek, :spec]
@@ -0,0 +1,30 @@
1
+ require_relative 'lib/indieweb/endpoints/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.5', '< 2.8')
5
+
6
+ spec.name = 'indieweb-endpoints'
7
+ spec.version = IndieWeb::Endpoints::VERSION
8
+ spec.authors = ['Jason Garber']
9
+ spec.email = ['jason@sixtwothree.org']
10
+
11
+ spec.summary = 'Discover a URL’s IndieAuth, Micropub, Microsub, and Webmention endpoints.'
12
+ spec.description = spec.summary
13
+ spec.homepage = 'https://github.com/indieweb/indieweb-endpoints-ruby'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
17
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(bin|spec)/}) }
18
+ end
19
+
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.metadata['bug_tracker_uri'] = "#{spec.homepage}/issues"
23
+ spec.metadata['changelog_uri'] = "#{spec.homepage}/blob/v#{spec.version}/CHANGELOG.md"
24
+
25
+ spec.add_runtime_dependency 'absolutely', '~> 4.0'
26
+ spec.add_runtime_dependency 'addressable', '~> 2.7'
27
+ spec.add_runtime_dependency 'http', '~> 4.4'
28
+ spec.add_runtime_dependency 'link-header-parser', '~> 2.0'
29
+ spec.add_runtime_dependency 'nokogiri', '~> 1.10'
30
+ end
@@ -0,0 +1,35 @@
1
+ require 'absolutely'
2
+ require 'addressable/uri'
3
+ require 'http'
4
+ require 'link-header-parser'
5
+ require 'nokogiri'
6
+
7
+ require 'indieweb/endpoints/version'
8
+ require 'indieweb/endpoints/exceptions'
9
+
10
+ require 'indieweb/endpoints/services/response_parser_service'
11
+
12
+ require 'indieweb/endpoints/client'
13
+ require 'indieweb/endpoints/parsers'
14
+
15
+ require 'indieweb/endpoints/parsers/base_parser'
16
+ require 'indieweb/endpoints/parsers/authorization_endpoint_parser'
17
+ require 'indieweb/endpoints/parsers/micropub_parser'
18
+ require 'indieweb/endpoints/parsers/microsub_parser'
19
+ require 'indieweb/endpoints/parsers/redirect_uri_parser'
20
+ require 'indieweb/endpoints/parsers/token_endpoint_parser'
21
+ require 'indieweb/endpoints/parsers/webmention_parser'
22
+
23
+ module IndieWeb
24
+ module Endpoints
25
+ # Discover a URL's IndieAuth, Micropub, Microsub, and Webmention endpoints
26
+ #
27
+ # IndieWeb::Endpoints.get('https://aaronparecki.com')
28
+ #
29
+ # @param url [String] an absolute URL
30
+ # @return [Hash{Symbol => String, Array, nil}]
31
+ def self.get(url)
32
+ Client.new(url).endpoints
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,54 @@
1
+ module IndieWeb
2
+ module Endpoints
3
+ class Client
4
+ HTTP_HEADERS_OPTS = {
5
+ accept: '*/*',
6
+ user_agent: 'IndieWeb Endpoint Discovery (https://rubygems.org/gems/indieweb-endpoints)'
7
+ }.freeze
8
+
9
+ # Create a new client with a URL to parse for IndieWeb endpoints
10
+ #
11
+ # client = IndieWeb::Endpoints::Client.new('https://aaronparecki.com')
12
+ #
13
+ # @param url [String] an absolute URL
14
+ def initialize(url)
15
+ raise ArgumentError, "url must be a String (given #{url.class})" unless url.is_a?(String)
16
+
17
+ @url = url
18
+
19
+ raise ArgumentError, "url (#{url}) must be an absolute URL (e.g. https://example.com)" unless uri.absolute? && uri.scheme.match?(/^https?$/)
20
+ end
21
+
22
+ # @return [String]
23
+ def inspect
24
+ format(%(#<#{self.class.name}:%#0x url: #{url.inspect}>), object_id)
25
+ end
26
+
27
+ # @return [Hash{Symbol => String, Array, nil}]
28
+ def endpoints
29
+ @endpoints ||= Parsers.registered.transform_values { |parser| parser.new(response).results }
30
+ end
31
+
32
+ # @see https://www.w3.org/TR/webmention/#limits-on-get-requests
33
+ #
34
+ # @return [HTTP::Response]
35
+ def response
36
+ @response ||= HTTP.follow(max_hops: 20).headers(HTTP_HEADERS_OPTS).timeout(connect: 5, read: 5).get(uri)
37
+ rescue HTTP::ConnectionError,
38
+ HTTP::TimeoutError,
39
+ HTTP::Redirector::TooManyRedirectsError => exception
40
+ raise IndieWeb::Endpoints.const_get(exception.class.name.split('::').last), exception
41
+ end
42
+
43
+ private
44
+
45
+ attr_accessor :url
46
+
47
+ def uri
48
+ @uri ||= Addressable::URI.parse(url)
49
+ rescue Addressable::URI::InvalidURIError => exception
50
+ raise InvalidURIError, exception
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,15 @@
1
+ module IndieWeb
2
+ module Endpoints
3
+ class IndieWebEndpointsError < StandardError; end
4
+
5
+ class ArgumentError < IndieWebEndpointsError; end
6
+
7
+ class ConnectionError < IndieWebEndpointsError; end
8
+
9
+ class InvalidURIError < IndieWebEndpointsError; end
10
+
11
+ class TimeoutError < IndieWebEndpointsError; end
12
+
13
+ class TooManyRedirectsError < IndieWebEndpointsError; end
14
+ end
15
+ end
@@ -0,0 +1,13 @@
1
+ module IndieWeb
2
+ module Endpoints
3
+ module Parsers
4
+ def self.register(klass)
5
+ registered[klass.identifier] = klass
6
+ end
7
+
8
+ def self.registered
9
+ @registered ||= {}
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ module IndieWeb
2
+ module Endpoints
3
+ module Parsers
4
+ class AuthorizationEndpointParser < BaseParser
5
+ @identifier = :authorization_endpoint
6
+
7
+ Parsers.register(self)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,45 @@
1
+ module IndieWeb
2
+ module Endpoints
3
+ module Parsers
4
+ class BaseParser
5
+ class << self
6
+ attr_reader :identifier
7
+ end
8
+
9
+ # @param response [HTTP::Response]
10
+ def initialize(response)
11
+ raise ArgumentError, "response must be an HTTP::Response (given #{response.class.name})" unless response.is_a?(HTTP::Response)
12
+
13
+ @response = response
14
+ end
15
+
16
+ # @return [String]
17
+ def results
18
+ mapped_results.shift
19
+ end
20
+
21
+ private
22
+
23
+ attr_reader :response
24
+
25
+ def mapped_results
26
+ @mapped_results ||= results_from_http_request.map { |endpoint| Absolutely.to_abs(base: response.uri.to_s, relative: endpoint) }.uniq.sort
27
+ rescue Absolutely::InvalidURIError => exception
28
+ raise InvalidURIError, exception
29
+ end
30
+
31
+ def results_from_body
32
+ @results_from_body ||= Services::ResponseParserService.parse_body(response, self.class.identifier)
33
+ end
34
+
35
+ def results_from_headers
36
+ @results_from_headers ||= Services::ResponseParserService.parse_headers(response, self.class.identifier)
37
+ end
38
+
39
+ def results_from_http_request
40
+ @results_from_http_request ||= [results_from_headers, results_from_body].flatten.compact
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,11 @@
1
+ module IndieWeb
2
+ module Endpoints
3
+ module Parsers
4
+ class MicropubParser < BaseParser
5
+ @identifier = :micropub
6
+
7
+ Parsers.register(self)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module IndieWeb
2
+ module Endpoints
3
+ module Parsers
4
+ class MicrosubParser < BaseParser
5
+ @identifier = :microsub
6
+
7
+ Parsers.register(self)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,18 @@
1
+ module IndieWeb
2
+ module Endpoints
3
+ module Parsers
4
+ class RedirectUriParser < BaseParser
5
+ @identifier = :redirect_uri
6
+
7
+ Parsers.register(self)
8
+
9
+ # @return [Array<String>, nil]
10
+ def results
11
+ return unless mapped_results.any?
12
+
13
+ mapped_results
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,11 @@
1
+ module IndieWeb
2
+ module Endpoints
3
+ module Parsers
4
+ class TokenEndpointParser < BaseParser
5
+ @identifier = :token_endpoint
6
+
7
+ Parsers.register(self)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,22 @@
1
+ module IndieWeb
2
+ module Endpoints
3
+ module Parsers
4
+ class WebmentionParser < BaseParser
5
+ @identifier = :webmention
6
+
7
+ Parsers.register(self)
8
+
9
+ private
10
+
11
+ def results_for_node(node)
12
+ Services::ResponseParserService.parse_body(response, self.class.identifier, node)
13
+ end
14
+
15
+ # https://www.w3.org/TR/webmention/#sender-discovers-receiver-webmention-endpoint
16
+ def results_from_body
17
+ @results_from_body ||= [results_for_node('link'), results_for_node('a')].flatten.compact
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,29 @@
1
+ module IndieWeb
2
+ module Endpoints
3
+ module Services
4
+ class ResponseParserService
5
+ # @param response [HTTP::Response]
6
+ # @param identifier [Symbol]
7
+ # @return [Array<String>]
8
+ def self.parse_body(response, identifier, node = 'link')
9
+ return unless response.mime_type == 'text/html'
10
+
11
+ # Reject endpoints that contain a fragment identifier
12
+ Nokogiri::HTML(response.body.to_s).css(%(#{node}[rel~="#{identifier}"][href]:not([href*="#"]))).map { |element| element['href'] }
13
+ end
14
+
15
+ # @param response [HTTP::Response]
16
+ # @param identifier [Symbol]
17
+ # @return [Array<String>, nil]
18
+ def self.parse_headers(response, identifier)
19
+ headers = LinkHeaderParser.parse(response.headers.get('link'), base: response.uri.to_s).group_by_relation_type[identifier]
20
+
21
+ return unless headers
22
+
23
+ # Reject endpoints that contain a fragment identifier
24
+ headers.reject { |header| Addressable::URI.parse(header.target_uri).fragment }.map(&:target_uri)
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,5 @@
1
+ module IndieWeb
2
+ module Endpoints
3
+ VERSION = '4.0.0'.freeze
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,149 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: indieweb-endpoints
3
+ version: !ruby/object:Gem::Version
4
+ version: 4.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Jason Garber
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-07-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: absolutely
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: addressable
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.7'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: http
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '4.4'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '4.4'
55
+ - !ruby/object:Gem::Dependency
56
+ name: link-header-parser
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: nokogiri
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.10'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.10'
83
+ description: Discover a URL’s IndieAuth, Micropub, Microsub, and Webmention endpoints.
84
+ email:
85
+ - jason@sixtwothree.org
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".editorconfig"
91
+ - ".github/CODEOWNERS"
92
+ - ".gitignore"
93
+ - ".reek.yml"
94
+ - ".rspec"
95
+ - ".rubocop"
96
+ - ".rubocop.yml"
97
+ - ".ruby-version"
98
+ - ".simplecov"
99
+ - ".travis.yml"
100
+ - CHANGELOG.md
101
+ - CODE_OF_CONDUCT.md
102
+ - CONTRIBUTING.md
103
+ - Gemfile
104
+ - LICENSE
105
+ - README.md
106
+ - Rakefile
107
+ - indieweb-endpoints.gemspec
108
+ - lib/indieweb/endpoints.rb
109
+ - lib/indieweb/endpoints/client.rb
110
+ - lib/indieweb/endpoints/exceptions.rb
111
+ - lib/indieweb/endpoints/parsers.rb
112
+ - lib/indieweb/endpoints/parsers/authorization_endpoint_parser.rb
113
+ - lib/indieweb/endpoints/parsers/base_parser.rb
114
+ - lib/indieweb/endpoints/parsers/micropub_parser.rb
115
+ - lib/indieweb/endpoints/parsers/microsub_parser.rb
116
+ - lib/indieweb/endpoints/parsers/redirect_uri_parser.rb
117
+ - lib/indieweb/endpoints/parsers/token_endpoint_parser.rb
118
+ - lib/indieweb/endpoints/parsers/webmention_parser.rb
119
+ - lib/indieweb/endpoints/services/response_parser_service.rb
120
+ - lib/indieweb/endpoints/version.rb
121
+ homepage: https://github.com/indieweb/indieweb-endpoints-ruby
122
+ licenses:
123
+ - MIT
124
+ metadata:
125
+ bug_tracker_uri: https://github.com/indieweb/indieweb-endpoints-ruby/issues
126
+ changelog_uri: https://github.com/indieweb/indieweb-endpoints-ruby/blob/v4.0.0/CHANGELOG.md
127
+ post_install_message:
128
+ rdoc_options: []
129
+ require_paths:
130
+ - lib
131
+ required_ruby_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '2.5'
136
+ - - "<"
137
+ - !ruby/object:Gem::Version
138
+ version: '2.8'
139
+ required_rubygems_version: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - ">="
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ requirements: []
145
+ rubygems_version: 3.1.2
146
+ signing_key:
147
+ specification_version: 4
148
+ summary: Discover a URL’s IndieAuth, Micropub, Microsub, and Webmention endpoints.
149
+ test_files: []