feedbuilder 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.
- checksums.yaml +7 -0
- data/.rspec +1 -1
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/feedbuilder.gemspec +3 -2
- data/lib/feedbuilder/provider.rb +5 -4
- data/lib/feedbuilder/url_builder.rb +26 -21
- data/lib/feedbuilder/version.rb +1 -1
- data/spec/provider_spec.rb +2 -0
- data/spec/spec_helper.rb +1 -1
- data/spec/url_builder_spec.rb +80 -0
- metadata +49 -22
- data/.rvmrc +0 -3
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8627a0a888505dacac4628978b3b4819ebc9c187
|
4
|
+
data.tar.gz: 41386a5d8f0305b43b9832f10c00d5ad58ce8870
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f3d954adcef09e349229d06afaa30a0cc5e86e437d4a8c99d487ae7d9b9d7679ecaa1cc28236b4f190388f648b44a78983ebb7540969e0d86249f71e4d7e3f7c
|
7
|
+
data.tar.gz: 128c545b7f4834620d799bace28bb0cd8b86d3eeb4caed7a52079d0aebe4268e0beb98e085d7d0944e9ca09c0d063260984f0b8e5136c99fca03696a00182dc5
|
data/.rspec
CHANGED
@@ -1 +1 @@
|
|
1
|
-
--color --format progress
|
1
|
+
--color --format progress
|
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
feedbuilder
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.0.0
|
data/feedbuilder.gemspec
CHANGED
@@ -15,8 +15,9 @@ Gem::Specification.new do |s|
|
|
15
15
|
|
16
16
|
s.rubyforge_project = "feedbuilder"
|
17
17
|
|
18
|
-
s.add_dependency 'activesupport', '>= 3.0.0'
|
19
|
-
s.add_dependency 'ratom'
|
18
|
+
s.add_dependency 'activesupport', '~> 3.0', '>= 3.0.0'
|
19
|
+
s.add_dependency 'ratom', '~> 0.8', '>= 0.8.2'
|
20
|
+
s.add_dependency 'addressable', '~> 2.3', '>= 2.3.5'
|
20
21
|
s.add_development_dependency 'rspec', '~> 2.0'
|
21
22
|
|
22
23
|
s.files = `git ls-files`.split("\n")
|
data/lib/feedbuilder/provider.rb
CHANGED
@@ -29,17 +29,18 @@ module FeedBuilder
|
|
29
29
|
if collection.respond_to?(:total_pages) && collection.respond_to?(:current_page) &&
|
30
30
|
collection.respond_to?(:per_page)
|
31
31
|
if collection.total_pages > 1
|
32
|
-
feed.links << Atom::Link.new(:href => url_builder.first_url(collection.per_page), :rel => :first
|
32
|
+
feed.links << Atom::Link.new(:href => url_builder.first_url(collection.per_page), :rel => :first,
|
33
|
+
:type => 'application/atom+xml')
|
33
34
|
if collection.current_page > 1
|
34
35
|
feed.links << Atom::Link.new(:href => url_builder.prev_url(collection.current_page, collection.per_page),
|
35
|
-
:rel => :previous)
|
36
|
+
:rel => :previous, :type => 'application/atom+xml')
|
36
37
|
end
|
37
38
|
if collection.current_page < collection.total_pages
|
38
39
|
feed.links << Atom::Link.new(:href => url_builder.next_url(collection.current_page, collection.per_page),
|
39
|
-
:rel => :next)
|
40
|
+
:rel => :next, :type => 'application/atom+xml')
|
40
41
|
end
|
41
42
|
feed.links << Atom::Link.new(:href => url_builder.last_url(collection.total_pages, collection.per_page),
|
42
|
-
:rel => :last)
|
43
|
+
:rel => :last, :type => 'application/atom+xml')
|
43
44
|
end
|
44
45
|
end
|
45
46
|
collection.each {|model| feed.entries << build_entry(model, &block)}
|
@@ -1,48 +1,53 @@
|
|
1
|
+
require 'addressable/uri'
|
2
|
+
|
1
3
|
module FeedBuilder
|
2
4
|
class UrlBuilder
|
3
5
|
attr_reader :base_url, :html_url, :self_url
|
4
6
|
|
5
7
|
def initialize(base_url, html_url, self_url = nil, options = {})
|
6
|
-
@base_url = base_url
|
7
|
-
@html_url = html_url
|
8
|
+
@base_url = Addressable::URI.parse(base_url)
|
9
|
+
@html_url = Addressable::URI.parse(html_url)
|
8
10
|
if self_url.present?
|
9
|
-
@self_url = self_url
|
11
|
+
@self_url = Addressable::URI.parse(self_url)
|
10
12
|
else
|
11
|
-
@self_url = html_url.dup
|
12
|
-
|
13
|
-
@self_url.sub!(/\?/, '.atom?')
|
14
|
-
else
|
15
|
-
@self_url << '.atom'
|
16
|
-
end
|
13
|
+
@self_url = @html_url.dup
|
14
|
+
@self_url.path = "#{@self_url.path}.atom"
|
17
15
|
end
|
18
16
|
@page_param = options[:page_param] || :page
|
19
17
|
@per_page_param = options[:per_page_param] || :per_page
|
20
18
|
end
|
21
19
|
|
22
20
|
def first_url(per_page)
|
23
|
-
|
21
|
+
self_url.dup.tap do |copy|
|
22
|
+
copy.query_values = hashify_query_values(copy).
|
23
|
+
merge(@page_param.to_s => '1', @per_page_param.to_s => per_page.to_s)
|
24
|
+
end
|
24
25
|
end
|
25
26
|
|
26
27
|
def next_url(current_page, per_page)
|
27
|
-
|
28
|
+
self_url.dup.tap do |copy|
|
29
|
+
copy.query_values = hashify_query_values(copy).
|
30
|
+
merge(@page_param.to_s => (current_page + 1).to_s, @per_page_param.to_s => per_page.to_s)
|
31
|
+
end
|
28
32
|
end
|
29
33
|
|
30
34
|
def prev_url(current_page, per_page)
|
31
|
-
|
35
|
+
self_url.dup.tap do |copy|
|
36
|
+
copy.query_values = hashify_query_values(copy).
|
37
|
+
merge(@page_param.to_s => (current_page - 1).to_s, @per_page_param.to_s => per_page.to_s)
|
38
|
+
end
|
32
39
|
end
|
33
40
|
|
34
41
|
def last_url(total_pages, per_page)
|
35
|
-
|
42
|
+
self_url.dup.tap do |copy|
|
43
|
+
copy.query_values = hashify_query_values(copy).
|
44
|
+
merge(@page_param.to_s => total_pages.to_s, @per_page_param.to_s => per_page.to_s)
|
45
|
+
end
|
36
46
|
end
|
37
47
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
qs = params.inject([]) {|m, kv| m << "#{kv[0]}=#{kv[1]}"}
|
42
|
-
sep = copy =~ /\?/ ? '&' : '?'
|
43
|
-
copy << "#{sep}#{URI.escape(qs.join('&'))}"
|
44
|
-
end
|
45
|
-
copy
|
48
|
+
private
|
49
|
+
def hashify_query_values(uri)
|
50
|
+
(uri.query_values(Array) || []).each_with_object({}) { |(key, val), m| m[key] ||= []; m[key] << val}
|
46
51
|
end
|
47
52
|
end
|
48
53
|
end
|
data/lib/feedbuilder/version.rb
CHANGED
data/spec/provider_spec.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe FeedBuilder::UrlBuilder do
|
4
|
+
subject do
|
5
|
+
FeedBuilder::UrlBuilder.new('http://example.com', 'http://example.com/foobar.html?baz=quux',
|
6
|
+
'http://example.com/foobar.atom?baz=quux')
|
7
|
+
end
|
8
|
+
|
9
|
+
describe '#first_url' do
|
10
|
+
it 'has the correct path' do
|
11
|
+
subject.first_url(10).path.should eq('/foobar.atom')
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'has the correct baz param' do
|
15
|
+
subject.first_url(10).query_values['baz'].should eq('quux')
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'has the correct page param' do
|
19
|
+
subject.first_url(10).query_values['page'].should eq('1')
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'has the correct per_page param' do
|
23
|
+
subject.first_url(10).query_values['per_page'].should eq('10')
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '#next_url' do
|
28
|
+
it 'has the correct path' do
|
29
|
+
subject.next_url(1, 10).path.should eq('/foobar.atom')
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'has the correct baz param' do
|
33
|
+
subject.next_url(1, 10).query_values['baz'].should eq('quux')
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'has the correct page param' do
|
37
|
+
subject.next_url(1, 10).query_values['page'].should eq('2')
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'has the correct per_page param' do
|
41
|
+
subject.next_url(1, 10).query_values['per_page'].should eq('10')
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe '#prev_url' do
|
46
|
+
it 'has the correct path' do
|
47
|
+
subject.prev_url(2, 10).path.should eq('/foobar.atom')
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'has the correct baz param' do
|
51
|
+
subject.prev_url(2, 10).query_values['baz'].should eq('quux')
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'has the correct page param' do
|
55
|
+
subject.prev_url(2, 10).query_values['page'].should eq('1')
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'has the correct per_page param' do
|
59
|
+
subject.prev_url(2, 10).query_values['per_page'].should eq('10')
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe '#last_url' do
|
64
|
+
it 'has the correct path' do
|
65
|
+
subject.last_url(5, 10).path.should eq('/foobar.atom')
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'has the correct baz param' do
|
69
|
+
subject.last_url(5, 10).query_values['baz'].should eq('quux')
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'has the correct page param' do
|
73
|
+
subject.last_url(5, 10).query_values['page'].should eq('5')
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'has the correct per_page param' do
|
77
|
+
subject.last_url(5, 10).query_values['per_page'].should eq('10')
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
metadata
CHANGED
@@ -1,52 +1,78 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: feedbuilder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.2.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Brian Moseley
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-03-14 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: activesupport
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.0'
|
20
|
+
- - '>='
|
20
21
|
- !ruby/object:Gem::Version
|
21
22
|
version: 3.0.0
|
22
23
|
type: :runtime
|
23
24
|
prerelease: false
|
24
25
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
26
|
requirements:
|
27
|
-
- -
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '3.0'
|
30
|
+
- - '>='
|
28
31
|
- !ruby/object:Gem::Version
|
29
32
|
version: 3.0.0
|
30
33
|
- !ruby/object:Gem::Dependency
|
31
34
|
name: ratom
|
32
35
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
36
|
requirements:
|
35
|
-
- -
|
37
|
+
- - ~>
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0.8'
|
40
|
+
- - '>='
|
36
41
|
- !ruby/object:Gem::Version
|
37
|
-
version:
|
42
|
+
version: 0.8.2
|
38
43
|
type: :runtime
|
39
44
|
prerelease: false
|
40
45
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
46
|
requirements:
|
43
|
-
- -
|
47
|
+
- - ~>
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0.8'
|
50
|
+
- - '>='
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 0.8.2
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: addressable
|
55
|
+
requirement: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ~>
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '2.3'
|
60
|
+
- - '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 2.3.5
|
63
|
+
type: :runtime
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '2.3'
|
70
|
+
- - '>='
|
44
71
|
- !ruby/object:Gem::Version
|
45
|
-
version:
|
72
|
+
version: 2.3.5
|
46
73
|
- !ruby/object:Gem::Dependency
|
47
74
|
name: rspec
|
48
75
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
76
|
requirements:
|
51
77
|
- - ~>
|
52
78
|
- !ruby/object:Gem::Version
|
@@ -54,7 +80,6 @@ dependencies:
|
|
54
80
|
type: :development
|
55
81
|
prerelease: false
|
56
82
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
83
|
requirements:
|
59
84
|
- - ~>
|
60
85
|
- !ruby/object:Gem::Version
|
@@ -69,7 +94,8 @@ extra_rdoc_files: []
|
|
69
94
|
files:
|
70
95
|
- .gitignore
|
71
96
|
- .rspec
|
72
|
-
- .
|
97
|
+
- .ruby-gemset
|
98
|
+
- .ruby-version
|
73
99
|
- Gemfile
|
74
100
|
- LICENSE
|
75
101
|
- README.md
|
@@ -82,31 +108,32 @@ files:
|
|
82
108
|
- spec/nug.rb
|
83
109
|
- spec/provider_spec.rb
|
84
110
|
- spec/spec_helper.rb
|
111
|
+
- spec/url_builder_spec.rb
|
85
112
|
homepage: ''
|
86
113
|
licenses: []
|
114
|
+
metadata: {}
|
87
115
|
post_install_message:
|
88
116
|
rdoc_options: []
|
89
117
|
require_paths:
|
90
118
|
- lib
|
91
119
|
required_ruby_version: !ruby/object:Gem::Requirement
|
92
|
-
none: false
|
93
120
|
requirements:
|
94
|
-
- -
|
121
|
+
- - '>='
|
95
122
|
- !ruby/object:Gem::Version
|
96
123
|
version: '0'
|
97
124
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
|
-
none: false
|
99
125
|
requirements:
|
100
|
-
- -
|
126
|
+
- - '>='
|
101
127
|
- !ruby/object:Gem::Version
|
102
128
|
version: '0'
|
103
129
|
requirements: []
|
104
130
|
rubyforge_project: feedbuilder
|
105
|
-
rubygems_version:
|
131
|
+
rubygems_version: 2.2.2
|
106
132
|
signing_key:
|
107
|
-
specification_version:
|
133
|
+
specification_version: 4
|
108
134
|
summary: An easier way to build Atom feeds
|
109
135
|
test_files:
|
110
136
|
- spec/nug.rb
|
111
137
|
- spec/provider_spec.rb
|
112
138
|
- spec/spec_helper.rb
|
139
|
+
- spec/url_builder_spec.rb
|
data/.rvmrc
DELETED