link-header-parser 2.2.0 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -1
- data/CONTRIBUTING.md +2 -2
- data/README.md +4 -4
- data/lib/link-header-parser.rb +1 -2
- data/lib/link_header_parser/link_header.rb +8 -9
- data/lib/link_header_parser/link_header_parameter.rb +6 -4
- data/lib/link_header_parser/link_headers_collection.rb +5 -5
- data/lib/link_header_parser/version.rb +1 -1
- data/link-header-parser.gemspec +1 -1
- metadata +7 -8
- data/lib/link_header_parser/exceptions.rb +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6b2127eef719541b0ed02c6cb37c7271ed1c1bac8358f5808fb50c08d5ccada3
|
4
|
+
data.tar.gz: 999fdc8ea6ad395fe72e88094ed4e924063844600b25df4df5822b2e85b6c2aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 90a5edd9b4ea7802818d84d858a365f365c6aee0cdcb9ec453feb5620ef7c6b2957da0063a8eaa2847318b69be5e668874a1bf4dc5b01cb36ff75cfd6190a33d
|
7
|
+
data.tar.gz: 676c81a374430b522d62d2cc569e149e4c18d5eead47db851cadc1fe509ff787d02b3ecdb823a1e70f8244a6f4d3fb8b122a18ca2dd4ea697eff6faa8c9e22a5
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,14 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
-
##
|
3
|
+
## 3.0.0 / 2021-05-22
|
4
|
+
|
5
|
+
- Add implicit type conversion methods, alias explicit methods, and update specs (d132535)
|
6
|
+
- Remove exceptions module (249d77c)
|
7
|
+
- Use implicit conversions instead of type checking in methods (628c01b)
|
8
|
+
- Replace Absolutely dependency with Addressable (beb5188)
|
9
|
+
- Update project Ruby version to 2.5.9 (4a3941f)
|
10
|
+
|
11
|
+
## 2.2.0 / 2021-04-02
|
4
12
|
|
5
13
|
- Expand supported Ruby versions to include 3.0 (7187878)
|
6
14
|
|
data/CONTRIBUTING.md
CHANGED
@@ -8,9 +8,9 @@ There are a couple ways you can help improve link-header-parser-ruby:
|
|
8
8
|
|
9
9
|
## Getting Started
|
10
10
|
|
11
|
-
link-header-parser-ruby is developed using Ruby 2.5.
|
11
|
+
link-header-parser-ruby is developed using Ruby 2.5.9 and is additionally tested against Ruby 2.6, 2.7, and 3.0 using [CircleCI](https://app.circleci.com/pipelines/github/jgarber623/link-header-parser-ruby).
|
12
12
|
|
13
|
-
Before making changes to link-header-parser-ruby, you'll want to install Ruby 2.5.
|
13
|
+
Before making changes to link-header-parser-ruby, you'll want to install Ruby 2.5.9. 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.9 using your method of choice, install the project's gems by running:
|
14
14
|
|
15
15
|
```sh
|
16
16
|
bundle install
|
data/README.md
CHANGED
@@ -12,7 +12,7 @@
|
|
12
12
|
|
13
13
|
Before installing and using link-header-parser-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).
|
14
14
|
|
15
|
-
link-header-parser-ruby is developed using Ruby 2.5.
|
15
|
+
link-header-parser-ruby is developed using Ruby 2.5.9 and is additionally tested against Ruby 2.6, 2.7, and 3.0 using [CircleCI](https://app.circleci.com/pipelines/github/jgarber623/link-header-parser-ruby).
|
16
16
|
|
17
17
|
## Installation
|
18
18
|
|
@@ -42,13 +42,13 @@ response = HTTP.get('https://sixtwothree.org')
|
|
42
42
|
|
43
43
|
link_headers = response.headers.get('link')
|
44
44
|
|
45
|
-
collection = LinkHeaderParser.parse(link_headers, base: response.uri
|
45
|
+
collection = LinkHeaderParser.parse(link_headers, base: response.uri)
|
46
46
|
```
|
47
47
|
|
48
48
|
The `parse` method accepts two arguments:
|
49
49
|
|
50
50
|
1. an `Array` of strings representing HTTP Link headers (e.g. `['</>; rel="home"', '</chapters/1>; anchor="#copyright"; rel="license"']`)
|
51
|
-
1. a `String` representing the absolute URL of the resource providing the HTTP Link headers
|
51
|
+
1. a `String` (or any `String`-like object) representing the absolute URL of the resource providing the HTTP Link headers
|
52
52
|
|
53
53
|
In the example above, `collection` is an instance of `LinkHeadersCollection` which includes Ruby's [`Enumerable`](https://ruby-doc.org/core/Enumerable.html) mixin. This mixin allows for use of common methods like `each`, `first`/`last`, and `map`.
|
54
54
|
|
@@ -137,7 +137,7 @@ link_header.relation_types
|
|
137
137
|
link_header = LinkHeaderParser.parse('</posts.rss>; rel="alternate"; hreflang="en-US"; title="sixtwothree.org: Posts"; type="application/rss+xml"', base: 'https://sixtwothree.org').first
|
138
138
|
|
139
139
|
link_header.link_parameters
|
140
|
-
#=> [#<LinkHeaderParser::LinkHeaderParameter
|
140
|
+
#=> [#<LinkHeaderParser::LinkHeaderParameter name: "rel", value: "alternate">, #<LinkHeaderParser::LinkHeaderParameter name: "hreflang", value: "en-US">, #<LinkHeaderParser::LinkHeaderParameter name: "title", value: "sixtwothree.org: Posts">, #<LinkHeaderParser::LinkHeaderParameter name: "type", value: "application/rss+xml">]
|
141
141
|
```
|
142
142
|
|
143
143
|
Note that the `Array` returned by the `link_parameters` method may include multiple `LinkHeaderParameter`s with the same name depending on the provided Link header. Certain methods on `LinkHeader` will return values from the first occurrence of a parameter name (e.g. `link_header.relations_string`) in accordance with [RFC-8288](https://tools.ietf.org/html/rfc8288).
|
data/lib/link-header-parser.rb
CHANGED
@@ -11,11 +11,8 @@ module LinkHeaderParser
|
|
11
11
|
# @param field_value [String]
|
12
12
|
# @param base [String]
|
13
13
|
def initialize(field_value, base:)
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
@field_value = field_value
|
18
|
-
@base = base
|
14
|
+
@field_value = field_value.to_str
|
15
|
+
@base = base.to_str
|
19
16
|
end
|
20
17
|
|
21
18
|
# The context URL for this Link header extracted from field_value (or target URL if no context URL is present)
|
@@ -31,7 +28,7 @@ module LinkHeaderParser
|
|
31
28
|
#
|
32
29
|
# @return [String]
|
33
30
|
def context_uri
|
34
|
-
@context_uri ||=
|
31
|
+
@context_uri ||= Addressable::URI.join(target_uri, context_string).normalize.to_s
|
35
32
|
end
|
36
33
|
|
37
34
|
def inspect
|
@@ -59,7 +56,7 @@ module LinkHeaderParser
|
|
59
56
|
#
|
60
57
|
# @return [String]
|
61
58
|
def relations_string
|
62
|
-
@relations_string ||= grouped_link_parameters[:rel]&.first
|
59
|
+
@relations_string ||= grouped_link_parameters[:rel]&.first.to_s
|
63
60
|
end
|
64
61
|
|
65
62
|
# The target URL for this Link header extracted from field_value
|
@@ -75,11 +72,11 @@ module LinkHeaderParser
|
|
75
72
|
#
|
76
73
|
# @return [String]
|
77
74
|
def target_uri
|
78
|
-
@target_uri ||=
|
75
|
+
@target_uri ||= Addressable::URI.join(base, target_string).normalize.to_s
|
79
76
|
end
|
80
77
|
|
81
78
|
# @return [Hash{Symbol => String, Array, Hash{Symbol => Array}}]
|
82
|
-
def
|
79
|
+
def to_hash
|
83
80
|
{
|
84
81
|
target_string: target_string,
|
85
82
|
target_uri: target_uri,
|
@@ -91,6 +88,8 @@ module LinkHeaderParser
|
|
91
88
|
}
|
92
89
|
end
|
93
90
|
|
91
|
+
alias to_h to_hash
|
92
|
+
|
94
93
|
private
|
95
94
|
|
96
95
|
attr_reader :base
|
@@ -6,7 +6,7 @@ module LinkHeaderParser
|
|
6
6
|
|
7
7
|
# @param parameter [String]
|
8
8
|
def initialize(parameter)
|
9
|
-
@parameter = parameter
|
9
|
+
@parameter = parameter.to_str
|
10
10
|
end
|
11
11
|
|
12
12
|
def inspect
|
@@ -22,16 +22,18 @@ module LinkHeaderParser
|
|
22
22
|
|
23
23
|
# @see https://tools.ietf.org/html/rfc8288#appendix-B.3 (Appendix B.3.2.8)
|
24
24
|
#
|
25
|
-
# @return [String
|
25
|
+
# @return [String]
|
26
26
|
def value
|
27
|
-
@value ||= parameter_match_data[:value]
|
27
|
+
@value ||= parameter_match_data[:value].to_s
|
28
28
|
end
|
29
29
|
|
30
30
|
# @return [Array<String>]
|
31
|
-
def
|
31
|
+
def to_ary
|
32
32
|
[name, value]
|
33
33
|
end
|
34
34
|
|
35
|
+
alias to_a to_ary
|
36
|
+
|
35
37
|
private
|
36
38
|
|
37
39
|
def parameter_match_data
|
@@ -11,10 +11,10 @@ module LinkHeaderParser
|
|
11
11
|
# @param headers [Array<String>]
|
12
12
|
# @param base [String]
|
13
13
|
def initialize(*headers, base:)
|
14
|
-
@headers = headers.flatten
|
15
|
-
@base = base
|
14
|
+
@headers = headers.to_ary.flatten.map(&:to_str)
|
15
|
+
@base = base.to_str
|
16
16
|
|
17
|
-
|
17
|
+
distinct_headers.each { |header| push(LinkHeader.new(header, base: base)) }
|
18
18
|
end
|
19
19
|
|
20
20
|
# @return [Hash{Symbol => Array<LinkHeaderParser::LinkHeader>}]
|
@@ -37,8 +37,8 @@ module LinkHeaderParser
|
|
37
37
|
|
38
38
|
attr_reader :base
|
39
39
|
|
40
|
-
def
|
41
|
-
@
|
40
|
+
def distinct_headers
|
41
|
+
@distinct_headers ||= headers.flat_map { |header| header.split(/,(?=[\s|<])/) }.map(&:strip)
|
42
42
|
end
|
43
43
|
|
44
44
|
def members
|
data/link-header-parser.gemspec
CHANGED
@@ -22,5 +22,5 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.metadata['bug_tracker_uri'] = "#{spec.homepage}/issues"
|
23
23
|
spec.metadata['changelog_uri'] = "#{spec.homepage}/blob/v#{spec.version}/CHANGELOG.md"
|
24
24
|
|
25
|
-
spec.add_runtime_dependency '
|
25
|
+
spec.add_runtime_dependency 'addressable', '~> 2.7'
|
26
26
|
end
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: link-header-parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Garber
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-05-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: addressable
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '2.7'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '2.7'
|
27
27
|
description: Parse HTTP Link headers.
|
28
28
|
email:
|
29
29
|
- jason@sixtwothree.org
|
@@ -36,7 +36,6 @@ files:
|
|
36
36
|
- LICENSE
|
37
37
|
- README.md
|
38
38
|
- lib/link-header-parser.rb
|
39
|
-
- lib/link_header_parser/exceptions.rb
|
40
39
|
- lib/link_header_parser/link_header.rb
|
41
40
|
- lib/link_header_parser/link_header_parameter.rb
|
42
41
|
- lib/link_header_parser/link_headers_collection.rb
|
@@ -47,7 +46,7 @@ licenses:
|
|
47
46
|
- MIT
|
48
47
|
metadata:
|
49
48
|
bug_tracker_uri: https://github.com/jgarber623/link-header-parser-ruby/issues
|
50
|
-
changelog_uri: https://github.com/jgarber623/link-header-parser-ruby/blob/
|
49
|
+
changelog_uri: https://github.com/jgarber623/link-header-parser-ruby/blob/v3.0.0/CHANGELOG.md
|
51
50
|
post_install_message:
|
52
51
|
rdoc_options: []
|
53
52
|
require_paths:
|
@@ -66,7 +65,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
66
65
|
- !ruby/object:Gem::Version
|
67
66
|
version: '0'
|
68
67
|
requirements: []
|
69
|
-
rubygems_version: 3.
|
68
|
+
rubygems_version: 3.2.16
|
70
69
|
signing_key:
|
71
70
|
specification_version: 4
|
72
71
|
summary: Parse HTTP Link headers.
|