captive-api 1.1.0 → 1.2.1
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ab12a1c792bf550f36961f83688c299f75a9d6bc1153ef850aa5448be4283ec0
|
4
|
+
data.tar.gz: 72a79ff779a827484909877dc99b678a92315e35cd720b71950b34ffeb454780
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 78a473ad837f0851c115b3868bf031d70dfec945f643d43348bd8de26fd04a8154e41bf8dd9cc9209cdd61c39807374851f0096da100c6d6e9f76b3b43edae3c
|
7
|
+
data.tar.gz: 20e6fd708d8f5fa147588553eaec6b8049e5dae6bd58e614a8da2acb2fc3f60a74228647a9ea89d186de2a74f289de08e735928e5cd3a74513162f1df30f598a
|
data/README.md
CHANGED
@@ -27,6 +27,31 @@ The class `Captive::Api::ApplicationController` includes 2 concerns :
|
|
27
27
|
| [pagination](https://github.com/Captive-Studio/captive-api/blob/main/app/controllers/concerns/api/pagination_concern.rb) | Logique de pagination pour les index |
|
28
28
|
| [render error](https://github.com/Captive-Studio/captive-api/blob/main/app/controllers/concerns/api/render_error_concern.rb) | Attrape certaines erreurs pour retourner une page d'erreur en json. Permet aussi d'utiliser les méthodes pour rendre des pages d'erreur json manuellement |
|
29
29
|
|
30
|
+
### PaginationConcern
|
31
|
+
|
32
|
+
#### `#pagination`
|
33
|
+
|
34
|
+
You can use the pagination method like this :
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
@tenues = @tenues.page(pagination[:page])
|
38
|
+
.per(pagination[:per_page])
|
39
|
+
```
|
40
|
+
|
41
|
+
*The method `page` and `per` come from [will_paginate](https://github.com/mislav/will_paginate)*
|
42
|
+
|
43
|
+
The pagination method return an hash like this :
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
{ page: 1, per_page: 10 }
|
47
|
+
```
|
48
|
+
|
49
|
+
⚠️ The first page is `1` and not `0` !
|
50
|
+
|
51
|
+
### RenderErrorConcern
|
52
|
+
|
53
|
+
TODO
|
54
|
+
|
30
55
|
## Installation
|
31
56
|
Add this line to your application's Gemfile:
|
32
57
|
|
@@ -15,10 +15,12 @@ module Api
|
|
15
15
|
DEFAULT_NB_ITEMS_PAR_PAGE = 10
|
16
16
|
|
17
17
|
def pagination
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
@pagination ||= begin
|
19
|
+
par_page = (params[:per_page] || DEFAULT_NB_ITEMS_PAR_PAGE).to_i
|
20
|
+
par_page = MAX_ITEMS_PAR_PAGE if par_page > MAX_ITEMS_PAR_PAGE
|
21
|
+
page = (params[:page] || 1).to_i
|
22
|
+
{ page: page, per_page: par_page }
|
23
|
+
end
|
22
24
|
end
|
23
25
|
end
|
24
26
|
end
|
@@ -8,6 +8,7 @@ module Api
|
|
8
8
|
|
9
9
|
included do
|
10
10
|
rescue_from ActiveRecord::RecordNotFound, with: :not_found
|
11
|
+
rescue_from ActionController::ParameterMissing, with: :handle_parameter_missing
|
11
12
|
|
12
13
|
rescue_from CanCan::AccessDenied do |exception|
|
13
14
|
render_error_from_exception(exception, status: :forbidden)
|
@@ -23,7 +24,7 @@ module Api
|
|
23
24
|
errors = object.errors.messages
|
24
25
|
Rails.logger.error("Impossible de sauvagarder l'objet #{object.class} : #{errors}")
|
25
26
|
render_error(
|
26
|
-
message: message, errors: errors, status:
|
27
|
+
message: message, errors: errors, status: status
|
27
28
|
)
|
28
29
|
end
|
29
30
|
|
@@ -33,6 +34,10 @@ module Api
|
|
33
34
|
)
|
34
35
|
end
|
35
36
|
|
37
|
+
def handle_parameter_missing(exception)
|
38
|
+
render_error_from_exception(exception, status: :bad_request)
|
39
|
+
end
|
40
|
+
|
36
41
|
def not_found(exception)
|
37
42
|
render_error(message: "#{exception.model} not found", status: :not_found)
|
38
43
|
end
|
data/lib/captive/api/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: captive-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Captive
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2023-
|
12
|
+
date: 2023-07-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -64,7 +64,6 @@ homepage: https://www.captive.fr/
|
|
64
64
|
licenses:
|
65
65
|
- MIT
|
66
66
|
metadata:
|
67
|
-
allowed_push_host: https://rubygems.org/
|
68
67
|
homepage_uri: https://www.captive.fr/
|
69
68
|
source_code_uri: https://github.com/Captive-Studio/captive-api
|
70
69
|
post_install_message:
|