webmention 2.0.0 → 5.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 +4 -4
- data/.rubocop.yml +5 -5
- data/.ruby-version +1 -1
- data/.simplecov +6 -4
- data/.travis.yml +0 -1
- data/CHANGELOG.md +27 -0
- data/CONTRIBUTING.md +2 -2
- data/Gemfile +13 -0
- data/README.md +2 -2
- data/lib/webmention.rb +20 -9
- data/lib/webmention/client.rb +20 -3
- data/lib/webmention/parsers.rb +5 -23
- data/lib/webmention/parsers/base_parser.rb +27 -0
- data/lib/webmention/parsers/html_parser.rb +35 -43
- data/lib/webmention/services/http_request_service.rb +47 -0
- data/lib/webmention/version.rb +1 -1
- data/webmention.gemspec +10 -23
- metadata +16 -142
- data/lib/webmention/http_request.rb +0 -41
- data/lib/webmention/registerable.rb +0 -11
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: bdbd526bc4e17aa56447d83497ba225b902dd685581aab0934b9ef4ca4164c1e
         | 
| 4 | 
            +
              data.tar.gz: 12feb3e14687d066fada7d39ca1f6689328f2160610bac5e4301254e61afe630
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 407be30d3a706ade7b5a1bd7698aa6470e1962a657f17325b5a45356710ff67330650f9abf2923d2211eea59773d27a5140baaee7f2fd1fdd7e0da8d1ed33f13
         | 
| 7 | 
            +
              data.tar.gz: 1d5b4eb9c3b20ab8ad4fb0183482485b54dc5d1047c359e08ea6a63d9e277276b47b73ec429450c51be871046d8b1c057bbed718a286556d8566464ab3d2d8ef
         | 
    
        data/.rubocop.yml
    CHANGED
    
    | @@ -1,5 +1,10 @@ | |
| 1 1 | 
             
            require:
         | 
| 2 | 
            +
              - rubocop-minitest
         | 
| 2 3 | 
             
              - rubocop-performance
         | 
| 4 | 
            +
              - rubocop-rake
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            AllCops:
         | 
| 7 | 
            +
              NewCops: enable
         | 
| 3 8 |  | 
| 4 9 | 
             
            Layout/HashAlignment:
         | 
| 5 10 | 
             
              EnforcedColonStyle: table
         | 
| @@ -10,7 +15,6 @@ Layout/LineLength: | |
| 10 15 |  | 
| 11 16 | 
             
            Metrics/BlockLength:
         | 
| 12 17 | 
             
              Exclude:
         | 
| 13 | 
            -
                - webmention.gemspec
         | 
| 14 18 | 
             
                - test/**/*
         | 
| 15 19 |  | 
| 16 20 | 
             
            Naming/RescuedExceptionsVariableName:
         | 
| @@ -22,9 +26,5 @@ Style/Documentation: | |
| 22 26 | 
             
            Style/FrozenStringLiteralComment:
         | 
| 23 27 | 
             
              Enabled: false
         | 
| 24 28 |  | 
| 25 | 
            -
            Style/SingleLineMethods:
         | 
| 26 | 
            -
              Exclude:
         | 
| 27 | 
            -
                - test/**/*
         | 
| 28 | 
            -
             | 
| 29 29 | 
             
            Style/SymbolArray:
         | 
| 30 30 | 
             
              Enabled: false
         | 
    
        data/.ruby-version
    CHANGED
    
    | @@ -1 +1 @@ | |
| 1 | 
            -
            2. | 
| 1 | 
            +
            2.5.8
         | 
    
        data/.simplecov
    CHANGED
    
    | @@ -3,8 +3,10 @@ require 'simplecov-console' | |
| 3 3 | 
             
            SimpleCov.start do
         | 
| 4 4 | 
             
              add_filter '/test/'
         | 
| 5 5 |  | 
| 6 | 
            -
              formatter SimpleCov::Formatter::MultiFormatter.new( | 
| 7 | 
            -
                 | 
| 8 | 
            -
             | 
| 9 | 
            -
             | 
| 6 | 
            +
              formatter SimpleCov::Formatter::MultiFormatter.new(
         | 
| 7 | 
            +
                [
         | 
| 8 | 
            +
                  SimpleCov::Formatter::Console,
         | 
| 9 | 
            +
                  SimpleCov::Formatter::HTMLFormatter
         | 
| 10 | 
            +
                ]
         | 
| 11 | 
            +
              )
         | 
| 10 12 | 
             
            end
         | 
    
        data/.travis.yml
    CHANGED
    
    
    
        data/CHANGELOG.md
    CHANGED
    
    | @@ -1,5 +1,32 @@ | |
| 1 1 | 
             
            # Changelog
         | 
| 2 2 |  | 
| 3 | 
            +
            ## v5.0.0 / 2020-12-13
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            - Update absolutely and indieweb-endpoints gems to v5.0 (89f4ea8)
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            ## v4.0.0 / 2020-08-23
         | 
| 8 | 
            +
             | 
| 9 | 
            +
            - **Breaking change:** Update minimum supported Ruby version to 2.5 (b2bc62f)
         | 
| 10 | 
            +
            - Update indieweb-endpoints to 4.0 (e61588f)
         | 
| 11 | 
            +
            - Update project Ruby version to 2.5.8 (2a626a6)
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            ## v3.0.0 / 2020-05-19
         | 
| 14 | 
            +
             | 
| 15 | 
            +
            - Reject "internal" URLs when sending webmentions (#24) (ccc82c8)
         | 
| 16 | 
            +
            - Select only HTTP/HTTPS URLs when sending webmentions (#22) (39e5852)
         | 
| 17 | 
            +
             | 
| 18 | 
            +
            ## 2.2.0 / 2020-05-18
         | 
| 19 | 
            +
             | 
| 20 | 
            +
            - Update absolutely and indieweb-endpoints gems (350d2ed)
         | 
| 21 | 
            +
            - Add pry-byebug and `bin/console` script (d2c5e03)
         | 
| 22 | 
            +
            - Move development dependencies to Gemfile per current Bundler conventions (3a2fc21)
         | 
| 23 | 
            +
            - Update development Ruby version to 2.4.10 (4c7d1f7)
         | 
| 24 | 
            +
             | 
| 25 | 
            +
            ## 2.1.0 / 2020-04-06
         | 
| 26 | 
            +
             | 
| 27 | 
            +
            - Refactor `BaseParser` class and remove `Registerable` module (b706229)
         | 
| 28 | 
            +
            - Refactor `HttpRequest` and `NodeParser` classes into Service Objects (f29c073 and 7456bf1)
         | 
| 29 | 
            +
             | 
| 3 30 | 
             
            ## 2.0.0 / 2020-01-25
         | 
| 4 31 |  | 
| 5 32 | 
             
            - Add Ruby 2.7 to list of supported Ruby versions (c67ed14)
         | 
    
        data/CONTRIBUTING.md
    CHANGED
    
    | @@ -8,9 +8,9 @@ There are a couple ways you can help improve webmention-client-ruby: | |
| 8 8 |  | 
| 9 9 | 
             
            ## Getting Started
         | 
| 10 10 |  | 
| 11 | 
            -
            webmention-client-ruby is developed using Ruby 2. | 
| 11 | 
            +
            webmention-client-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.org/indieweb/webmention-client-ruby).
         | 
| 12 12 |  | 
| 13 | 
            -
            Before making changes to webmention-client-ruby, you'll want to install Ruby 2. | 
| 13 | 
            +
            Before making changes to webmention-client-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 14 |  | 
| 15 15 | 
             
            ```sh
         | 
| 16 16 | 
             
            bundle install
         | 
    
        data/Gemfile
    CHANGED
    
    | @@ -2,3 +2,16 @@ source 'https://rubygems.org' | |
| 2 2 |  | 
| 3 3 | 
             
            # Specify gem's dependencies in webmention.gemspec
         | 
| 4 4 | 
             
            gemspec
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            gem 'minitest', '~> 5.14'
         | 
| 7 | 
            +
            gem 'minitest-reporters', '~> 1.4'
         | 
| 8 | 
            +
            gem 'pry-byebug', '~> 3.9'
         | 
| 9 | 
            +
            gem 'rake', '~> 13.0'
         | 
| 10 | 
            +
            gem 'reek', '~> 6.0'
         | 
| 11 | 
            +
            gem 'rubocop', '~> 1.6'
         | 
| 12 | 
            +
            gem 'rubocop-minitest', '~> 0.10.1'
         | 
| 13 | 
            +
            gem 'rubocop-performance', '~> 1.9'
         | 
| 14 | 
            +
            gem 'rubocop-rake', '~> 0.5.1'
         | 
| 15 | 
            +
            gem 'simplecov', '~> 0.20.0'
         | 
| 16 | 
            +
            gem 'simplecov-console', '~> 0.8.0'
         | 
| 17 | 
            +
            gem 'webmock', '~> 3.10'
         | 
    
        data/README.md
    CHANGED
    
    | @@ -16,9 +16,9 @@ | |
| 16 16 |  | 
| 17 17 | 
             
            ## Getting Started
         | 
| 18 18 |  | 
| 19 | 
            -
            Before installing and using webmention-client-ruby, you'll want to have [Ruby](https://www.ruby-lang.org) 2. | 
| 19 | 
            +
            Before installing and using webmention-client-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 20 |  | 
| 21 | 
            -
            webmention-client-ruby is developed using Ruby 2. | 
| 21 | 
            +
            webmention-client-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.org/indieweb/webmention-client-ruby).
         | 
| 22 22 |  | 
| 23 23 | 
             
            ## Installation
         | 
| 24 24 |  | 
    
        data/lib/webmention.rb
    CHANGED
    
    | @@ -8,20 +8,31 @@ require 'webmention/version' | |
| 8 8 | 
             
            require 'webmention/exceptions'
         | 
| 9 9 |  | 
| 10 10 | 
             
            require 'webmention/client'
         | 
| 11 | 
            -
            require 'webmention/http_request'
         | 
| 12 | 
            -
            require 'webmention/registerable'
         | 
| 13 11 |  | 
| 14 12 | 
             
            require 'webmention/parsers'
         | 
| 13 | 
            +
            require 'webmention/parsers/base_parser'
         | 
| 15 14 | 
             
            require 'webmention/parsers/html_parser'
         | 
| 16 15 |  | 
| 16 | 
            +
            require 'webmention/services/http_request_service'
         | 
| 17 | 
            +
             | 
| 17 18 | 
             
            module Webmention
         | 
| 18 | 
            -
               | 
| 19 | 
            -
             | 
| 20 | 
            -
             | 
| 21 | 
            -
             | 
| 19 | 
            +
              # Create a new Webmention::Client
         | 
| 20 | 
            +
              # Convenience method for Webmention::Client.new
         | 
| 21 | 
            +
              #
         | 
| 22 | 
            +
              #   client = Webmention.client('https://source.example.com/post/100')
         | 
| 23 | 
            +
              #
         | 
| 24 | 
            +
              # @param source [String] An absolute URL representing the source document
         | 
| 25 | 
            +
              # @return [Webmention::Client]
         | 
| 26 | 
            +
              def self.client(source)
         | 
| 27 | 
            +
                Client.new(source)
         | 
| 28 | 
            +
              end
         | 
| 22 29 |  | 
| 23 | 
            -
             | 
| 24 | 
            -
             | 
| 25 | 
            -
             | 
| 30 | 
            +
              # Send a webmention from the source URL to the target URL
         | 
| 31 | 
            +
              #
         | 
| 32 | 
            +
              # @param source [String] An absolute URL representing the source document
         | 
| 33 | 
            +
              # @param target [String] An absolute URL representing the target document
         | 
| 34 | 
            +
              # @return [HTTP::Response, nil]
         | 
| 35 | 
            +
              def self.send_mention(source, target)
         | 
| 36 | 
            +
                client(source).send_mention(target)
         | 
| 26 37 | 
             
              end
         | 
| 27 38 | 
             
            end
         | 
    
        data/lib/webmention/client.rb
    CHANGED
    
    | @@ -1,5 +1,10 @@ | |
| 1 1 | 
             
            module Webmention
         | 
| 2 2 | 
             
              class Client
         | 
| 3 | 
            +
                # Create a new Webmention::Client
         | 
| 4 | 
            +
                #
         | 
| 5 | 
            +
                #   client = Webmention::Client.new('https://source.example.com/post/100')
         | 
| 6 | 
            +
                #
         | 
| 7 | 
            +
                # @param source [String] An absolute URL representing the source document
         | 
| 3 8 | 
             
                def initialize(source)
         | 
| 4 9 | 
             
                  raise ArgumentError, "source must be a String (given #{source.class.name})" unless source.is_a?(String)
         | 
| 5 10 |  | 
| @@ -8,22 +13,34 @@ module Webmention | |
| 8 13 | 
             
                  raise ArgumentError, 'source must be an absolute URL (e.g. https://example.com)' unless source_uri.absolute?
         | 
| 9 14 | 
             
                end
         | 
| 10 15 |  | 
| 16 | 
            +
                # Send webmentions to all mentioned URLs in this client's source document
         | 
| 17 | 
            +
                #
         | 
| 18 | 
            +
                # @return [Hash{String => HTTP::Response, nil}]
         | 
| 11 19 | 
             
                def send_all_mentions
         | 
| 12 20 | 
             
                  mentioned_urls.each_with_object({}) { |url, hash| hash[url] = send_mention(url) }
         | 
| 13 21 | 
             
                end
         | 
| 14 22 |  | 
| 23 | 
            +
                # Extract mentioned URLs from this client's source document
         | 
| 24 | 
            +
                #
         | 
| 25 | 
            +
                # @return [Array<String>]
         | 
| 26 | 
            +
                # @raise [Webmention::UnsupportedMimeTypeError]
         | 
| 15 27 | 
             
                def mentioned_urls
         | 
| 16 28 | 
             
                  raise UnsupportedMimeTypeError, "Unsupported MIME Type: #{source_response.mime_type}" unless parser_for_mime_type
         | 
| 17 29 |  | 
| 18 30 | 
             
                  @mentioned_urls ||= parser_for_mime_type.new(source_response).results
         | 
| 19 31 | 
             
                end
         | 
| 20 32 |  | 
| 33 | 
            +
                # Send a webmention from this client's source URL to the target URL
         | 
| 34 | 
            +
                #
         | 
| 35 | 
            +
                # @param target [String] An absolute URL representing the target document
         | 
| 36 | 
            +
                # @return [HTTP::Response, nil]
         | 
| 37 | 
            +
                # @raise [Webmention::ArgumentError, Webmention::ConnectionError, Webmention::InvalidURIError, Webmention::TimeoutError, Webmention::TooManyRedirectsError]
         | 
| 21 38 | 
             
                def send_mention(target)
         | 
| 22 | 
            -
                  endpoint = IndieWeb::Endpoints.get(target) | 
| 39 | 
            +
                  endpoint = IndieWeb::Endpoints.get(target)[:webmention]
         | 
| 23 40 |  | 
| 24 41 | 
             
                  return unless endpoint
         | 
| 25 42 |  | 
| 26 | 
            -
                   | 
| 43 | 
            +
                  Services::HttpRequestService.post(Addressable::URI.parse(endpoint), source: @source, target: target)
         | 
| 27 44 | 
             
                rescue IndieWeb::Endpoints::IndieWebEndpointsError => exception
         | 
| 28 45 | 
             
                  raise Webmention.const_get(exception.class.name.split('::').last), exception
         | 
| 29 46 | 
             
                end
         | 
| @@ -35,7 +52,7 @@ module Webmention | |
| 35 52 | 
             
                end
         | 
| 36 53 |  | 
| 37 54 | 
             
                def source_response
         | 
| 38 | 
            -
                  @source_response ||=  | 
| 55 | 
            +
                  @source_response ||= Services::HttpRequestService.get(source_uri)
         | 
| 39 56 | 
             
                end
         | 
| 40 57 |  | 
| 41 58 | 
             
                def source_uri
         | 
    
        data/lib/webmention/parsers.rb
    CHANGED
    
    | @@ -1,29 +1,11 @@ | |
| 1 1 | 
             
            module Webmention
         | 
| 2 2 | 
             
              module Parsers
         | 
| 3 | 
            -
                 | 
| 4 | 
            -
             | 
| 5 | 
            -
                 | 
| 6 | 
            -
                  def initialize(response)
         | 
| 7 | 
            -
                    raise ArgumentError, "response must be an HTTP::Response (given #{response.class.name})" unless response.is_a?(HTTP::Response)
         | 
| 8 | 
            -
             | 
| 9 | 
            -
                    @response = response
         | 
| 10 | 
            -
             | 
| 11 | 
            -
                    raise UnsupportedMimeTypeError, "Unsupported MIME Type: #{response.mime_type}" unless self.class.mime_types.include?(response.mime_type)
         | 
| 12 | 
            -
                  end
         | 
| 13 | 
            -
             | 
| 14 | 
            -
                  def results
         | 
| 15 | 
            -
                    @results ||= parse_response_body
         | 
| 16 | 
            -
                  end
         | 
| 17 | 
            -
             | 
| 18 | 
            -
                  private
         | 
| 19 | 
            -
             | 
| 20 | 
            -
                  def response_body
         | 
| 21 | 
            -
                    @response_body ||= @response.body.to_s
         | 
| 22 | 
            -
                  end
         | 
| 3 | 
            +
                def self.register(klass)
         | 
| 4 | 
            +
                  klass.mime_types.each { |mime_type| registered[mime_type] = klass }
         | 
| 5 | 
            +
                end
         | 
| 23 6 |  | 
| 24 | 
            -
             | 
| 25 | 
            -
             | 
| 26 | 
            -
                  end
         | 
| 7 | 
            +
                def self.registered
         | 
| 8 | 
            +
                  @registered ||= {}
         | 
| 27 9 | 
             
                end
         | 
| 28 10 | 
             
              end
         | 
| 29 11 | 
             
            end
         | 
| @@ -0,0 +1,27 @@ | |
| 1 | 
            +
            module Webmention
         | 
| 2 | 
            +
              module Parsers
         | 
| 3 | 
            +
                class BaseParser
         | 
| 4 | 
            +
                  class << self
         | 
| 5 | 
            +
                    attr_reader :mime_types
         | 
| 6 | 
            +
                  end
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                  def initialize(response)
         | 
| 9 | 
            +
                    raise ArgumentError, "response must be an HTTP::Response (given #{response.class.name})" unless response.is_a?(HTTP::Response)
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                    @response = response
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                    raise UnsupportedMimeTypeError, "Unsupported MIME Type: #{response.mime_type}" unless self.class.mime_types.include?(response.mime_type)
         | 
| 14 | 
            +
                  end
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                  private
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                  def response_body
         | 
| 19 | 
            +
                    @response_body ||= @response.body.to_s
         | 
| 20 | 
            +
                  end
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                  def response_url
         | 
| 23 | 
            +
                    @response_url ||= @response.uri.to_s
         | 
| 24 | 
            +
                  end
         | 
| 25 | 
            +
                end
         | 
| 26 | 
            +
              end
         | 
| 27 | 
            +
            end
         | 
| @@ -1,23 +1,26 @@ | |
| 1 1 | 
             
            module Webmention
         | 
| 2 2 | 
             
              module Parsers
         | 
| 3 3 | 
             
                class HtmlParser < BaseParser
         | 
| 4 | 
            -
                   | 
| 5 | 
            -
                    ['text/html']
         | 
| 6 | 
            -
                  end
         | 
| 4 | 
            +
                  @mime_types = ['text/html']
         | 
| 7 5 |  | 
| 8 6 | 
             
                  Parsers.register(self)
         | 
| 9 7 |  | 
| 10 | 
            -
                   | 
| 11 | 
            -
                    cite | 
| 12 | 
            -
                    data | 
| 13 | 
            -
                    href | 
| 14 | 
            -
                    poster | 
| 15 | 
            -
                    src | 
| 16 | 
            -
                    srcset | 
| 8 | 
            +
                  HTML_ATTRIBUTES_MAP = {
         | 
| 9 | 
            +
                    'cite'   => %w[blockquote del ins q],
         | 
| 10 | 
            +
                    'data'   => %w[object],
         | 
| 11 | 
            +
                    'href'   => %w[a area],
         | 
| 12 | 
            +
                    'poster' => %w[video],
         | 
| 13 | 
            +
                    'src'    => %w[audio embed img source track video],
         | 
| 14 | 
            +
                    'srcset' => %w[img source]
         | 
| 17 15 | 
             
                  }.freeze
         | 
| 18 16 |  | 
| 19 | 
            -
                   | 
| 20 | 
            -
             | 
| 17 | 
            +
                  CSS_SELECTORS_ARRAY = HTML_ATTRIBUTES_MAP.flat_map { |attribute, names| names.map { |name| "#{name}[#{attribute}]" } }.freeze
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                  # Parse an HTML string for URLs
         | 
| 20 | 
            +
                  #
         | 
| 21 | 
            +
                  # @return [Array<String>] Unique external URLs whose scheme matches http/https
         | 
| 22 | 
            +
                  def results
         | 
| 23 | 
            +
                    @results ||= resolved_urls.uniq.select { |url| url.match?(%r{https?://}) }.reject { |url| url.match(/^#{response_url}(?:#.*)?$/) }
         | 
| 21 24 | 
             
                  end
         | 
| 22 25 |  | 
| 23 26 | 
             
                  private
         | 
| @@ -26,46 +29,35 @@ module Webmention | |
| 26 29 | 
             
                    @doc ||= Nokogiri::HTML(response_body)
         | 
| 27 30 | 
             
                  end
         | 
| 28 31 |  | 
| 29 | 
            -
                   | 
| 30 | 
            -
             | 
| 31 | 
            -
                  # @return [Array] the URLs
         | 
| 32 | 
            -
                  def parse_response_body
         | 
| 33 | 
            -
                    CSS_SELECTORS_MAP
         | 
| 34 | 
            -
                      .each_with_object([]) { |(*args), array| array << search_node(*args) }
         | 
| 35 | 
            -
                      .flatten
         | 
| 36 | 
            -
                      .map { |url| Absolutely.to_abs(base: response_url, relative: url) }
         | 
| 37 | 
            -
                      .uniq
         | 
| 32 | 
            +
                  def resolved_urls
         | 
| 33 | 
            +
                    UrlAttributesParser.parse(*url_attributes).map { |url| Absolutely.to_abs(base: response_url, relative: url) }
         | 
| 38 34 | 
             
                  end
         | 
| 39 35 |  | 
| 40 36 | 
             
                  def root_node
         | 
| 41 | 
            -
                     | 
| 37 | 
            +
                    doc.at_css('.h-entry .e-content', '.h-entry') || doc.css('body')
         | 
| 38 | 
            +
                  end
         | 
| 39 | 
            +
             | 
| 40 | 
            +
                  def url_attributes
         | 
| 41 | 
            +
                    url_nodes.flat_map(&:attribute_nodes).select { |attribute| HTML_ATTRIBUTES_MAP.key?(attribute.name) }
         | 
| 42 42 | 
             
                  end
         | 
| 43 43 |  | 
| 44 | 
            -
                  def  | 
| 45 | 
            -
                     | 
| 44 | 
            +
                  def url_nodes
         | 
| 45 | 
            +
                    root_node.css(*CSS_SELECTORS_ARRAY)
         | 
| 46 46 | 
             
                  end
         | 
| 47 47 |  | 
| 48 | 
            -
                  module  | 
| 49 | 
            -
                     | 
| 50 | 
            -
             | 
| 51 | 
            -
             | 
| 52 | 
            -
                       | 
| 53 | 
            -
             | 
| 54 | 
            -
                      # @return [Nokogiri::XML::NodeSet]
         | 
| 55 | 
            -
                      def nodes_from(node, selectors)
         | 
| 56 | 
            -
                        node.css(*selectors)
         | 
| 57 | 
            -
                      end
         | 
| 48 | 
            +
                  module UrlAttributesParser
         | 
| 49 | 
            +
                    # @param attributes [Array<Nokogiri::XML::Attr>]
         | 
| 50 | 
            +
                    # @return [Array<String>]
         | 
| 51 | 
            +
                    def self.parse(*attributes)
         | 
| 52 | 
            +
                      attributes.flat_map { |attribute| value_from(attribute) }
         | 
| 53 | 
            +
                    end
         | 
| 58 54 |  | 
| 59 | 
            -
             | 
| 60 | 
            -
             | 
| 61 | 
            -
             | 
| 62 | 
            -
                       | 
| 63 | 
            -
                      # @return [Array] the HTML attribute values
         | 
| 64 | 
            -
                      def values_from(node, attribute)
         | 
| 65 | 
            -
                        return Array(node[attribute]) unless attribute == :srcset
         | 
| 55 | 
            +
                    # @param attribute [Nokogiri::XML::Attr]
         | 
| 56 | 
            +
                    # @return [String, Array<String>]
         | 
| 57 | 
            +
                    def self.value_from(attribute)
         | 
| 58 | 
            +
                      return attribute.value unless attribute.name == 'srcset'
         | 
| 66 59 |  | 
| 67 | 
            -
             | 
| 68 | 
            -
                      end
         | 
| 60 | 
            +
                      attribute.value.split(',').map { |value| value.strip.match(/^\S+/).to_s }
         | 
| 69 61 | 
             
                    end
         | 
| 70 62 | 
             
                  end
         | 
| 71 63 | 
             
                end
         | 
| @@ -0,0 +1,47 @@ | |
| 1 | 
            +
            module Webmention
         | 
| 2 | 
            +
              module Services
         | 
| 3 | 
            +
                module HttpRequestService
         | 
| 4 | 
            +
                  # Defaults derived from Webmention specification examples
         | 
| 5 | 
            +
                  # https://www.w3.org/TR/webmention/#limits-on-get-requests
         | 
| 6 | 
            +
                  # rubocop:disable Layout/HashAlignment
         | 
| 7 | 
            +
                  HTTP_CLIENT_OPTS = {
         | 
| 8 | 
            +
                    follow: {
         | 
| 9 | 
            +
                      max_hops: 20
         | 
| 10 | 
            +
                    },
         | 
| 11 | 
            +
                    headers: {
         | 
| 12 | 
            +
                      accept: '*/*',
         | 
| 13 | 
            +
                      user_agent: 'Webmention Client (https://rubygems.org/gems/webmention)'
         | 
| 14 | 
            +
                    },
         | 
| 15 | 
            +
                    timeout_options: {
         | 
| 16 | 
            +
                      connect_timeout: 5,
         | 
| 17 | 
            +
                      read_timeout: 5
         | 
| 18 | 
            +
                    }
         | 
| 19 | 
            +
                  }.freeze
         | 
| 20 | 
            +
                  # rubocop:enable Layout/HashAlignment
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                  class << self
         | 
| 23 | 
            +
                    def get(uri)
         | 
| 24 | 
            +
                      request(:get, uri)
         | 
| 25 | 
            +
                    end
         | 
| 26 | 
            +
             | 
| 27 | 
            +
                    def post(uri, **options)
         | 
| 28 | 
            +
                      request(:post, uri, form: options)
         | 
| 29 | 
            +
                    end
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                    private
         | 
| 32 | 
            +
             | 
| 33 | 
            +
                    def client
         | 
| 34 | 
            +
                      @client ||= HTTP::Client.new(HTTP_CLIENT_OPTS)
         | 
| 35 | 
            +
                    end
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                    def request(method, uri, **options)
         | 
| 38 | 
            +
                      client.request(method, uri, options)
         | 
| 39 | 
            +
                    rescue HTTP::ConnectionError,
         | 
| 40 | 
            +
                           HTTP::TimeoutError,
         | 
| 41 | 
            +
                           HTTP::Redirector::TooManyRedirectsError => exception
         | 
| 42 | 
            +
                      raise Webmention.const_get(exception.class.name.split('::').last), exception
         | 
| 43 | 
            +
                    end
         | 
| 44 | 
            +
                  end
         | 
| 45 | 
            +
                end
         | 
| 46 | 
            +
              end
         | 
| 47 | 
            +
            end
         | 
    
        data/lib/webmention/version.rb
    CHANGED
    
    
    
        data/webmention.gemspec
    CHANGED
    
    | @@ -1,10 +1,7 @@ | |
| 1 | 
            -
             | 
| 2 | 
            -
            $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
         | 
| 3 | 
            -
             | 
| 4 | 
            -
            require 'webmention/version'
         | 
| 1 | 
            +
            require_relative 'lib/webmention/version'
         | 
| 5 2 |  | 
| 6 3 | 
             
            Gem::Specification.new do |spec|
         | 
| 7 | 
            -
              spec.required_ruby_version =  | 
| 4 | 
            +
              spec.required_ruby_version = Gem::Requirement.new('>= 2.5', '< 2.8')
         | 
| 8 5 |  | 
| 9 6 | 
             
              spec.name          = 'webmention'
         | 
| 10 7 | 
             
              spec.version       = Webmention::VERSION
         | 
| @@ -16,28 +13,18 @@ Gem::Specification.new do |spec| | |
| 16 13 | 
             
              spec.homepage      = 'https://github.com/indieweb/webmention-client-ruby'
         | 
| 17 14 | 
             
              spec.license       = 'Apache-2.0'
         | 
| 18 15 |  | 
| 19 | 
            -
              spec.files         =  | 
| 16 | 
            +
              spec.files         = Dir.chdir(File.expand_path(__dir__)) do
         | 
| 17 | 
            +
                `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(bin|test)/}) }
         | 
| 18 | 
            +
              end
         | 
| 20 19 |  | 
| 21 20 | 
             
              spec.require_paths = ['lib']
         | 
| 22 21 |  | 
| 23 | 
            -
              spec.metadata = {
         | 
| 24 | 
            -
             | 
| 25 | 
            -
                'changelog_uri'   => "#{spec.homepage}/blob/v#{spec.version}/CHANGELOG.md"
         | 
| 26 | 
            -
              }
         | 
| 27 | 
            -
             | 
| 28 | 
            -
              spec.add_development_dependency 'minitest', '~> 5.14'
         | 
| 29 | 
            -
              spec.add_development_dependency 'minitest-reporters', '~> 1.4'
         | 
| 30 | 
            -
              spec.add_development_dependency 'rake', '~> 13.0'
         | 
| 31 | 
            -
              spec.add_development_dependency 'reek', '~> 5.6'
         | 
| 32 | 
            -
              spec.add_development_dependency 'rubocop', '~> 0.79.0'
         | 
| 33 | 
            -
              spec.add_development_dependency 'rubocop-performance', '~> 1.5'
         | 
| 34 | 
            -
              spec.add_development_dependency 'simplecov', '~> 0.17.1'
         | 
| 35 | 
            -
              spec.add_development_dependency 'simplecov-console', '~> 0.6.0'
         | 
| 36 | 
            -
              spec.add_development_dependency 'webmock', '~> 3.8'
         | 
| 22 | 
            +
              spec.metadata['bug_tracker_uri'] = "#{spec.homepage}/issues"
         | 
| 23 | 
            +
              spec.metadata['changelog_uri']   = "#{spec.homepage}/blob/v#{spec.version}/CHANGELOG.md"
         | 
| 37 24 |  | 
| 38 | 
            -
              spec.add_runtime_dependency 'absolutely', '~>  | 
| 25 | 
            +
              spec.add_runtime_dependency 'absolutely', '~> 5.0'
         | 
| 39 26 | 
             
              spec.add_runtime_dependency 'addressable', '~> 2.7'
         | 
| 40 | 
            -
              spec.add_runtime_dependency 'http', '~> 4. | 
| 41 | 
            -
              spec.add_runtime_dependency 'indieweb-endpoints', '~>  | 
| 27 | 
            +
              spec.add_runtime_dependency 'http', '~> 4.4'
         | 
| 28 | 
            +
              spec.add_runtime_dependency 'indieweb-endpoints', '~> 5.0'
         | 
| 42 29 | 
             
              spec.add_runtime_dependency 'nokogiri', '~> 1.10'
         | 
| 43 30 | 
             
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,156 +1,30 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: webmention
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version:  | 
| 4 | 
            +
              version: 5.0.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Aaron Parecki
         | 
| 8 8 | 
             
            - Nat Welch
         | 
| 9 | 
            -
            autorequire: | 
| 9 | 
            +
            autorequire:
         | 
| 10 10 | 
             
            bindir: bin
         | 
| 11 11 | 
             
            cert_chain: []
         | 
| 12 | 
            -
            date: 2020- | 
| 12 | 
            +
            date: 2020-12-14 00:00:00.000000000 Z
         | 
| 13 13 | 
             
            dependencies:
         | 
| 14 | 
            -
            - !ruby/object:Gem::Dependency
         | 
| 15 | 
            -
              name: minitest
         | 
| 16 | 
            -
              requirement: !ruby/object:Gem::Requirement
         | 
| 17 | 
            -
                requirements:
         | 
| 18 | 
            -
                - - "~>"
         | 
| 19 | 
            -
                  - !ruby/object:Gem::Version
         | 
| 20 | 
            -
                    version: '5.14'
         | 
| 21 | 
            -
              type: :development
         | 
| 22 | 
            -
              prerelease: false
         | 
| 23 | 
            -
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 24 | 
            -
                requirements:
         | 
| 25 | 
            -
                - - "~>"
         | 
| 26 | 
            -
                  - !ruby/object:Gem::Version
         | 
| 27 | 
            -
                    version: '5.14'
         | 
| 28 | 
            -
            - !ruby/object:Gem::Dependency
         | 
| 29 | 
            -
              name: minitest-reporters
         | 
| 30 | 
            -
              requirement: !ruby/object:Gem::Requirement
         | 
| 31 | 
            -
                requirements:
         | 
| 32 | 
            -
                - - "~>"
         | 
| 33 | 
            -
                  - !ruby/object:Gem::Version
         | 
| 34 | 
            -
                    version: '1.4'
         | 
| 35 | 
            -
              type: :development
         | 
| 36 | 
            -
              prerelease: false
         | 
| 37 | 
            -
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 38 | 
            -
                requirements:
         | 
| 39 | 
            -
                - - "~>"
         | 
| 40 | 
            -
                  - !ruby/object:Gem::Version
         | 
| 41 | 
            -
                    version: '1.4'
         | 
| 42 | 
            -
            - !ruby/object:Gem::Dependency
         | 
| 43 | 
            -
              name: rake
         | 
| 44 | 
            -
              requirement: !ruby/object:Gem::Requirement
         | 
| 45 | 
            -
                requirements:
         | 
| 46 | 
            -
                - - "~>"
         | 
| 47 | 
            -
                  - !ruby/object:Gem::Version
         | 
| 48 | 
            -
                    version: '13.0'
         | 
| 49 | 
            -
              type: :development
         | 
| 50 | 
            -
              prerelease: false
         | 
| 51 | 
            -
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 52 | 
            -
                requirements:
         | 
| 53 | 
            -
                - - "~>"
         | 
| 54 | 
            -
                  - !ruby/object:Gem::Version
         | 
| 55 | 
            -
                    version: '13.0'
         | 
| 56 | 
            -
            - !ruby/object:Gem::Dependency
         | 
| 57 | 
            -
              name: reek
         | 
| 58 | 
            -
              requirement: !ruby/object:Gem::Requirement
         | 
| 59 | 
            -
                requirements:
         | 
| 60 | 
            -
                - - "~>"
         | 
| 61 | 
            -
                  - !ruby/object:Gem::Version
         | 
| 62 | 
            -
                    version: '5.6'
         | 
| 63 | 
            -
              type: :development
         | 
| 64 | 
            -
              prerelease: false
         | 
| 65 | 
            -
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 66 | 
            -
                requirements:
         | 
| 67 | 
            -
                - - "~>"
         | 
| 68 | 
            -
                  - !ruby/object:Gem::Version
         | 
| 69 | 
            -
                    version: '5.6'
         | 
| 70 | 
            -
            - !ruby/object:Gem::Dependency
         | 
| 71 | 
            -
              name: rubocop
         | 
| 72 | 
            -
              requirement: !ruby/object:Gem::Requirement
         | 
| 73 | 
            -
                requirements:
         | 
| 74 | 
            -
                - - "~>"
         | 
| 75 | 
            -
                  - !ruby/object:Gem::Version
         | 
| 76 | 
            -
                    version: 0.79.0
         | 
| 77 | 
            -
              type: :development
         | 
| 78 | 
            -
              prerelease: false
         | 
| 79 | 
            -
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 80 | 
            -
                requirements:
         | 
| 81 | 
            -
                - - "~>"
         | 
| 82 | 
            -
                  - !ruby/object:Gem::Version
         | 
| 83 | 
            -
                    version: 0.79.0
         | 
| 84 | 
            -
            - !ruby/object:Gem::Dependency
         | 
| 85 | 
            -
              name: rubocop-performance
         | 
| 86 | 
            -
              requirement: !ruby/object:Gem::Requirement
         | 
| 87 | 
            -
                requirements:
         | 
| 88 | 
            -
                - - "~>"
         | 
| 89 | 
            -
                  - !ruby/object:Gem::Version
         | 
| 90 | 
            -
                    version: '1.5'
         | 
| 91 | 
            -
              type: :development
         | 
| 92 | 
            -
              prerelease: false
         | 
| 93 | 
            -
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 94 | 
            -
                requirements:
         | 
| 95 | 
            -
                - - "~>"
         | 
| 96 | 
            -
                  - !ruby/object:Gem::Version
         | 
| 97 | 
            -
                    version: '1.5'
         | 
| 98 | 
            -
            - !ruby/object:Gem::Dependency
         | 
| 99 | 
            -
              name: simplecov
         | 
| 100 | 
            -
              requirement: !ruby/object:Gem::Requirement
         | 
| 101 | 
            -
                requirements:
         | 
| 102 | 
            -
                - - "~>"
         | 
| 103 | 
            -
                  - !ruby/object:Gem::Version
         | 
| 104 | 
            -
                    version: 0.17.1
         | 
| 105 | 
            -
              type: :development
         | 
| 106 | 
            -
              prerelease: false
         | 
| 107 | 
            -
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 108 | 
            -
                requirements:
         | 
| 109 | 
            -
                - - "~>"
         | 
| 110 | 
            -
                  - !ruby/object:Gem::Version
         | 
| 111 | 
            -
                    version: 0.17.1
         | 
| 112 | 
            -
            - !ruby/object:Gem::Dependency
         | 
| 113 | 
            -
              name: simplecov-console
         | 
| 114 | 
            -
              requirement: !ruby/object:Gem::Requirement
         | 
| 115 | 
            -
                requirements:
         | 
| 116 | 
            -
                - - "~>"
         | 
| 117 | 
            -
                  - !ruby/object:Gem::Version
         | 
| 118 | 
            -
                    version: 0.6.0
         | 
| 119 | 
            -
              type: :development
         | 
| 120 | 
            -
              prerelease: false
         | 
| 121 | 
            -
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 122 | 
            -
                requirements:
         | 
| 123 | 
            -
                - - "~>"
         | 
| 124 | 
            -
                  - !ruby/object:Gem::Version
         | 
| 125 | 
            -
                    version: 0.6.0
         | 
| 126 | 
            -
            - !ruby/object:Gem::Dependency
         | 
| 127 | 
            -
              name: webmock
         | 
| 128 | 
            -
              requirement: !ruby/object:Gem::Requirement
         | 
| 129 | 
            -
                requirements:
         | 
| 130 | 
            -
                - - "~>"
         | 
| 131 | 
            -
                  - !ruby/object:Gem::Version
         | 
| 132 | 
            -
                    version: '3.8'
         | 
| 133 | 
            -
              type: :development
         | 
| 134 | 
            -
              prerelease: false
         | 
| 135 | 
            -
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 136 | 
            -
                requirements:
         | 
| 137 | 
            -
                - - "~>"
         | 
| 138 | 
            -
                  - !ruby/object:Gem::Version
         | 
| 139 | 
            -
                    version: '3.8'
         | 
| 140 14 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 141 15 | 
             
              name: absolutely
         | 
| 142 16 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 143 17 | 
             
                requirements:
         | 
| 144 18 | 
             
                - - "~>"
         | 
| 145 19 | 
             
                  - !ruby/object:Gem::Version
         | 
| 146 | 
            -
                    version: ' | 
| 20 | 
            +
                    version: '5.0'
         | 
| 147 21 | 
             
              type: :runtime
         | 
| 148 22 | 
             
              prerelease: false
         | 
| 149 23 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 150 24 | 
             
                requirements:
         | 
| 151 25 | 
             
                - - "~>"
         | 
| 152 26 | 
             
                  - !ruby/object:Gem::Version
         | 
| 153 | 
            -
                    version: ' | 
| 27 | 
            +
                    version: '5.0'
         | 
| 154 28 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 155 29 | 
             
              name: addressable
         | 
| 156 30 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| @@ -171,28 +45,28 @@ dependencies: | |
| 171 45 | 
             
                requirements:
         | 
| 172 46 | 
             
                - - "~>"
         | 
| 173 47 | 
             
                  - !ruby/object:Gem::Version
         | 
| 174 | 
            -
                    version: '4. | 
| 48 | 
            +
                    version: '4.4'
         | 
| 175 49 | 
             
              type: :runtime
         | 
| 176 50 | 
             
              prerelease: false
         | 
| 177 51 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 178 52 | 
             
                requirements:
         | 
| 179 53 | 
             
                - - "~>"
         | 
| 180 54 | 
             
                  - !ruby/object:Gem::Version
         | 
| 181 | 
            -
                    version: '4. | 
| 55 | 
            +
                    version: '4.4'
         | 
| 182 56 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 183 57 | 
             
              name: indieweb-endpoints
         | 
| 184 58 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 185 59 | 
             
                requirements:
         | 
| 186 60 | 
             
                - - "~>"
         | 
| 187 61 | 
             
                  - !ruby/object:Gem::Version
         | 
| 188 | 
            -
                    version: ' | 
| 62 | 
            +
                    version: '5.0'
         | 
| 189 63 | 
             
              type: :runtime
         | 
| 190 64 | 
             
              prerelease: false
         | 
| 191 65 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 192 66 | 
             
                requirements:
         | 
| 193 67 | 
             
                - - "~>"
         | 
| 194 68 | 
             
                  - !ruby/object:Gem::Version
         | 
| 195 | 
            -
                    version: ' | 
| 69 | 
            +
                    version: '5.0'
         | 
| 196 70 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 197 71 | 
             
              name: nokogiri
         | 
| 198 72 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| @@ -231,10 +105,10 @@ files: | |
| 231 105 | 
             
            - lib/webmention.rb
         | 
| 232 106 | 
             
            - lib/webmention/client.rb
         | 
| 233 107 | 
             
            - lib/webmention/exceptions.rb
         | 
| 234 | 
            -
            - lib/webmention/http_request.rb
         | 
| 235 108 | 
             
            - lib/webmention/parsers.rb
         | 
| 109 | 
            +
            - lib/webmention/parsers/base_parser.rb
         | 
| 236 110 | 
             
            - lib/webmention/parsers/html_parser.rb
         | 
| 237 | 
            -
            - lib/webmention/ | 
| 111 | 
            +
            - lib/webmention/services/http_request_service.rb
         | 
| 238 112 | 
             
            - lib/webmention/version.rb
         | 
| 239 113 | 
             
            - webmention.gemspec
         | 
| 240 114 | 
             
            homepage: https://github.com/indieweb/webmention-client-ruby
         | 
| @@ -242,8 +116,8 @@ licenses: | |
| 242 116 | 
             
            - Apache-2.0
         | 
| 243 117 | 
             
            metadata:
         | 
| 244 118 | 
             
              bug_tracker_uri: https://github.com/indieweb/webmention-client-ruby/issues
         | 
| 245 | 
            -
              changelog_uri: https://github.com/indieweb/webmention-client-ruby/blob/ | 
| 246 | 
            -
            post_install_message: | 
| 119 | 
            +
              changelog_uri: https://github.com/indieweb/webmention-client-ruby/blob/v5.0.0/CHANGELOG.md
         | 
| 120 | 
            +
            post_install_message:
         | 
| 247 121 | 
             
            rdoc_options: []
         | 
| 248 122 | 
             
            require_paths:
         | 
| 249 123 | 
             
            - lib
         | 
| @@ -251,7 +125,7 @@ required_ruby_version: !ruby/object:Gem::Requirement | |
| 251 125 | 
             
              requirements:
         | 
| 252 126 | 
             
              - - ">="
         | 
| 253 127 | 
             
                - !ruby/object:Gem::Version
         | 
| 254 | 
            -
                  version: '2. | 
| 128 | 
            +
                  version: '2.5'
         | 
| 255 129 | 
             
              - - "<"
         | 
| 256 130 | 
             
                - !ruby/object:Gem::Version
         | 
| 257 131 | 
             
                  version: '2.8'
         | 
| @@ -261,8 +135,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 261 135 | 
             
                - !ruby/object:Gem::Version
         | 
| 262 136 | 
             
                  version: '0'
         | 
| 263 137 | 
             
            requirements: []
         | 
| 264 | 
            -
            rubygems_version: 3. | 
| 265 | 
            -
            signing_key: | 
| 138 | 
            +
            rubygems_version: 3.1.2
         | 
| 139 | 
            +
            signing_key:
         | 
| 266 140 | 
             
            specification_version: 4
         | 
| 267 141 | 
             
            summary: Webmention notification client
         | 
| 268 142 | 
             
            test_files: []
         | 
| @@ -1,41 +0,0 @@ | |
| 1 | 
            -
            module Webmention
         | 
| 2 | 
            -
              class HttpRequest
         | 
| 3 | 
            -
                # Defaults derived from Webmention specification examples
         | 
| 4 | 
            -
                # https://www.w3.org/TR/webmention/#limits-on-get-requests
         | 
| 5 | 
            -
                # rubocop:disable Layout/HashAlignment
         | 
| 6 | 
            -
                HTTP_CLIENT_OPTS = {
         | 
| 7 | 
            -
                  follow: {
         | 
| 8 | 
            -
                    max_hops: 20
         | 
| 9 | 
            -
                  },
         | 
| 10 | 
            -
                  headers: {
         | 
| 11 | 
            -
                    accept: '*/*',
         | 
| 12 | 
            -
                    user_agent: 'Webmention Client (https://rubygems.org/gems/webmention)'
         | 
| 13 | 
            -
                  },
         | 
| 14 | 
            -
                  timeout_options: {
         | 
| 15 | 
            -
                    connect_timeout: 5,
         | 
| 16 | 
            -
                    read_timeout: 5
         | 
| 17 | 
            -
                  }
         | 
| 18 | 
            -
                }.freeze
         | 
| 19 | 
            -
                # rubocop:enable Layout/HashAlignment
         | 
| 20 | 
            -
             | 
| 21 | 
            -
                class << self
         | 
| 22 | 
            -
                  def get(uri)
         | 
| 23 | 
            -
                    request(:get, uri)
         | 
| 24 | 
            -
                  end
         | 
| 25 | 
            -
             | 
| 26 | 
            -
                  def post(uri, **options)
         | 
| 27 | 
            -
                    request(:post, uri, form: options)
         | 
| 28 | 
            -
                  end
         | 
| 29 | 
            -
             | 
| 30 | 
            -
                  private
         | 
| 31 | 
            -
             | 
| 32 | 
            -
                  def request(method, uri, **options)
         | 
| 33 | 
            -
                    HTTP::Client.new(HTTP_CLIENT_OPTS).request(method, uri, options)
         | 
| 34 | 
            -
                  rescue HTTP::ConnectionError,
         | 
| 35 | 
            -
                         HTTP::TimeoutError,
         | 
| 36 | 
            -
                         HTTP::Redirector::TooManyRedirectsError => exception
         | 
| 37 | 
            -
                    raise Webmention.const_get(exception.class.name.split('::').last), exception
         | 
| 38 | 
            -
                  end
         | 
| 39 | 
            -
                end
         | 
| 40 | 
            -
              end
         | 
| 41 | 
            -
            end
         |