api-pagination 4.6.3 → 4.7.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 +5 -5
- data/lib/api-pagination/configuration.rb +3 -0
- data/lib/api-pagination/version.rb +2 -2
- data/lib/rails/pagination.rb +7 -2
- data/spec/rails_spec.rb +14 -1
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: cc970990a6d83c6df9816d8deb22656f16f227c0c125e4824a102b49b3df25a8
|
4
|
+
data.tar.gz: 692ec9b45e7e26140541de25bed1b4a4be625b675967d4155cef94f6ae637dd0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a421c4df55bcaec8e6f42b76a4e719b83a2d10c9727b9dcd143f4a90072bc46062fea5313b18e10e57b7691b2d3853c72096a0ee2f41f999f77981ad1e798122
|
7
|
+
data.tar.gz: 9a54546062c9a98e2d5f602cc3145b50f2fe20dbbe7be623e42d22ae1c07e200ea257d6da82fe992af1ef48c98331a308304456dcb5dc86b96eb69f29a3ec91a
|
@@ -8,6 +8,8 @@ module ApiPagination
|
|
8
8
|
|
9
9
|
attr_accessor :include_total
|
10
10
|
|
11
|
+
attr_accessor :base_url
|
12
|
+
|
11
13
|
def configure(&block)
|
12
14
|
yield self
|
13
15
|
end
|
@@ -17,6 +19,7 @@ module ApiPagination
|
|
17
19
|
@per_page_header = 'Per-Page'
|
18
20
|
@page_header = nil
|
19
21
|
@include_total = true
|
22
|
+
@base_url = nil
|
20
23
|
end
|
21
24
|
|
22
25
|
['page', 'per_page'].each do |param_name|
|
data/lib/rails/pagination.rb
CHANGED
@@ -29,8 +29,8 @@ module Rails
|
|
29
29
|
|
30
30
|
collection = ApiPagination.paginate(collection, options)
|
31
31
|
|
32
|
-
links = (headers['Link'] ||
|
33
|
-
url = request.
|
32
|
+
links = (headers['Link'] || '').split(',').map(&:strip)
|
33
|
+
url = base_url + request.path_info
|
34
34
|
pages = ApiPagination.pages_from(collection)
|
35
35
|
|
36
36
|
pages.each do |k, v|
|
@@ -58,5 +58,10 @@ module Rails
|
|
58
58
|
end
|
59
59
|
total_count || ApiPagination.total_from(collection)
|
60
60
|
end
|
61
|
+
|
62
|
+
def base_url
|
63
|
+
ApiPagination.config.base_url || request.base_url
|
64
|
+
end
|
65
|
+
|
61
66
|
end
|
62
67
|
end
|
data/spec/rails_spec.rb
CHANGED
@@ -74,19 +74,23 @@ describe NumbersController, :type => :controller do
|
|
74
74
|
ApiPagination.config.total_header = 'X-Total-Count'
|
75
75
|
ApiPagination.config.per_page_header = 'X-Per-Page'
|
76
76
|
ApiPagination.config.page_header = 'X-Page'
|
77
|
+
ApiPagination.config.base_url = 'http://guybrush:3000'
|
77
78
|
|
78
|
-
get :index, params:
|
79
|
+
get :index, params: params
|
79
80
|
end
|
80
81
|
|
81
82
|
after do
|
82
83
|
ApiPagination.config.total_header = 'Total'
|
83
84
|
ApiPagination.config.per_page_header = 'Per-Page'
|
84
85
|
ApiPagination.config.page_header = nil
|
86
|
+
ApiPagination.config.base_url = nil
|
85
87
|
end
|
86
88
|
|
89
|
+
let(:params) { { count: 10 } }
|
87
90
|
let(:total) { response.header['X-Total-Count'].to_i }
|
88
91
|
let(:per_page) { response.header['X-Per-Page'].to_i }
|
89
92
|
let(:page) { response.header['X-Page'].to_i }
|
93
|
+
let(:link) { response.header['Link'] }
|
90
94
|
|
91
95
|
it 'should give a X-Total-Count header' do
|
92
96
|
headers_keys = response.headers.keys
|
@@ -110,6 +114,15 @@ describe NumbersController, :type => :controller do
|
|
110
114
|
expect(headers_keys).to include('X-Page')
|
111
115
|
expect(page).to eq(1)
|
112
116
|
end
|
117
|
+
|
118
|
+
context 'with paginated result' do
|
119
|
+
let(:params) { { count: 20 } }
|
120
|
+
it 'should use custom base_url in the Link header' do
|
121
|
+
|
122
|
+
expect(response.headers['Link']).to eq(
|
123
|
+
'<http://guybrush:3000/numbers?count=20&page=2>; rel="last", <http://guybrush:3000/numbers?count=20&page=2>; rel="next"')
|
124
|
+
end
|
125
|
+
end
|
113
126
|
end
|
114
127
|
|
115
128
|
context 'configured not to include the total' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: api-pagination
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Celis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-01-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -124,19 +124,19 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
124
124
|
version: '0'
|
125
125
|
requirements: []
|
126
126
|
rubyforge_project:
|
127
|
-
rubygems_version: 2.
|
127
|
+
rubygems_version: 2.7.3
|
128
128
|
signing_key:
|
129
129
|
specification_version: 4
|
130
130
|
summary: Link header pagination for Rails and Grape APIs. Don't use the request body.
|
131
131
|
test_files:
|
132
|
+
- spec/spec_helper.rb
|
132
133
|
- spec/api-pagination_spec.rb
|
133
|
-
- spec/grape_spec.rb
|
134
|
-
- spec/rails_spec.rb
|
135
134
|
- spec/sequel_spec.rb
|
136
|
-
- spec/spec_helper.rb
|
137
135
|
- spec/support/numbers_api.rb
|
138
136
|
- spec/support/numbers_controller.rb
|
139
|
-
- spec/support/shared_examples/existing_headers.rb
|
140
137
|
- spec/support/shared_examples/first_page.rb
|
141
|
-
- spec/support/shared_examples/last_page.rb
|
142
138
|
- spec/support/shared_examples/middle_page.rb
|
139
|
+
- spec/support/shared_examples/last_page.rb
|
140
|
+
- spec/support/shared_examples/existing_headers.rb
|
141
|
+
- spec/grape_spec.rb
|
142
|
+
- spec/rails_spec.rb
|