api_helper 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -2
- data/lib/api_helper/paginatable.rb +41 -4
- data/lib/api_helper/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9efe86fda7179ba792ecf18057ebf0b1445d7f83
|
4
|
+
data.tar.gz: 9f17ca34299833efa46df0e68a1f75d1470d269b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fcfd8f2af69946d843ebfd2f0579ef44f8db74b816c9a6843df7fd5cdb95565b8f93a3f5767b195089cec00f5b0a9894f7cf69300c133fb1116da37a43f4118b
|
7
|
+
data.tar.gz: eb80f9bd80df82e8ae784b4b4a368c39c47d63ce16a910025d225d3197af26501d3e0e8bfff7be5cfe9ab002d62ba3c022fed09487dd4d1d10ae3671075ee5e6
|
data/.travis.yml
CHANGED
@@ -94,21 +94,34 @@ module APIHelper::Paginatable
|
|
94
94
|
pages_count = (items_count.to_f / @pagination_per_page).ceil
|
95
95
|
pages_count = 1 if pages_count < 1
|
96
96
|
|
97
|
+
@pagination_items_count = items_count
|
98
|
+
@pagination_pages_count = pages_count
|
99
|
+
|
97
100
|
@pagination_page = (params[:page] || 1).to_i
|
98
101
|
@pagination_page = pages_count if @pagination_page > pages_count
|
99
102
|
@pagination_page = 1 if @pagination_page < 1
|
100
103
|
|
104
|
+
if current_page > 1
|
105
|
+
@pagination_first_page_url = add_or_replace_uri_param(request.url, :page, 1)
|
106
|
+
@pagination_prev_page_url = add_or_replace_uri_param(request.url, :page, (current_page > pages_count ? pages_count : current_page - 1))
|
107
|
+
end
|
108
|
+
|
109
|
+
if current_page < pages_count
|
110
|
+
@pagination_next_page_url = add_or_replace_uri_param(request.url, :page, current_page + 1)
|
111
|
+
@pagination_last_page_url = add_or_replace_uri_param(request.url, :page, pages_count)
|
112
|
+
end
|
113
|
+
|
101
114
|
if set_header
|
102
115
|
link_headers ||= []
|
103
116
|
|
104
117
|
if current_page > 1
|
105
|
-
link_headers << "<#{
|
106
|
-
link_headers << "<#{
|
118
|
+
link_headers << "<#{@pagination_first_page_url}>; rel=\"first\"" if @pagination_first_page_url
|
119
|
+
link_headers << "<#{@pagination_prev_page_url}>; rel=\"prev\"" if @pagination_prev_page_url
|
107
120
|
end
|
108
121
|
|
109
122
|
if current_page < pages_count
|
110
|
-
link_headers << "<#{
|
111
|
-
link_headers << "<#{
|
123
|
+
link_headers << "<#{@pagination_next_page_url}>; rel=\"next\"" if @pagination_next_page_url
|
124
|
+
link_headers << "<#{@pagination_last_page_url}>; rel=\"last\"" if @pagination_last_page_url
|
112
125
|
end
|
113
126
|
|
114
127
|
link_header = link_headers.join(', ')
|
@@ -139,6 +152,30 @@ module APIHelper::Paginatable
|
|
139
152
|
@pagination_per_page
|
140
153
|
end
|
141
154
|
|
155
|
+
def pagination_items_count
|
156
|
+
@pagination_items_count
|
157
|
+
end
|
158
|
+
|
159
|
+
def pagination_pages_count
|
160
|
+
@pagination_pages_count
|
161
|
+
end
|
162
|
+
|
163
|
+
def pagination_first_page_url
|
164
|
+
@pagination_first_page_url
|
165
|
+
end
|
166
|
+
|
167
|
+
def pagination_prev_page_url
|
168
|
+
@pagination_prev_page_url
|
169
|
+
end
|
170
|
+
|
171
|
+
def pagination_next_page_url
|
172
|
+
@pagination_next_page_url
|
173
|
+
end
|
174
|
+
|
175
|
+
def pagination_last_page_url
|
176
|
+
@pagination_last_page_url
|
177
|
+
end
|
178
|
+
|
142
179
|
alias_method :paginate_with, :pagination_per_page
|
143
180
|
|
144
181
|
def add_or_replace_uri_param(url, param_name, param_value) # :nodoc:
|
data/lib/api_helper/version.rb
CHANGED