fetcheable_on_api 0.1.4 → 0.1.5

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
  SHA256:
3
- metadata.gz: 5eedb9e4ed066e00c70b68c6e40a66aab2908012657c2b290d717d5961fde978
4
- data.tar.gz: fe9d93cdf84b2d40bcca56b079a59ce5df8ab0ad43adcf7ea38b611d7aba2bcc
3
+ metadata.gz: fe1436fc856be39403a098964fd749c327d478b1cd4caa23776b030fa44dbb05
4
+ data.tar.gz: 382385b75448f082476ec23adfd4d360b5aa53b8a8cdfb072de4f1dcecf94d63
5
5
  SHA512:
6
- metadata.gz: 22189018b1660c830d13e46ab1f83fcf3b2f8e9a7d5a6e2807758e19f336bf4c2f04e5ff3715ff8551d1681360c1d5abf2d1c9e1541ee52cc178fa1020f5d8fc
7
- data.tar.gz: a265f51a961e07ec9ccedcbb51a22da4e2ffffd00a2aa056efbcf67f6c1357b95cfb3707b893b05c472c4092ee50529c392679afc0a55ae36f80f7b9a2b244a4
6
+ metadata.gz: 913c31f970e2a6592a0aeab78f4f2e64d37074c120782fff145a7766e1e62a1d6469cf3dc36ec20ff09ff06a98d9978ba035e6a63cebc8beccb71eb96e398e69
7
+ data.tar.gz: 9ea51948fc95741f8e751a1371de3f7cdee1ea725751cc814df1b5916ab7c9e09adbc096f84e23ef70e1a20ca3590ec3fa0f75b428a60704ef934ae3d14304b5
data/README.md CHANGED
@@ -253,6 +253,13 @@ $ curl -X GET \
253
253
  ]
254
254
  ```
255
255
 
256
+ When you use pagination, additional information is returned in the Header
257
+
258
+ - `Pagination-Current-Page`: the current page number
259
+ - `Pagination-Per`: the number of records per page
260
+ - `Pagination-Total-Pages`: the total number of pages
261
+ - `Pagination-Total-Count`: the total number of records
262
+
256
263
  ### Filtering
257
264
 
258
265
  The `filter` query parameter is reserved for filtering data and the controller must set the attributes allowed to be filtered.
@@ -45,6 +45,9 @@ module FetcheableOnApi
45
45
  protected
46
46
 
47
47
  def apply_filters(collection)
48
+ return collection unless valid_parameters?(params)
49
+ return collection unless valid_parameters?(params[:filter])
50
+
48
51
  return collection if params[:filter].blank?
49
52
 
50
53
  filter_params = params.require(:filter)
@@ -20,7 +20,9 @@ module FetcheableOnApi
20
20
  protected
21
21
 
22
22
  def apply_pagination(collection)
23
- return collection if params[:page].blank?
23
+ return collection unless valid_parameters?(params)
24
+ return collection unless valid_parameters?(params[:page])
25
+ return collection unless params[:page].present?
24
26
 
25
27
  limit = params[:page].fetch(
26
28
  :size,
@@ -48,6 +48,9 @@ module FetcheableOnApi
48
48
  protected
49
49
 
50
50
  def apply_sort(collection)
51
+ return collection unless valid_parameters?(params)
52
+ return collection unless valid_parameters?(params[:sort])
53
+
51
54
  return collection if params[:sort].blank?
52
55
 
53
56
  ordering = {}
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FetcheableOnApi
4
- VERSION = '0.1.4'.freeze
4
+ VERSION = '0.1.5'.freeze
5
5
  end
@@ -53,6 +53,11 @@ module FetcheableOnApi
53
53
 
54
54
  apply_pagination(collection)
55
55
  end
56
+
57
+ def valid_parameters?(parameters)
58
+ parameters.is_a?(ActionController::Parameters) ||
59
+ parameters.is_a?(Hash)
60
+ end
56
61
  end
57
62
 
58
63
  ActiveSupport.on_load :action_controller do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fetcheable_on_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fabien
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-11-19 00:00:00.000000000 Z
11
+ date: 2018-11-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport