http_link_header 0.1.0 → 0.2.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.
- data/README.md +20 -0
- data/Rakefile +5 -0
- data/http_link_header.gemspec +3 -0
- data/lib/http_link_header/http_link_params.rb +4 -1
- data/lib/http_link_header/version.rb +1 -1
- data/spec/lib/http_link_header_spec.rb +57 -0
- data/spec/spec_helper.rb +18 -0
- metadata +42 -12
- data/README.rdoc +0 -7
data/README.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# HttpLinkHeader
|
2
|
+
|
3
|
+
Parses and generates HTTP Link headers as defined by
|
4
|
+
[IETF RFC 5988](http://tools.ietf.org/html/rfc5988).
|
5
|
+
|
6
|
+
<dl>
|
7
|
+
<dt>Author</dt>
|
8
|
+
<dd>Clyde Law (mailto:claw@alum.mit.edu)</dd>
|
9
|
+
|
10
|
+
<dt>License</dt>
|
11
|
+
<dd>Released under the MIT license</dd>
|
12
|
+
</dl>
|
13
|
+
|
14
|
+
## Changelog
|
15
|
+
|
16
|
+
### v0.2.0
|
17
|
+
* Fix ruby 2.0 compat (#1 - @urkle)
|
18
|
+
|
19
|
+
### v0.1.0
|
20
|
+
* Initial version
|
data/Rakefile
CHANGED
data/http_link_header.gemspec
CHANGED
@@ -18,4 +18,7 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
19
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
20
|
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
s.add_development_dependency "rake", "~> 10.0"
|
23
|
+
s.add_development_dependency "rspec", "~> 3.4"
|
21
24
|
end
|
@@ -1,6 +1,8 @@
|
|
1
|
+
require 'set'
|
2
|
+
|
1
3
|
class HttpLinkHeader::HttpLinkParams < ::Hash
|
2
4
|
DELIMETER = ';'
|
3
|
-
RELATION_TYPE_ATTRIBUTES = Set['rel', 'rev']
|
5
|
+
RELATION_TYPE_ATTRIBUTES = ::Set['rel', 'rev']
|
4
6
|
|
5
7
|
class RelationTypes < ::Set
|
6
8
|
|
@@ -8,6 +10,7 @@ class HttpLinkHeader::HttpLinkParams < ::Hash
|
|
8
10
|
if relation_types.is_a?(Enumerable)
|
9
11
|
super(relation_types)
|
10
12
|
elsif relation_types.is_a?(String)
|
13
|
+
super()
|
11
14
|
add(relation_types)
|
12
15
|
else
|
13
16
|
raise ArgumentError, "invalid relation-types: #{relation_types}"
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe HttpLinkHeader do
|
4
|
+
let(:url) { 'http://example.com/?page=1' }
|
5
|
+
let(:rel_types) { 'next' }
|
6
|
+
let(:link) { "<#{url}>; rel=\"#{rel_types}\"" }
|
7
|
+
|
8
|
+
describe 'add' do
|
9
|
+
it 'should add the link' do
|
10
|
+
expect {
|
11
|
+
subject.add(link)
|
12
|
+
}.to change {subject.length}.by(1)
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should add the url to []' do
|
16
|
+
expect {
|
17
|
+
subject.add(link)
|
18
|
+
}.to change {subject[url]}.from(nil)
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'the added url should point to an HttpLinkParam object' do
|
22
|
+
subject.add(link)
|
23
|
+
|
24
|
+
expect(subject[url]).to be_a(HttpLinkHeader::HttpLinkParams)
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'the link params should have the rel relation' do
|
28
|
+
subject.add(link)
|
29
|
+
|
30
|
+
expect(subject[url][:rel]).to be_a(HttpLinkHeader::HttpLinkParams::RelationTypes)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe '#rel' do
|
35
|
+
it 'should find the url by rel type' do
|
36
|
+
subject.add(link)
|
37
|
+
|
38
|
+
expect(subject.rel('next')).to eq(url)
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'with multiple rel types' do
|
42
|
+
let(:rel_types) { 'next last' }
|
43
|
+
|
44
|
+
it 'should find the url by the next type' do
|
45
|
+
subject.add(link)
|
46
|
+
|
47
|
+
expect(subject.rel('next')).to eq(url)
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'should find the url by the last type' do
|
51
|
+
subject.add(link)
|
52
|
+
|
53
|
+
expect(subject.rel('last')).to eq(url)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
2
|
+
require 'http_link_header'
|
3
|
+
|
4
|
+
RSpec.configure do |config|
|
5
|
+
config.expect_with :rspec do |expectations|
|
6
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
7
|
+
end
|
8
|
+
|
9
|
+
config.mock_with :rspec do |mocks|
|
10
|
+
mocks.verify_partial_doubles = true
|
11
|
+
end
|
12
|
+
|
13
|
+
config.disable_monkey_patching!
|
14
|
+
|
15
|
+
config.order = :random
|
16
|
+
|
17
|
+
Kernel.srand config.seed
|
18
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: http_link_header
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 2
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Clyde Law
|
@@ -15,10 +15,38 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
date: 2016-07-29 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
type: :development
|
22
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
23
|
+
none: false
|
24
|
+
requirements:
|
25
|
+
- - ~>
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
hash: 35
|
28
|
+
segments:
|
29
|
+
- 10
|
30
|
+
- 0
|
31
|
+
version: "10.0"
|
32
|
+
name: rake
|
33
|
+
version_requirements: *id001
|
34
|
+
prerelease: false
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
type: :development
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ~>
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
hash: 15
|
43
|
+
segments:
|
44
|
+
- 3
|
45
|
+
- 4
|
46
|
+
version: "3.4"
|
47
|
+
name: rspec
|
48
|
+
version_requirements: *id002
|
49
|
+
prerelease: false
|
22
50
|
description: Parses and generates HTTP Link headers as defined by IETF RFC 5988.
|
23
51
|
email:
|
24
52
|
- claw@alum.mit.edu
|
@@ -31,13 +59,14 @@ extra_rdoc_files: []
|
|
31
59
|
files:
|
32
60
|
- .gitignore
|
33
61
|
- Gemfile
|
34
|
-
- README.
|
62
|
+
- README.md
|
35
63
|
- Rakefile
|
36
64
|
- http_link_header.gemspec
|
37
65
|
- lib/http_link_header.rb
|
38
66
|
- lib/http_link_header/http_link_params.rb
|
39
67
|
- lib/http_link_header/version.rb
|
40
|
-
|
68
|
+
- spec/lib/http_link_header_spec.rb
|
69
|
+
- spec/spec_helper.rb
|
41
70
|
homepage: http://github.com/Umofomia/http_link_header
|
42
71
|
licenses:
|
43
72
|
- MIT
|
@@ -67,9 +96,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
67
96
|
requirements: []
|
68
97
|
|
69
98
|
rubyforge_project: http_link_header
|
70
|
-
rubygems_version: 1.
|
99
|
+
rubygems_version: 1.8.30
|
71
100
|
signing_key:
|
72
101
|
specification_version: 3
|
73
102
|
summary: Parses and generates HTTP Link headers as defined by IETF RFC 5988.
|
74
|
-
test_files:
|
75
|
-
|
103
|
+
test_files:
|
104
|
+
- spec/lib/http_link_header_spec.rb
|
105
|
+
- spec/spec_helper.rb
|