captive-api 1.0.0 → 1.1.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: 610b0277d1e8fa73791417902e5da68398a888944d4eddec9962b203432fa7a0
|
4
|
+
data.tar.gz: 701f6b9b8905044fc77ade30868f4ac37203ee181d71360df6b87bbd269caa95
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2582ca1e4bc6f2b6353348c352c62958ddbfb43f22f994788ad5bcf3a6efa4f4922956cdaf14c6dd46bd2c2b3396b2dd90da3e7feb5fe8d1550aa336edfe87e7
|
7
|
+
data.tar.gz: 4bf48698d424366d310d97210bb2263d715a4d1257b92b21dcd041c8818848c22e14f9518bcca641a16081bc20d4667307d59dd1226a9ba79c1efd4abb854699
|
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,14 @@
|
|
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
|
+
|
9
12
|
rescue_from CanCan::AccessDenied do |exception|
|
10
13
|
render_error_from_exception(exception, status: :forbidden)
|
11
14
|
end
|
@@ -30,8 +33,8 @@ module Api
|
|
30
33
|
)
|
31
34
|
end
|
32
35
|
|
33
|
-
def not_found
|
34
|
-
render_error(message:
|
36
|
+
def not_found(exception)
|
37
|
+
render_error(message: "#{exception.model} not found", status: :not_found)
|
35
38
|
end
|
36
39
|
|
37
40
|
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.1.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-06-
|
12
|
+
date: 2023-06-30 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: rails
|