grape-kaminari 0.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 +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +72 -0
- data/Rakefile +1 -0
- data/grape-kaminari.gemspec +27 -0
- data/lib/grape/kaminari/version.rb +5 -0
- data/lib/grape/kaminari.rb +31 -0
- data/lib/grape-kaminari.rb +1 -0
- metadata +109 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: f7a8c5230ae29829672e54245091c948c65b12be
|
|
4
|
+
data.tar.gz: 3d43e68afdbebfc4987eebb206296c376d8a3abb
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 1bded3a46f9aa34a8006b1941a4a5d6ab4b47a9c2ef6c88889cc28adfdcde5bae158b43d517042da1031929d3882933d3b7a54a4ee41c7ce22d2eabaa1b977bc
|
|
7
|
+
data.tar.gz: 2024105c17eed72397afad38716b771425ae7de82bb1f2f341870bc3617d4facc95afbf640e1d00403371c8c377b5660f7fe8815d2d8e5eb1ec6b6175872c167
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2013 Monterail.com
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# Grape::Kaminari
|
|
2
|
+
|
|
3
|
+
[kaminari](https://github.com/amatsuda/kaminari) paginator integration for [grape](https://github.com/intridea/grape) API framework.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add this line to your application's Gemfile:
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
10
|
+
gem 'grape-kaminari'
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
And then execute:
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
$ bundle
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Or install it yourself as:
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
$ gem install grape-kaminari
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Usage
|
|
26
|
+
|
|
27
|
+
```ruby
|
|
28
|
+
class MyApi < Grape::API
|
|
29
|
+
# Include Grape::Kaminari module in your api
|
|
30
|
+
include Grape::Kaminari
|
|
31
|
+
|
|
32
|
+
resource :posts do
|
|
33
|
+
desc 'Return a list of posts.'
|
|
34
|
+
|
|
35
|
+
# Annotate action with `paginate`.
|
|
36
|
+
# This will add two optional params: page and per_page
|
|
37
|
+
# You can optionally overwrite the default :per_page setting (10)
|
|
38
|
+
paginate :per_page => 20
|
|
39
|
+
|
|
40
|
+
get do
|
|
41
|
+
posts = Post.where(...)
|
|
42
|
+
|
|
43
|
+
# Use `paginate` helper to execute kaminari methods
|
|
44
|
+
# with arguments automatically passed from params
|
|
45
|
+
paginate(posts)
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Now you can make a HTTP request to you are endpoint with `page` (and `per_page`) params
|
|
52
|
+
|
|
53
|
+
```
|
|
54
|
+
curl -v http://host.dev/api/posts?page=3
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
and the response wil be paginated and also will include pagination headers
|
|
58
|
+
|
|
59
|
+
```
|
|
60
|
+
X-Total: 42
|
|
61
|
+
X-Total-Pages: 5
|
|
62
|
+
X-Page: 3
|
|
63
|
+
X-Per-Page: 10
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Contributing
|
|
67
|
+
|
|
68
|
+
1. Fork it
|
|
69
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
70
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
71
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
|
72
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require "bundler/gem_tasks"
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'grape/kaminari/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "grape-kaminari"
|
|
8
|
+
spec.version = Grape::Kaminari::VERSION
|
|
9
|
+
spec.authors = ["Tymon Tobolski"]
|
|
10
|
+
spec.email = ["tymon.tobolski@monterail.com"]
|
|
11
|
+
spec.description = %q{kaminari paginator integration for grape API framework}
|
|
12
|
+
spec.summary = %q{kaminari integration for grape}
|
|
13
|
+
spec.homepage = ""
|
|
14
|
+
spec.license = "MIT"
|
|
15
|
+
|
|
16
|
+
spec.files = `git ls-files`.split($/)
|
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
19
|
+
spec.require_paths = ["lib"]
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
spec.add_runtime_dependency "grape"
|
|
23
|
+
spec.add_runtime_dependency "kaminari"
|
|
24
|
+
|
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
|
26
|
+
spec.add_development_dependency "rake"
|
|
27
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
require "grape/kaminari/version"
|
|
2
|
+
require "kaminari/grape"
|
|
3
|
+
|
|
4
|
+
module Grape
|
|
5
|
+
module Kaminari
|
|
6
|
+
def self.included(base)
|
|
7
|
+
base.class_eval do
|
|
8
|
+
helpers do
|
|
9
|
+
def paginate(collection)
|
|
10
|
+
collection.page(params[:page]).per(params[:per_page]).tap do |data|
|
|
11
|
+
header "X-Total", data.total_count.to_s
|
|
12
|
+
header "X-Total-Pages", data.num_pages.to_s
|
|
13
|
+
header "X-Page", data.current_page.to_s
|
|
14
|
+
header "X-Per-Page", params[:per_page].to_s
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def self.paginate(options = {})
|
|
20
|
+
options.reverse_merge!(per_page: 10)
|
|
21
|
+
params do
|
|
22
|
+
optional :page, type: Integer, default: 1,
|
|
23
|
+
desc: 'Page offset to fetch.'
|
|
24
|
+
optional :per_page, type: Integer, default: options[:per_page],
|
|
25
|
+
desc: 'Number of results to return per page.'
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require "grape/kaminari"
|
metadata
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: grape-kaminari
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Tymon Tobolski
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2013-12-06 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: grape
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - '>='
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '0'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - '>='
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '0'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: kaminari
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - '>='
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0'
|
|
34
|
+
type: :runtime
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - '>='
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: bundler
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - ~>
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '1.3'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - ~>
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '1.3'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: rake
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - '>='
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '0'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - '>='
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '0'
|
|
69
|
+
description: kaminari paginator integration for grape API framework
|
|
70
|
+
email:
|
|
71
|
+
- tymon.tobolski@monterail.com
|
|
72
|
+
executables: []
|
|
73
|
+
extensions: []
|
|
74
|
+
extra_rdoc_files: []
|
|
75
|
+
files:
|
|
76
|
+
- .gitignore
|
|
77
|
+
- Gemfile
|
|
78
|
+
- LICENSE.txt
|
|
79
|
+
- README.md
|
|
80
|
+
- Rakefile
|
|
81
|
+
- grape-kaminari.gemspec
|
|
82
|
+
- lib/grape-kaminari.rb
|
|
83
|
+
- lib/grape/kaminari.rb
|
|
84
|
+
- lib/grape/kaminari/version.rb
|
|
85
|
+
homepage: ''
|
|
86
|
+
licenses:
|
|
87
|
+
- MIT
|
|
88
|
+
metadata: {}
|
|
89
|
+
post_install_message:
|
|
90
|
+
rdoc_options: []
|
|
91
|
+
require_paths:
|
|
92
|
+
- lib
|
|
93
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
94
|
+
requirements:
|
|
95
|
+
- - '>='
|
|
96
|
+
- !ruby/object:Gem::Version
|
|
97
|
+
version: '0'
|
|
98
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
99
|
+
requirements:
|
|
100
|
+
- - '>='
|
|
101
|
+
- !ruby/object:Gem::Version
|
|
102
|
+
version: '0'
|
|
103
|
+
requirements: []
|
|
104
|
+
rubyforge_project:
|
|
105
|
+
rubygems_version: 2.1.11
|
|
106
|
+
signing_key:
|
|
107
|
+
specification_version: 4
|
|
108
|
+
summary: kaminari integration for grape
|
|
109
|
+
test_files: []
|