api_pagination_headers 1.1.1 → 1.1.2

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: 374afc4499dc9a5ee0ccb5e5bddcca51cfbd053b
4
- data.tar.gz: 206cc6c5517388e2fbed65c2757ae94a0a03a81f
3
+ metadata.gz: 7ea795c955eb559b1674f3e3512dde05644be6b4
4
+ data.tar.gz: e858bfccf5f408d91364daf0c09863ee6d6e0426
5
5
  SHA512:
6
- metadata.gz: d51b26e2bd2d30c3f5a6256bd3410111df837700707a0a03405441e0edeaaf6b5febfa544be00cbafe7b3b355bbb7f05d7418eff43ecbcf98b2a07ba483e9ab9
7
- data.tar.gz: 6bec58a194f0638ef434621da26aecd7852b33a6e38b71d0cd64f7a9a70a62ef30680eb247908fc37ce6404559e59dc382eb8dabd9812359da9e5ed08a2143c1
6
+ metadata.gz: 8be7d78b0599c5d67a1bb821916e8aeec24ef75cc3879848a6019773ab0c43e35620b4685d5aca40c3d3102a0b42032834eac3cb02463dccdc4d258f85425918
7
+ data.tar.gz: 32bcd099e63d6d79fd378c0040f3a57b74ef83db8a513e907f8b0fb8cb5fe5fe1b9b170bf6cdaa936999ca7dc254eae0e204b82124e497cf9176818c517915b0
data/Gemfile.lock CHANGED
@@ -1,102 +1,101 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- api_pagination_headers (1.1.0)
5
- rails (~> 4.0.0)
4
+ api_pagination_headers (1.1.2)
5
+ rails (~> 4.0)
6
6
  will_paginate (~> 3.0.5)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- actionmailer (4.0.0)
12
- actionpack (= 4.0.0)
13
- mail (~> 2.5.3)
14
- actionpack (4.0.0)
15
- activesupport (= 4.0.0)
11
+ actionmailer (4.0.4)
12
+ actionpack (= 4.0.4)
13
+ mail (~> 2.5.4)
14
+ actionpack (4.0.4)
15
+ activesupport (= 4.0.4)
16
16
  builder (~> 3.1.0)
17
17
  erubis (~> 2.7.0)
18
18
  rack (~> 1.5.2)
19
19
  rack-test (~> 0.6.2)
20
- activemodel (4.0.0)
21
- activesupport (= 4.0.0)
20
+ activemodel (4.0.4)
21
+ activesupport (= 4.0.4)
22
22
  builder (~> 3.1.0)
23
- activerecord (4.0.0)
24
- activemodel (= 4.0.0)
23
+ activerecord (4.0.4)
24
+ activemodel (= 4.0.4)
25
25
  activerecord-deprecated_finders (~> 1.0.2)
26
- activesupport (= 4.0.0)
26
+ activesupport (= 4.0.4)
27
27
  arel (~> 4.0.0)
28
28
  activerecord-deprecated_finders (1.0.3)
29
- activesupport (4.0.0)
30
- i18n (~> 0.6, >= 0.6.4)
29
+ activesupport (4.0.4)
30
+ i18n (~> 0.6, >= 0.6.9)
31
31
  minitest (~> 4.2)
32
32
  multi_json (~> 1.3)
33
33
  thread_safe (~> 0.1)
34
34
  tzinfo (~> 0.3.37)
35
- arel (4.0.0)
36
- atomic (1.1.14)
35
+ arel (4.0.2)
37
36
  builder (3.1.4)
38
- diff-lcs (1.2.4)
37
+ diff-lcs (1.2.5)
39
38
  erubis (2.7.0)
40
- factory_girl (4.2.0)
39
+ factory_girl (4.4.0)
41
40
  activesupport (>= 3.0.0)
42
- factory_girl_rails (4.2.1)
43
- factory_girl (~> 4.2.0)
41
+ factory_girl_rails (4.4.1)
42
+ factory_girl (~> 4.4.0)
44
43
  railties (>= 3.0.0)
45
44
  hike (1.2.3)
46
- i18n (0.6.5)
45
+ i18n (0.6.9)
47
46
  mail (2.5.4)
48
47
  mime-types (~> 1.16)
49
48
  treetop (~> 1.4.8)
50
- mime-types (1.25)
49
+ mime-types (1.25.1)
51
50
  minitest (4.7.5)
52
- multi_json (1.8.0)
53
- polyglot (0.3.3)
51
+ multi_json (1.9.2)
52
+ polyglot (0.3.4)
54
53
  rack (1.5.2)
55
54
  rack-test (0.6.2)
56
55
  rack (>= 1.0)
57
- rails (4.0.0)
58
- actionmailer (= 4.0.0)
59
- actionpack (= 4.0.0)
60
- activerecord (= 4.0.0)
61
- activesupport (= 4.0.0)
56
+ rails (4.0.4)
57
+ actionmailer (= 4.0.4)
58
+ actionpack (= 4.0.4)
59
+ activerecord (= 4.0.4)
60
+ activesupport (= 4.0.4)
62
61
  bundler (>= 1.3.0, < 2.0)
63
- railties (= 4.0.0)
62
+ railties (= 4.0.4)
64
63
  sprockets-rails (~> 2.0.0)
65
- railties (4.0.0)
66
- actionpack (= 4.0.0)
67
- activesupport (= 4.0.0)
64
+ railties (4.0.4)
65
+ actionpack (= 4.0.4)
66
+ activesupport (= 4.0.4)
68
67
  rake (>= 0.8.7)
69
68
  thor (>= 0.18.1, < 2.0)
70
- rake (10.1.0)
71
- rspec-core (2.14.5)
72
- rspec-expectations (2.14.3)
69
+ rake (10.2.2)
70
+ rspec-core (2.14.8)
71
+ rspec-expectations (2.14.5)
73
72
  diff-lcs (>= 1.1.3, < 2.0)
74
- rspec-mocks (2.14.3)
75
- rspec-rails (2.14.0)
73
+ rspec-mocks (2.14.6)
74
+ rspec-rails (2.14.2)
76
75
  actionpack (>= 3.0)
76
+ activemodel (>= 3.0)
77
77
  activesupport (>= 3.0)
78
78
  railties (>= 3.0)
79
79
  rspec-core (~> 2.14.0)
80
80
  rspec-expectations (~> 2.14.0)
81
81
  rspec-mocks (~> 2.14.0)
82
- sprockets (2.10.0)
82
+ sprockets (2.12.0)
83
83
  hike (~> 1.2)
84
84
  multi_json (~> 1.0)
85
85
  rack (~> 1.0)
86
86
  tilt (~> 1.1, != 1.3.0)
87
- sprockets-rails (2.0.0)
87
+ sprockets-rails (2.0.1)
88
88
  actionpack (>= 3.0)
89
89
  activesupport (>= 3.0)
90
90
  sprockets (~> 2.8)
91
- sqlite3 (1.3.8)
92
- thor (0.18.1)
93
- thread_safe (0.1.3)
94
- atomic
91
+ sqlite3 (1.3.9)
92
+ thor (0.19.1)
93
+ thread_safe (0.3.2)
95
94
  tilt (1.4.1)
96
95
  treetop (1.4.15)
97
96
  polyglot
98
97
  polyglot (>= 0.3.1)
99
- tzinfo (0.3.37)
98
+ tzinfo (0.3.39)
100
99
  will_paginate (3.0.5)
101
100
 
102
101
  PLATFORMS
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2013 Richard Käll
1
+ Copyright 2014 Richard Käll
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,5 +1,4 @@
1
- #api_pagination_headers
2
- [![Build Status](https://travis-ci.org/richardkall/api_pagination_headers.png)](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) [![Code Climate](https://codeclimate.com/github/richardkall/api_pagination_headers.png)](https://codeclimate.com/github/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.png)](https://gemnasium.com/richardkall/api_pagination_headers)
3
2
 
4
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 `X-Total-Count` header.
5
4
 
@@ -18,9 +17,7 @@ Include in your Gemfile:
18
17
  gem 'api_pagination_headers'
19
18
  ```
20
19
 
21
- Depending on [will_paginate](https://github.com/mislav/will_paginate) at the moment.
22
-
23
- Support for [rails-api](https://github.com/rails-api/rails-api) is built in.
20
+ Depending on [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.
24
21
 
25
22
  ##Usage
26
23
 
@@ -37,13 +34,5 @@ class PostsController < ApplicationController
37
34
  end
38
35
  ```
39
36
 
40
- ##Contributing
41
-
42
- 1. Fork it
43
- 2. Create your feature branch (`git checkout -b my-new-feature`)
44
- 3. Commit your changes (`git commit -am 'Add some feature'`)
45
- 4. Push to the branch (`git push origin my-new-feature`)
46
- 5. Create a new Pull Request
47
-
48
37
  ##License
49
- Copyright © 2013 [Richard Käll](http://richardkall.se). Licensed under the MIT license.
38
+ Copyright © 2014 [Richard Käll](http://richardkall.se). Licensed under the MIT license.
@@ -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.0.0'
18
+ s.add_dependency 'rails', '~> 4.0'
19
19
  s.add_dependency 'will_paginate', '~> 3.0.5'
20
20
 
21
21
  s.add_development_dependency 'factory_girl_rails'
@@ -4,7 +4,7 @@ module ApiPaginationHeaders
4
4
  def set_pagination_headers(name)
5
5
  scope = instance_variable_get("@#{name}")
6
6
  pages = set_page_numbers(scope)
7
- links = create_links(pages)
7
+ links = create_links(pages, scope)
8
8
 
9
9
  headers['Link'] = links.join(', ') unless links.empty?
10
10
  headers['X-Total-Count'] = "#{scope.total_entries}"
@@ -12,9 +12,9 @@ module ApiPaginationHeaders
12
12
 
13
13
  private
14
14
 
15
- def create_links(pages)
15
+ def create_links(pages, scope)
16
16
  url_without_params = request.url.split('?').first
17
- per_page = params[:per_page] ? params[:per_page].to_i : WillPaginate.per_page
17
+ per_page = params[:per_page] ? params[:per_page].to_i : scope.per_page
18
18
  links = []
19
19
  pages.each do |key, value|
20
20
  new_params = request.query_parameters.merge({ page: value, per_page: per_page })
@@ -1,3 +1,3 @@
1
1
  module ApiPaginationHeaders
2
- VERSION = '1.1.1'
2
+ VERSION = '1.1.2'
3
3
  end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe CommentsController, '#index' do
4
+ context 'when model has per_page attribute' do
5
+ it 'overrides WillPaginate default' do
6
+ FactoryGirl.create_list(:comment, 4)
7
+ get :index, format: :json
8
+ expect(response.headers['Link']).to eq("<#{comments_url(page: 2, per_page: 2, format: :json)}>; rel=\"next\", <#{comments_url(page: 2, per_page: 2, format: :json)}>; rel=\"last\"")
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,8 @@
1
+ class CommentsController < ApplicationController
2
+ after_action only: [:index] { set_pagination_headers(:comments) }
3
+
4
+ def index
5
+ @comments = Comment.all.paginate(per_page: params[:per_page], page: params[:page])
6
+ respond_with @comments
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ class Comment < ActiveRecord::Base
2
+ self.per_page = 2
3
+ end
@@ -1,3 +1,4 @@
1
1
  Dummy::Application.routes.draw do
2
2
  resources :posts
3
+ resources :comments
3
4
  end
@@ -0,0 +1,7 @@
1
+ class CreateComments < ActiveRecord::Migration
2
+ def change
3
+ create_table :comments do |t|
4
+ t.string :content
5
+ end
6
+ end
7
+ end
@@ -11,10 +11,14 @@
11
11
  #
12
12
  # It's strongly recommended that you check this file into your version control system.
13
13
 
14
- ActiveRecord::Schema.define(version: 20131001123917) do
14
+ ActiveRecord::Schema.define(version: 20140406141645) do
15
+
16
+ create_table "comments", force: true do |t|
17
+ t.string "content"
18
+ end
15
19
 
16
20
  create_table "posts", force: true do |t|
17
- t.string "content"
21
+ t.string "content"
18
22
  end
19
23
 
20
24
  end
@@ -0,0 +1,5 @@
1
+ FactoryGirl.define do
2
+ factory :comment do
3
+ sequence(:content) { |n| "Comment number #{n}" }
4
+ end
5
+ end
data/spec/spec_helper.rb CHANGED
@@ -11,6 +11,7 @@ RSpec.configure do |config|
11
11
  config.include Rails.application.routes.url_helpers
12
12
 
13
13
  config.after(:each) do
14
+ Comment.destroy_all
14
15
  Post.destroy_all
15
16
  end
16
17
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: api_pagination_headers
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
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: 2013-10-04 00:00:00.000000000 Z
11
+ date: 2014-04-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 4.0.0
19
+ version: '4.0'
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.0.0
26
+ version: '4.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: will_paginate
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -97,11 +97,14 @@ files:
97
97
  - api_pagination_headers.gemspec
98
98
  - lib/api_pagination_headers.rb
99
99
  - lib/api_pagination_headers/version.rb
100
+ - spec/controllers/comments_controller_spec.rb
100
101
  - spec/controllers/posts_controller_spec.rb
101
102
  - spec/dummy/Rakefile
102
103
  - spec/dummy/app/controllers/application_controller.rb
104
+ - spec/dummy/app/controllers/comments_controller.rb
103
105
  - spec/dummy/app/controllers/posts_controller.rb
104
106
  - spec/dummy/app/models/.keep
107
+ - spec/dummy/app/models/comment.rb
105
108
  - spec/dummy/app/models/post.rb
106
109
  - spec/dummy/bin/bundle
107
110
  - spec/dummy/bin/rails
@@ -116,7 +119,9 @@ files:
116
119
  - spec/dummy/config/initializers/session_store.rb
117
120
  - spec/dummy/config/routes.rb
118
121
  - spec/dummy/db/migrate/20131001123917_create_posts.rb
122
+ - spec/dummy/db/migrate/20140406141645_create_comments.rb
119
123
  - spec/dummy/db/schema.rb
124
+ - spec/factories/comments.rb
120
125
  - spec/factories/posts.rb
121
126
  - spec/spec_helper.rb
122
127
  homepage: https://github.com/richardkall/api_pagination_headers
@@ -139,7 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
144
  version: '0'
140
145
  requirements: []
141
146
  rubyforge_project:
142
- rubygems_version: 2.0.3
147
+ rubygems_version: 2.2.2
143
148
  signing_key:
144
149
  specification_version: 4
145
150
  summary: Link header pagination for APIs