captive-api 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aa071cf3e2b74fa646d99645daa968329f02a82df71344a1dc8bf6f0959b7cab
4
- data.tar.gz: 8dec67a5234fcacdcf177922403bffa3dc3ed71b61ff66c49e0013eab5516294
3
+ metadata.gz: 610b0277d1e8fa73791417902e5da68398a888944d4eddec9962b203432fa7a0
4
+ data.tar.gz: 701f6b9b8905044fc77ade30868f4ac37203ee181d71360df6b87bbd269caa95
5
5
  SHA512:
6
- metadata.gz: a35b99b5b24cca392656620b2cb1f3df13e678f00639a9688ddbf43864ddadfcc8cd7bba7bc3c8acac19b44aee89533923f6eff3efd4e382afda746110f6234c
7
- data.tar.gz: 7a878b264965496688cc8916f644ab1dfa52ff5ad84e11ce06f77f68fd57cc2da5436ba61d11c8f8b3a93c812f94a2d5096e80fc5227dda75d0b51c3d9b779e1
6
+ metadata.gz: 2582ca1e4bc6f2b6353348c352c62958ddbfb43f22f994788ad5bcf3a6efa4f4922956cdaf14c6dd46bd2c2b3396b2dd90da3e7feb5fe8d1550aa336edfe87e7
7
+ data.tar.gz: 4bf48698d424366d310d97210bb2263d715a4d1257b92b21dcd041c8818848c22e14f9518bcca641a16081bc20d4667307d59dd1226a9ba79c1efd4abb854699
data/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Captive::Api
2
- Short description and motivation.
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: 'Erreur not found', status: :not_found)
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)
@@ -1,5 +1,5 @@
1
1
  module Captive
2
2
  module Api
3
- VERSION = "1.0.0"
3
+ VERSION = "1.1.0".freeze
4
4
  end
5
5
  end
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.0.0
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-29 00:00:00.000000000 Z
12
+ date: 2023-06-30 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: rails