indieweb-endpoints 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8ea000fd8ce1b67e86979bf4e7b15a92fdadbf6c06930c1592a9bc9004a709f8
4
- data.tar.gz: 61065c74af761a2284a4df12ca9ace1eff6e0d73880139ecc88a7c5ab0d60c22
3
+ metadata.gz: 2168f56d7a493faa4d1bd7a61e5ecc1cf52ca405baf43254ad3149fa6ad62460
4
+ data.tar.gz: 93c838259316804108f5a5b9c9950235f9283c08109aa1b1c2eb9f89c6d3eac2
5
5
  SHA512:
6
- metadata.gz: a168817ddd7650e4e7bf54e2029427d70e682027f72658607c9c710bbc4646e7438f6b92f36b4a2b758ab1882220b0ea38a36d59e0ac80a3b595e016d0c0218a
7
- data.tar.gz: 97ca5850e60dbb0a1509809cd2982ec8eea9d3158e15dcfaaf3279eb92509eb738e76bbbdd007a9d925a3879b05ef3b4801932bb284c2d288894a20e00776ad1
6
+ metadata.gz: a685fc02841e5433b183103679df93b9e6d2b0c530a0d6b3b8acf01adb41d17814a2778ac74ec876b3b70671ebbbfe76edcd414f1c6f8195838834d62d826b15
7
+ data.tar.gz: fbb870ada2afdb2b5b217fa224a6e43166e6faed8aa422d6e26c9cbd2375a2313ead2db29ec2e1d703423b856a6b80768d69100737c5a3709b8297a615b980f2
data/.reek.yml CHANGED
@@ -1,9 +1,6 @@
1
1
  detectors:
2
2
  IrresponsibleModule:
3
3
  enabled: false
4
- TooManyStatements:
5
- exclude:
6
- - IndieWeb::Endpoints::Client#response
7
4
  UtilityFunction:
8
5
  exclude:
9
6
  - FixtureHelpers#read_fixture
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.2.0 / 2019-04-25
4
+
5
+ - Subclass exceptions under `IndieWeb::Endpoints::Error` ([667eec7](https://github.com/indieweb/indieweb-endpoints-ruby/commit/667eec7)).
6
+ - Refactor parsers and `Registerable` module ([3b96858](https://github.com/indieweb/indieweb-endpoints-ruby/commit/3b96858)).
7
+ - Refactor Client#response method ([c36fda3](https://github.com/indieweb/indieweb-endpoints-ruby/commit/c36fda3)).
8
+
3
9
  ## 0.1.0 / 2019-04-24
4
10
 
5
11
  - Initial release!
data/README.md CHANGED
@@ -79,7 +79,7 @@ puts client.endpoints # => Hash
79
79
 
80
80
  ### Exception Handling
81
81
 
82
- There are several exceptions that may be raised by indieweb-endpoints-ruby's underlying dependencies. These errors are raised as subclasses of `StandardError`.
82
+ There are several exceptions that may be raised by indieweb-endpoints-ruby's underlying dependencies. These errors are raised as subclasses of `IndieWeb::Endpoints::Error` (which itself is a subclass of `StandardError`).
83
83
 
84
84
  From [jgarber623/absolutely](https://github.com/jgarber623/absolutely) and [sporkmonger/addressable](https://github.com/sporkmonger/addressable):
85
85
 
@@ -21,16 +21,11 @@ module IndieWeb
21
21
  end
22
22
 
23
23
  def response
24
- @response ||= HTTP.follow.headers(HTTP_HEADERS_OPTS).timeout(
25
- connect: 10,
26
- read: 10
27
- ).get(@url)
28
- rescue HTTP::ConnectionError => exception
29
- raise ConnectionError, exception
30
- rescue HTTP::TimeoutError => exception
31
- raise TimeoutError, exception
32
- rescue HTTP::Redirector::TooManyRedirectsError => exception
33
- raise TooManyRedirectsError, exception
24
+ @response ||= HTTP.follow.headers(HTTP_HEADERS_OPTS).timeout(connect: 10, read: 10).get(@url)
25
+ rescue HTTP::ConnectionError,
26
+ HTTP::TimeoutError,
27
+ HTTP::Redirector::TooManyRedirectsError => exception
28
+ raise IndieWeb::Endpoints.const_get(exception.class.name.split('::').last), exception
34
29
  end
35
30
  end
36
31
  end
@@ -1,13 +1,15 @@
1
1
  module IndieWeb
2
2
  module Endpoints
3
- class ArgumentError < StandardError; end
3
+ class Error < StandardError; end
4
4
 
5
- class ConnectionError < StandardError; end
5
+ class ArgumentError < Error; end
6
6
 
7
- class InvalidURIError < StandardError; end
7
+ class ConnectionError < Error; end
8
8
 
9
- class TimeoutError < StandardError; end
9
+ class InvalidURIError < Error; end
10
10
 
11
- class TooManyRedirectsError < StandardError; end
11
+ class TimeoutError < Error; end
12
+
13
+ class TooManyRedirectsError < Error; end
12
14
  end
13
15
  end
@@ -50,7 +50,7 @@ module IndieWeb
50
50
  end
51
51
 
52
52
  def link_elements_css_selector
53
- @link_elements_css_selector ||= %(link[rel~="#{identifier}"][href])
53
+ @link_elements_css_selector ||= %(link[rel~="#{self.class.identifier}"][href])
54
54
  end
55
55
 
56
56
  def link_header
@@ -65,7 +65,7 @@ module IndieWeb
65
65
  def regexp_rel_paramater_pattern
66
66
  # Ultra-orthodox pattern matching Link header `rel` parameter including a matching identifier value
67
67
  # https://www.w3.org/TR/webmention/#sender-discovers-receiver-webmention-endpoint
68
- @regexp_rel_paramater_pattern ||= /(?:;|\s)rel="?(?:#{REGEXP_REG_REL_TYPE_PATTERN}+\s)?#{identifier}(?:\s#{REGEXP_REG_REL_TYPE_PATTERN})?"?/
68
+ @regexp_rel_paramater_pattern ||= /(?:;|\s)rel="?(?:#{REGEXP_REG_REL_TYPE_PATTERN}+\s)?#{self.class.identifier}(?:\s#{REGEXP_REG_REL_TYPE_PATTERN})?"?/
69
69
  end
70
70
 
71
71
  def results_from_body
@@ -2,13 +2,11 @@ module IndieWeb
2
2
  module Endpoints
3
3
  module Parsers
4
4
  class AuthorizationEndpointParser < BaseParser
5
- Parsers.register(:authorization_endpoint, self)
6
-
7
- private
8
-
9
- def identifier
10
- @identifier ||= :authorization_endpoint
5
+ def self.identifier
6
+ :authorization_endpoint
11
7
  end
8
+
9
+ Parsers.register(self)
12
10
  end
13
11
  end
14
12
  end
@@ -2,13 +2,11 @@ module IndieWeb
2
2
  module Endpoints
3
3
  module Parsers
4
4
  class MicropubParser < BaseParser
5
- Parsers.register(:micropub, self)
6
-
7
- private
8
-
9
- def identifier
10
- @identifier ||= :micropub
5
+ def self.identifier
6
+ :micropub
11
7
  end
8
+
9
+ Parsers.register(self)
12
10
  end
13
11
  end
14
12
  end
@@ -2,7 +2,11 @@ module IndieWeb
2
2
  module Endpoints
3
3
  module Parsers
4
4
  class RedirectUriParser < BaseParser
5
- Parsers.register(:redirect_uri, self)
5
+ def self.identifier
6
+ :redirect_uri
7
+ end
8
+
9
+ Parsers.register(self)
6
10
 
7
11
  def results
8
12
  return unless results_from_http_request.any?
@@ -14,10 +18,6 @@ module IndieWeb
14
18
 
15
19
  private
16
20
 
17
- def identifier
18
- @identifier ||= :redirect_uri
19
- end
20
-
21
21
  def results_from_body
22
22
  link_elements.map { |element| element['href'] } if response_is_html && link_elements.any?
23
23
  end
@@ -2,13 +2,11 @@ module IndieWeb
2
2
  module Endpoints
3
3
  module Parsers
4
4
  class TokenEndpointParser < BaseParser
5
- Parsers.register(:token_endpoint, self)
6
-
7
- private
8
-
9
- def identifier
10
- @identifier ||= :token_endpoint
5
+ def self.identifier
6
+ :token_endpoint
11
7
  end
8
+
9
+ Parsers.register(self)
12
10
  end
13
11
  end
14
12
  end
@@ -2,13 +2,13 @@ module IndieWeb
2
2
  module Endpoints
3
3
  module Parsers
4
4
  class WebmentionParser < BaseParser
5
- Parsers.register(:webmention, self)
5
+ def self.identifier
6
+ :webmention
7
+ end
6
8
 
7
- private
9
+ Parsers.register(self)
8
10
 
9
- def identifier
10
- @identifier ||= :webmention
11
- end
11
+ private
12
12
 
13
13
  def link_element
14
14
  # Return first `a` or `link` element with valid `rel` attribute
@@ -17,7 +17,7 @@ module IndieWeb
17
17
  end
18
18
 
19
19
  def link_elements_css_selector
20
- @link_elements_css_selector ||= %([rel~="#{identifier}"][href])
20
+ @link_elements_css_selector ||= %([rel~="#{self.class.identifier}"][href])
21
21
  end
22
22
  end
23
23
  end
@@ -1,8 +1,8 @@
1
1
  module IndieWeb
2
2
  module Endpoints
3
3
  module Registerable
4
- def register(identifier, klass)
5
- registered[identifier] = klass
4
+ def register(klass)
5
+ registered[klass.identifier] = klass
6
6
  end
7
7
 
8
8
  def registered
@@ -1,5 +1,5 @@
1
1
  module IndieWeb
2
2
  module Endpoints
3
- VERSION = '0.1.0'.freeze
3
+ VERSION = '0.2.0'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: indieweb-endpoints
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Garber