grape-kaminari 0.1.3 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -2
- data/lib/grape/kaminari.rb +3 -1
- data/lib/grape/kaminari/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b08eab293223b2ad7369fe8c005894a97d6a674a
|
4
|
+
data.tar.gz: bb86d66fc3b9e8b013d9c34f0de183bcdb84a01b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e293e4e23a6d4ba7c3e024fa0112c2c012add6efe86ec578a581887a40a9b42b6c8776d9b19f30790ae0a447898860faf6c3595b55e552d53c63e322db93e0c4
|
7
|
+
data.tar.gz: 0c1330a4d198b4221c7c5a88924dabb678c467055afb118bdd3b3087b98316178d8eb37a4900be6890609503dc05aa57f4a67f3c18c38bdc10cc9a8e525b176f
|
data/README.md
CHANGED
@@ -50,10 +50,14 @@ class MyApi < Grape::API
|
|
50
50
|
end
|
51
51
|
```
|
52
52
|
|
53
|
-
Now you can make a HTTP request to your endpoint with
|
53
|
+
Now you can make a HTTP request to your endpoint with the following parameters
|
54
|
+
|
55
|
+
- `page`: your current page (default: 1)
|
56
|
+
- `per_page`: how many to record in a page (default: 10)
|
57
|
+
- `offset`: the offset to start from (default: 0)
|
54
58
|
|
55
59
|
```
|
56
|
-
curl -v http://host.dev/api/posts?page=3
|
60
|
+
curl -v http://host.dev/api/posts?page=3&offset=10
|
57
61
|
```
|
58
62
|
|
59
63
|
and the response will be paginated and also will include pagination headers
|
@@ -65,6 +69,7 @@ X-Page: 3
|
|
65
69
|
X-Per-Page: 10
|
66
70
|
X-Next-Page: 4
|
67
71
|
X-Prev-Page: 2
|
72
|
+
X-Offset: 10
|
68
73
|
```
|
69
74
|
|
70
75
|
## Contributing
|
data/lib/grape/kaminari.rb
CHANGED
@@ -8,13 +8,14 @@ module Grape
|
|
8
8
|
base.class_eval do
|
9
9
|
helpers do
|
10
10
|
def paginate(collection)
|
11
|
-
collection.page(params[:page]).per(params[:per_page]).tap do |data|
|
11
|
+
collection.page(params[:page]).per(params[:per_page]).padding(params[:offset]).tap do |data|
|
12
12
|
header "X-Total", data.total_count.to_s
|
13
13
|
header "X-Total-Pages", data.num_pages.to_s
|
14
14
|
header "X-Per-Page", params[:per_page].to_s
|
15
15
|
header "X-Page", data.current_page.to_s
|
16
16
|
header "X-Next-Page", data.next_page.to_s
|
17
17
|
header "X-Prev-Page", data.prev_page.to_s
|
18
|
+
header "X-Offset", params[:offset].to_s
|
18
19
|
end
|
19
20
|
end
|
20
21
|
end
|
@@ -30,6 +31,7 @@ module Grape
|
|
30
31
|
optional :per_page, type: Integer, default: options[:per_page],
|
31
32
|
desc: 'Number of results to return per page.',
|
32
33
|
max_value: options[:max_per_page]
|
34
|
+
optional :offset, type: Integer, default: 0
|
33
35
|
end
|
34
36
|
end
|
35
37
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grape-kaminari
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tymon Tobolski
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-06-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: grape
|