api_pagination_headers 2.0.1 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 71e7a44f98f5f3f27c7f0631163945f1865fdcc8
4
- data.tar.gz: 3149cda9b4c6c12493b9a3f03c0ae2a545964d41
3
+ metadata.gz: bbc1bb209392610ed0cbdb2e6c8f1acad4c345ea
4
+ data.tar.gz: 12da3da8f08069065e7d2b9c65049c0790926870
5
5
  SHA512:
6
- metadata.gz: ee1d49d47f3ea87e6ccebfb0db2742a67530a10b55de1e7625dda439cf2ce53bb5a560ef0528a1ad89792faf27aa6ce9c0ff7a2517a630de5fabb2ba51d1120d
7
- data.tar.gz: 1c0a1ff5fdd4fbe9686190c0b84588e194ea1164a2f2907e4727e4dd4ceda79811f025f35fd5e8e661ac2a3f38208bc182fe8569a575aa7dfe7d82cc14e9de6c
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.0.0)
5
- rails (~> 4.1)
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.6)
11
- actionpack (= 4.1.6)
12
- actionview (= 4.1.6)
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
- actionpack (4.1.6)
15
- actionview (= 4.1.6)
16
- activesupport (= 4.1.6)
17
- rack (~> 1.5.2)
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
- actionview (4.1.6)
20
- activesupport (= 4.1.6)
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
- activemodel (4.1.6)
24
- activesupport (= 4.1.6)
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.6)
27
- activemodel (= 4.1.6)
28
- activesupport (= 4.1.6)
29
- arel (~> 5.0.0)
30
- activesupport (4.1.6)
31
- i18n (~> 0.6, >= 0.6.9)
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.1)
43
+ thread_safe (~> 0.3, >= 0.3.4)
35
44
  tzinfo (~> 1.1)
36
- arel (5.0.1.20140414130214)
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
- hike (1.2.3)
46
- i18n (0.6.11)
47
- json (1.8.1)
48
- kaminari (0.16.1)
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
- mail (2.6.1)
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
- minitest (5.4.2)
55
- multi_json (1.10.1)
56
- rack (1.5.2)
57
- rack-test (0.6.2)
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.6)
60
- actionmailer (= 4.1.6)
61
- actionpack (= 4.1.6)
62
- actionview (= 4.1.6)
63
- activemodel (= 4.1.6)
64
- activerecord (= 4.1.6)
65
- activesupport (= 4.1.6)
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.6)
68
- sprockets-rails (~> 2.0)
69
- railties (4.1.6)
70
- actionpack (= 4.1.6)
71
- activesupport (= 4.1.6)
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.3.2)
75
- rspec-core (3.1.7)
76
- rspec-support (~> 3.1.0)
77
- rspec-expectations (3.1.2)
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.1.0)
80
- rspec-mocks (3.1.3)
81
- rspec-support (~> 3.1.0)
82
- rspec-rails (3.1.0)
83
- actionpack (>= 3.0)
84
- activesupport (>= 3.0)
85
- railties (>= 3.0)
86
- rspec-core (~> 3.1.0)
87
- rspec-expectations (~> 3.1.0)
88
- rspec-mocks (~> 3.1.0)
89
- rspec-support (~> 3.1.0)
90
- rspec-support (3.1.2)
91
- sprockets (2.12.2)
92
- hike (~> 1.2)
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
- tilt (~> 1.1, != 1.3.0)
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.9)
121
+ sqlite3 (1.3.10)
101
122
  thor (0.19.1)
102
- thread_safe (0.3.4)
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
- Copyright 2014 Richard Käll
1
+ The MIT License (MIT)
2
2
 
3
- Permission is hereby granted, free of charge, to any person obtaining
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
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
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
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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 [![Build Status](https://travis-ci.org/richardkall/api_pagination_headers.svg)](http://travis-ci.org/richardkall/api_pagination_headers) [![Dependency Status](https://gemnasium.com/richardkall/api_pagination_headers.png)](https://gemnasium.com/richardkall/api_pagination_headers)
1
+ #api_pagination_headers [![Build Status](https://travis-ci.org/richardkall/api_pagination_headers.svg)](http://travis-ci.org/richardkall/api_pagination_headers) [![Dependency Status](https://gemnasium.com/richardkall/api_pagination_headers.svg)](https://gemnasium.com/richardkall/api_pagination_headers)
2
2
 
3
- api_pagination_headers is a gem that adds pagination info to a `Link` response header. This is considered to be the [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). It also adds the total number of records into a `Total-Count` header.
3
+ > Adds pagination info to a `Link` response header.
4
4
 
5
- Example:
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
- ##Installation
13
-
14
- Include in your Gemfile:
16
+ ## Requirements
15
17
 
16
- * Rails 4
18
+ - [Kaminari](https://github.com/amatsuda/kaminari) or [will_paginate](https://github.com/mislav/will_paginate)
17
19
 
18
- ```ruby
19
- gem 'api_pagination_headers'
20
- ```
20
+ ## Install
21
21
 
22
- * Rails 3.2
22
+ Include in your Gemfile:
23
23
 
24
24
  ```ruby
25
- gem 'api_pagination_headers', branch: 'rails-3-2'
25
+ gem 'api_pagination_headers'
26
26
  ```
27
27
 
28
- Depending on [Kaminari](https://github.com/amatsuda/kaminari) or [will_paginate](https://github.com/mislav/will_paginate) at the moment. Support for [rails-api](https://github.com/rails-api/rails-api) is built in.
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
- * Rails 3.2
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
- Copyright © 2014 [Richard Käll](http://richardkall.se). Licensed under the MIT license.
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', '~> 4.1'
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
@@ -20,5 +20,6 @@ module ApiPaginationHeaders
20
20
  TOTAL_COUNT_HEADER = 'Total-Count'
21
21
 
22
22
  config_accessor(:total_count_header) { TOTAL_COUNT_HEADER }
23
+ config_accessor(:force_https) { false }
23
24
  end
24
25
  end
@@ -1,3 +1,3 @@
1
1
  module ApiPaginationHeaders
2
- VERSION = '2.0.1'
2
+ VERSION = '2.1.0'
3
3
  end
@@ -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
@@ -1,3 +1,2 @@
1
1
  class ApplicationController < ActionController::Base
2
- respond_to :json
3
2
  end
@@ -3,6 +3,6 @@ class CommentsController < ApplicationController
3
3
 
4
4
  def index
5
5
  @comments = Comment.all.paginate(per_page: params[:per_page], page: params[:page])
6
- respond_with @comments
6
+ render json: @comments
7
7
  end
8
8
  end
@@ -3,6 +3,6 @@ class PostsController < ApplicationController
3
3
 
4
4
  def index
5
5
  @posts = Post.all.paginate(per_page: params[:per_page], page: params[:page])
6
- respond_with @posts
6
+ render json: @posts
7
7
  end
8
8
  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.1
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: 2014-10-27 00:00:00.000000000 Z
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: '4.1'
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: '4.1'
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.2
162
+ rubygems_version: 2.4.6
163
163
  signing_key:
164
164
  specification_version: 4
165
165
  summary: Link header pagination for APIs