captive-api 1.0.0 → 1.2.0
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: e72b812dfba5731acc69f880513c4d445b6cc116ba1414769b7b2a80fe2ff059
|
4
|
+
data.tar.gz: 54aa16d8fef4481576db2a1b516370425028daeafdfba386ff39d59b76a554b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c6ce7a15f9fe66265869f616b720d99b8adb4b2a4050db0a8cc86e61f8c8ab44dfa5de70d201a9dbac589b8f399ad909667bf605ac210347b331474253fa728b
|
7
|
+
data.tar.gz: e901f2a5e2e65a91f4f5602dd8528db230d73af5bc757eeb992c2bd7b2243c3136b56485d0f790656bf1433adb5f9342a50bbfe152c80fd328d1eab6aac65713
|
data/README.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# Captive::Api
|
2
|
-
|
2
|
+
|
3
|
+
[![Gem Version](https://img.shields.io/gem/v/captive-api.svg)](https://rubygems.org/gems/captive-api)
|
4
|
+
|
5
|
+
|
6
|
+
Code commun des API de Captive
|
3
7
|
|
4
8
|
## Usage
|
5
9
|
How to use my plugin.
|
@@ -16,6 +20,13 @@ module Api
|
|
16
20
|
end
|
17
21
|
```
|
18
22
|
|
23
|
+
The class `Captive::Api::ApplicationController` includes 2 concerns :
|
24
|
+
|
25
|
+
| Nom du concern | Description |
|
26
|
+
|:-----|:--------:|
|
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
|
+
| [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
|
+
|
19
30
|
## Installation
|
20
31
|
Add this line to your application's Gemfile:
|
21
32
|
|
@@ -1,6 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Api
|
4
|
+
##
|
5
|
+
# Défini le nombre max d'items par page à 100
|
6
|
+
# `MAX_ITEMS_PAR_PAGE = 100`
|
7
|
+
#
|
8
|
+
# Défini le nombre par défaut d'items par page à 10
|
9
|
+
# DEFAULT_NB_ITEMS_PAR_PAGE = 10
|
4
10
|
module PaginationConcern
|
5
11
|
extend ActiveSupport::Concern
|
6
12
|
|
@@ -1,11 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Api
|
4
|
+
##
|
5
|
+
# Permet de catcher des erreurs pour rendre une page d'erreur en json
|
4
6
|
module RenderErrorConcern
|
5
7
|
extend ActiveSupport::Concern
|
6
8
|
|
7
9
|
included do
|
8
10
|
rescue_from ActiveRecord::RecordNotFound, with: :not_found
|
11
|
+
rescue_from ActionController::ParameterMissing, with: :handle_parameter_missing
|
12
|
+
|
9
13
|
rescue_from CanCan::AccessDenied do |exception|
|
10
14
|
render_error_from_exception(exception, status: :forbidden)
|
11
15
|
end
|
@@ -20,7 +24,7 @@ module Api
|
|
20
24
|
errors = object.errors.messages
|
21
25
|
Rails.logger.error("Impossible de sauvagarder l'objet #{object.class} : #{errors}")
|
22
26
|
render_error(
|
23
|
-
message: message, errors: errors, status:
|
27
|
+
message: message, errors: errors, status: status
|
24
28
|
)
|
25
29
|
end
|
26
30
|
|
@@ -30,8 +34,12 @@ module Api
|
|
30
34
|
)
|
31
35
|
end
|
32
36
|
|
33
|
-
def
|
34
|
-
|
37
|
+
def handle_parameter_missing(exception)
|
38
|
+
render_error_from_exception(exception, status: :bad_request)
|
39
|
+
end
|
40
|
+
|
41
|
+
def not_found(exception)
|
42
|
+
render_error(message: "#{exception.model} not found", status: :not_found)
|
35
43
|
end
|
36
44
|
|
37
45
|
def render_error(message:, status:, errors: [], code: nil)
|
data/lib/captive/api/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: captive-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
+
- Captive
|
7
8
|
- Clément Prod'homme
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date: 2023-
|
12
|
+
date: 2023-07-03 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: rails
|
@@ -63,7 +64,6 @@ homepage: https://www.captive.fr/
|
|
63
64
|
licenses:
|
64
65
|
- MIT
|
65
66
|
metadata:
|
66
|
-
allowed_push_host: https://rubygems.org/
|
67
67
|
homepage_uri: https://www.captive.fr/
|
68
68
|
source_code_uri: https://github.com/Captive-Studio/captive-api
|
69
69
|
post_install_message:
|