api_pagination_headers 2.0.1 → 2.1.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 +4 -4
- data/Gemfile.lock +86 -66
- data/LICENSE +18 -17
- data/README.md +21 -37
- data/api_pagination_headers.gemspec +1 -1
- data/lib/api_pagination_headers.rb +3 -0
- data/lib/api_pagination_headers/config.rb +1 -0
- data/lib/api_pagination_headers/version.rb +1 -1
- data/spec/controllers/posts_controller_spec.rb +12 -0
- data/spec/dummy/app/controllers/application_controller.rb +0 -1
- data/spec/dummy/app/controllers/comments_controller.rb +1 -1
- data/spec/dummy/app/controllers/posts_controller.rb +1 -1
- metadata +7 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: bbc1bb209392610ed0cbdb2e6c8f1acad4c345ea
|
|
4
|
+
data.tar.gz: 12da3da8f08069065e7d2b9c65049c0790926870
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 63023f56aa083ff91a158a1de00fe3e9585a002abbb42f755aba164334ff0ede0dd2f3cac9954cd4772fcc10379b599c3e6fe9c2addca3b6788b52fa14bebf7b
|
|
7
|
+
data.tar.gz: f17ec0aec0d372f9b125a889b9b06ce341db288f6face91980bfe150a865d5d2d32a57d8f665c52c284a405664f8c8f98bf8c6ac438e5b9db1884d986c55b014
|
data/Gemfile.lock
CHANGED
|
@@ -1,39 +1,48 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
api_pagination_headers (2.
|
|
5
|
-
rails (
|
|
4
|
+
api_pagination_headers (2.1.0)
|
|
5
|
+
rails (>= 4.1.8)
|
|
6
6
|
|
|
7
7
|
GEM
|
|
8
8
|
remote: https://rubygems.org/
|
|
9
9
|
specs:
|
|
10
|
-
actionmailer (4.1
|
|
11
|
-
actionpack (= 4.1
|
|
12
|
-
actionview (= 4.1
|
|
10
|
+
actionmailer (4.2.1)
|
|
11
|
+
actionpack (= 4.2.1)
|
|
12
|
+
actionview (= 4.2.1)
|
|
13
|
+
activejob (= 4.2.1)
|
|
13
14
|
mail (~> 2.5, >= 2.5.4)
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
rails-dom-testing (~> 1.0, >= 1.0.5)
|
|
16
|
+
actionpack (4.2.1)
|
|
17
|
+
actionview (= 4.2.1)
|
|
18
|
+
activesupport (= 4.2.1)
|
|
19
|
+
rack (~> 1.6)
|
|
18
20
|
rack-test (~> 0.6.2)
|
|
19
|
-
|
|
20
|
-
|
|
21
|
+
rails-dom-testing (~> 1.0, >= 1.0.5)
|
|
22
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.1)
|
|
23
|
+
actionview (4.2.1)
|
|
24
|
+
activesupport (= 4.2.1)
|
|
21
25
|
builder (~> 3.1)
|
|
22
26
|
erubis (~> 2.7.0)
|
|
23
|
-
|
|
24
|
-
|
|
27
|
+
rails-dom-testing (~> 1.0, >= 1.0.5)
|
|
28
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.1)
|
|
29
|
+
activejob (4.2.1)
|
|
30
|
+
activesupport (= 4.2.1)
|
|
31
|
+
globalid (>= 0.3.0)
|
|
32
|
+
activemodel (4.2.1)
|
|
33
|
+
activesupport (= 4.2.1)
|
|
25
34
|
builder (~> 3.1)
|
|
26
|
-
activerecord (4.1
|
|
27
|
-
activemodel (= 4.1
|
|
28
|
-
activesupport (= 4.1
|
|
29
|
-
arel (~>
|
|
30
|
-
activesupport (4.1
|
|
31
|
-
i18n (~> 0.
|
|
35
|
+
activerecord (4.2.1)
|
|
36
|
+
activemodel (= 4.2.1)
|
|
37
|
+
activesupport (= 4.2.1)
|
|
38
|
+
arel (~> 6.0)
|
|
39
|
+
activesupport (4.2.1)
|
|
40
|
+
i18n (~> 0.7)
|
|
32
41
|
json (~> 1.7, >= 1.7.7)
|
|
33
42
|
minitest (~> 5.1)
|
|
34
|
-
thread_safe (~> 0.
|
|
43
|
+
thread_safe (~> 0.3, >= 0.3.4)
|
|
35
44
|
tzinfo (~> 1.1)
|
|
36
|
-
arel (
|
|
45
|
+
arel (6.0.0)
|
|
37
46
|
builder (3.2.2)
|
|
38
47
|
diff-lcs (1.2.5)
|
|
39
48
|
erubis (2.7.0)
|
|
@@ -42,65 +51,76 @@ GEM
|
|
|
42
51
|
factory_girl_rails (4.5.0)
|
|
43
52
|
factory_girl (~> 4.5.0)
|
|
44
53
|
railties (>= 3.0.0)
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
54
|
+
globalid (0.3.5)
|
|
55
|
+
activesupport (>= 4.1.0)
|
|
56
|
+
i18n (0.7.0)
|
|
57
|
+
json (1.8.2)
|
|
58
|
+
kaminari (0.16.3)
|
|
49
59
|
actionpack (>= 3.0.0)
|
|
50
60
|
activesupport (>= 3.0.0)
|
|
51
|
-
|
|
61
|
+
loofah (2.0.1)
|
|
62
|
+
nokogiri (>= 1.5.9)
|
|
63
|
+
mail (2.6.3)
|
|
52
64
|
mime-types (>= 1.16, < 3)
|
|
53
65
|
mime-types (2.4.3)
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
66
|
+
mini_portile (0.6.2)
|
|
67
|
+
minitest (5.6.0)
|
|
68
|
+
nokogiri (1.6.6.2)
|
|
69
|
+
mini_portile (~> 0.6.0)
|
|
70
|
+
rack (1.6.0)
|
|
71
|
+
rack-test (0.6.3)
|
|
58
72
|
rack (>= 1.0)
|
|
59
|
-
rails (4.1
|
|
60
|
-
actionmailer (= 4.1
|
|
61
|
-
actionpack (= 4.1
|
|
62
|
-
actionview (= 4.1
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
73
|
+
rails (4.2.1)
|
|
74
|
+
actionmailer (= 4.2.1)
|
|
75
|
+
actionpack (= 4.2.1)
|
|
76
|
+
actionview (= 4.2.1)
|
|
77
|
+
activejob (= 4.2.1)
|
|
78
|
+
activemodel (= 4.2.1)
|
|
79
|
+
activerecord (= 4.2.1)
|
|
80
|
+
activesupport (= 4.2.1)
|
|
66
81
|
bundler (>= 1.3.0, < 2.0)
|
|
67
|
-
railties (= 4.1
|
|
68
|
-
sprockets-rails
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
82
|
+
railties (= 4.2.1)
|
|
83
|
+
sprockets-rails
|
|
84
|
+
rails-deprecated_sanitizer (1.0.3)
|
|
85
|
+
activesupport (>= 4.2.0.alpha)
|
|
86
|
+
rails-dom-testing (1.0.6)
|
|
87
|
+
activesupport (>= 4.2.0.beta, < 5.0)
|
|
88
|
+
nokogiri (~> 1.6.0)
|
|
89
|
+
rails-deprecated_sanitizer (>= 1.0.1)
|
|
90
|
+
rails-html-sanitizer (1.0.2)
|
|
91
|
+
loofah (~> 2.0)
|
|
92
|
+
railties (4.2.1)
|
|
93
|
+
actionpack (= 4.2.1)
|
|
94
|
+
activesupport (= 4.2.1)
|
|
72
95
|
rake (>= 0.8.7)
|
|
73
96
|
thor (>= 0.18.1, < 2.0)
|
|
74
|
-
rake (10.
|
|
75
|
-
rspec-core (3.
|
|
76
|
-
rspec-support (~> 3.
|
|
77
|
-
rspec-expectations (3.1
|
|
97
|
+
rake (10.4.2)
|
|
98
|
+
rspec-core (3.2.3)
|
|
99
|
+
rspec-support (~> 3.2.0)
|
|
100
|
+
rspec-expectations (3.2.1)
|
|
78
101
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
79
|
-
rspec-support (~> 3.
|
|
80
|
-
rspec-mocks (3.1
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
rspec-
|
|
88
|
-
rspec-
|
|
89
|
-
rspec-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
multi_json (~> 1.0)
|
|
102
|
+
rspec-support (~> 3.2.0)
|
|
103
|
+
rspec-mocks (3.2.1)
|
|
104
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
105
|
+
rspec-support (~> 3.2.0)
|
|
106
|
+
rspec-rails (3.2.1)
|
|
107
|
+
actionpack (>= 3.0, < 4.3)
|
|
108
|
+
activesupport (>= 3.0, < 4.3)
|
|
109
|
+
railties (>= 3.0, < 4.3)
|
|
110
|
+
rspec-core (~> 3.2.0)
|
|
111
|
+
rspec-expectations (~> 3.2.0)
|
|
112
|
+
rspec-mocks (~> 3.2.0)
|
|
113
|
+
rspec-support (~> 3.2.0)
|
|
114
|
+
rspec-support (3.2.2)
|
|
115
|
+
sprockets (3.0.1)
|
|
94
116
|
rack (~> 1.0)
|
|
95
|
-
|
|
96
|
-
sprockets-rails (2.2.0)
|
|
117
|
+
sprockets-rails (2.2.4)
|
|
97
118
|
actionpack (>= 3.0)
|
|
98
119
|
activesupport (>= 3.0)
|
|
99
120
|
sprockets (>= 2.8, < 4.0)
|
|
100
|
-
sqlite3 (1.3.
|
|
121
|
+
sqlite3 (1.3.10)
|
|
101
122
|
thor (0.19.1)
|
|
102
|
-
thread_safe (0.3.
|
|
103
|
-
tilt (1.4.1)
|
|
123
|
+
thread_safe (0.3.5)
|
|
104
124
|
tzinfo (1.2.2)
|
|
105
125
|
thread_safe (~> 0.1)
|
|
106
126
|
will_paginate (3.0.7)
|
data/LICENSE
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
|
-
|
|
1
|
+
The MIT License (MIT)
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
a copy of this software and associated documentation files (the
|
|
5
|
-
"Software"), to deal in the Software without restriction, including
|
|
6
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
-
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
-
the following conditions:
|
|
3
|
+
Copyright (c) Richard Käll <richard.kall@me.com> (richardkall.se)
|
|
10
4
|
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
13
11
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.ITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
|
@@ -1,37 +1,31 @@
|
|
|
1
|
-
#api_pagination_headers [](http://travis-ci.org/richardkall/api_pagination_headers) [](http://travis-ci.org/richardkall/api_pagination_headers) [](https://gemnasium.com/richardkall/api_pagination_headers)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
> Adds pagination info to a `Link` response header.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
This technique is considered to be a [best practice](http://www.vinaysahni.com/best-practices-for-a-pragmatic-restful-api#pagination) for REST APIs and is currently used by [GitHub](http://developer.github.com/v3/#pagination). The gem also adds the total number of records into a `Total-Count` header.
|
|
6
|
+
|
|
7
|
+
Support for [rails-api](https://github.com/rails-api/rails-api) is built in.
|
|
8
|
+
|
|
9
|
+
**Example**
|
|
6
10
|
|
|
7
11
|
```
|
|
8
12
|
Link: <http://example.com/posts?page=2&per_page=10>; rel="next", <http://example.com/posts?page=2&per_page=10>; rel="last"
|
|
9
13
|
Total-Count: 11
|
|
10
14
|
```
|
|
11
15
|
|
|
12
|
-
##
|
|
13
|
-
|
|
14
|
-
Include in your Gemfile:
|
|
16
|
+
## Requirements
|
|
15
17
|
|
|
16
|
-
|
|
18
|
+
- [Kaminari](https://github.com/amatsuda/kaminari) or [will_paginate](https://github.com/mislav/will_paginate)
|
|
17
19
|
|
|
18
|
-
|
|
19
|
-
gem 'api_pagination_headers'
|
|
20
|
-
```
|
|
20
|
+
## Install
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
Include in your Gemfile:
|
|
23
23
|
|
|
24
24
|
```ruby
|
|
25
|
-
gem 'api_pagination_headers'
|
|
25
|
+
gem 'api_pagination_headers'
|
|
26
26
|
```
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
##Usage
|
|
31
|
-
|
|
32
|
-
In the controller:
|
|
33
|
-
|
|
34
|
-
* Rails 4
|
|
28
|
+
## Usage
|
|
35
29
|
|
|
36
30
|
```ruby
|
|
37
31
|
class PostsController < ApplicationController
|
|
@@ -44,28 +38,18 @@ class PostsController < ApplicationController
|
|
|
44
38
|
end
|
|
45
39
|
```
|
|
46
40
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
```ruby
|
|
50
|
-
class PostsController < ApplicationController
|
|
51
|
-
after_filter only: [:index] { set_pagination_headers(:posts) }
|
|
52
|
-
|
|
53
|
-
def index
|
|
54
|
-
@posts = Post.paginate(per_page: params[:per_page], page: params[:page])
|
|
55
|
-
respond_with @posts
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
##Configuration
|
|
61
|
-
|
|
62
|
-
You can change the `Total-Count` header title by configuring the gem.
|
|
41
|
+
## Config
|
|
63
42
|
|
|
64
43
|
```ruby
|
|
65
44
|
ApiPaginationHeaders.configure do |config|
|
|
45
|
+
# Change total count header title (default: 'Total-Count')
|
|
66
46
|
config.total_count_header = 'X-Total-Count'
|
|
47
|
+
|
|
48
|
+
# Force HTTPS (default: false)
|
|
49
|
+
config.force_https = true
|
|
67
50
|
end
|
|
68
51
|
```
|
|
69
52
|
|
|
70
|
-
##License
|
|
71
|
-
|
|
53
|
+
## License
|
|
54
|
+
|
|
55
|
+
MIT © [Richard Käll](http://richardkall.se)
|
|
@@ -15,7 +15,7 @@ Gem::Specification.new do |s|
|
|
|
15
15
|
s.files = `git ls-files`.split($/)
|
|
16
16
|
s.test_files = `git ls-files -- {spec}/*`.split("\n")
|
|
17
17
|
|
|
18
|
-
s.add_dependency 'rails', '
|
|
18
|
+
s.add_dependency 'rails', '>= 4.1.8'
|
|
19
19
|
|
|
20
20
|
s.add_development_dependency 'factory_girl_rails'
|
|
21
21
|
s.add_development_dependency 'sqlite3'
|
|
@@ -19,6 +19,9 @@ module ApiPaginationHeaders
|
|
|
19
19
|
|
|
20
20
|
def create_links(pages, scope)
|
|
21
21
|
url_without_params = request.url.split('?').first
|
|
22
|
+
if ApiPaginationHeaders.config.force_https
|
|
23
|
+
url_without_params.sub! 'http://', 'https://'
|
|
24
|
+
end
|
|
22
25
|
|
|
23
26
|
if params[:per_page]
|
|
24
27
|
per_page = params[:per_page].to_i
|
|
@@ -98,4 +98,16 @@ describe PostsController, '#index', type: :controller do
|
|
|
98
98
|
expect(response.headers['Link']).to eq("<#{posts_url(page: 2, per_page: 1, order: 'asc', format: :json)}>; rel=\"next\", <#{posts_url(page: 2, per_page: 1, order: 'asc', format: :json)}>; rel=\"last\"")
|
|
99
99
|
end
|
|
100
100
|
end
|
|
101
|
+
|
|
102
|
+
context 'when config has force_https set to true' do
|
|
103
|
+
it 'replaces http:// with https:// in Link header' do
|
|
104
|
+
ApiPaginationHeaders.config.force_https = true
|
|
105
|
+
FactoryGirl.create_list(:post, 2)
|
|
106
|
+
get :index, order: 'asc', format: :json
|
|
107
|
+
expect(response.headers['Link']).to match 'https://'
|
|
108
|
+
expect(response.headers['Link']).not_to match 'http://'
|
|
109
|
+
ApiPaginationHeaders.config.force_https = false
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
|
|
101
113
|
end
|
metadata
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: api_pagination_headers
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.0
|
|
4
|
+
version: 2.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Richard Käll
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2015-04-18 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rails
|
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
|
16
16
|
requirements:
|
|
17
|
-
- - "
|
|
17
|
+
- - ">="
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version:
|
|
19
|
+
version: 4.1.8
|
|
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: 4.1.8
|
|
27
27
|
- !ruby/object:Gem::Dependency
|
|
28
28
|
name: factory_girl_rails
|
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -159,7 +159,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
159
159
|
version: '0'
|
|
160
160
|
requirements: []
|
|
161
161
|
rubyforge_project:
|
|
162
|
-
rubygems_version: 2.4.
|
|
162
|
+
rubygems_version: 2.4.6
|
|
163
163
|
signing_key:
|
|
164
164
|
specification_version: 4
|
|
165
165
|
summary: Link header pagination for APIs
|