captive-api 0.2.12 → 1.0.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 +4 -4
- data/README.md +6 -48
- data/Rakefile +5 -9
- data/app/controllers/captive/api/application_controller.rb +3 -3
- data/app/controllers/concerns/api/pagination_concern.rb +8 -17
- data/app/controllers/concerns/api/render_error_concern.rb +6 -14
- data/app/jobs/captive/api/application_job.rb +1 -1
- data/app/mailers/captive/api/application_mailer.rb +1 -1
- data/app/models/captive/api/application_record.rb +1 -1
- data/config/routes.rb +1 -1
- data/lib/captive/api/engine.rb +2 -2
- data/lib/captive/api/version.rb +5 -0
- data/lib/captive/api.rb +2 -1
- metadata +5 -19
- data/config/initializers/oj.rb +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aa071cf3e2b74fa646d99645daa968329f02a82df71344a1dc8bf6f0959b7cab
|
4
|
+
data.tar.gz: 8dec67a5234fcacdcf177922403bffa3dc3ed71b61ff66c49e0013eab5516294
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a35b99b5b24cca392656620b2cb1f3df13e678f00639a9688ddbf43864ddadfcc8cd7bba7bc3c8acac19b44aee89533923f6eff3efd4e382afda746110f6234c
|
7
|
+
data.tar.gz: 7a878b264965496688cc8916f644ab1dfa52ff5ad84e11ce06f77f68fd57cc2da5436ba61d11c8f8b3a93c812f94a2d5096e80fc5227dda75d0b51c3d9b779e1
|
data/README.md
CHANGED
@@ -1,60 +1,22 @@
|
|
1
|
-
# Captive::
|
2
|
-
|
3
|
-
[](https://opensource.org/licenses/MIT)
|
4
|
-
[](https://rubygems.org/gems/captive-api)
|
5
|
-
|
6
|
-
Code commun des API de Captive
|
1
|
+
# Captive::Api
|
2
|
+
Short description and motivation.
|
7
3
|
|
8
4
|
## Usage
|
9
|
-
|
10
5
|
How to use my plugin.
|
11
6
|
|
12
7
|
Implementation :
|
13
8
|
|
14
9
|
```ruby
|
15
|
-
module
|
10
|
+
module Api
|
16
11
|
module V1
|
17
|
-
class BaseController < Captive::
|
12
|
+
class BaseController < Captive::Api::ApplicationController
|
18
13
|
...
|
19
14
|
end
|
20
15
|
end
|
21
16
|
end
|
22
17
|
```
|
23
18
|
|
24
|
-
The class `Captive::API::ApplicationController` includes 2 concerns :
|
25
|
-
|
26
|
-
| Nom du concern | Description |
|
27
|
-
|:-----|:--------:|
|
28
|
-
| [pagination](https://github.com/Captive-Studio/captive-api/blob/main/app/controllers/concerns/api/pagination_concern.rb) | Logique de pagination pour les index |
|
29
|
-
| [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 |
|
30
|
-
|
31
|
-
### PaginationConcern
|
32
|
-
|
33
|
-
#### `#pagination`
|
34
|
-
|
35
|
-
You can use the pagination method like this :
|
36
|
-
|
37
|
-
```ruby
|
38
|
-
@tenues = @tenues.page(pagination[:page])
|
39
|
-
.per(pagination[:per_page])
|
40
|
-
```
|
41
|
-
|
42
|
-
*The method `page` and `per` come from [will_paginate](https://github.com/mislav/will_paginate)*
|
43
|
-
|
44
|
-
The pagination method return an hash like this :
|
45
|
-
|
46
|
-
```ruby
|
47
|
-
{ page: 1, per_page: 20 }
|
48
|
-
```
|
49
|
-
|
50
|
-
⚠️ The first page is `1` and not `0` !
|
51
|
-
|
52
|
-
### RenderErrorConcern
|
53
|
-
|
54
|
-
TODO
|
55
|
-
|
56
19
|
## Installation
|
57
|
-
|
58
20
|
Add this line to your application's Gemfile:
|
59
21
|
|
60
22
|
```ruby
|
@@ -62,21 +24,17 @@ gem "captive-api"
|
|
62
24
|
```
|
63
25
|
|
64
26
|
And then execute:
|
65
|
-
|
66
27
|
```bash
|
67
|
-
bundle
|
28
|
+
$ bundle
|
68
29
|
```
|
69
30
|
|
70
31
|
Or install it yourself as:
|
71
|
-
|
72
32
|
```bash
|
73
|
-
gem install captive-api
|
33
|
+
$ gem install captive-api
|
74
34
|
```
|
75
35
|
|
76
36
|
## Contributing
|
77
|
-
|
78
37
|
Contribution directions go here.
|
79
38
|
|
80
39
|
## License
|
81
|
-
|
82
40
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
CHANGED
@@ -1,12 +1,8 @@
|
|
1
|
-
|
1
|
+
require "bundler/setup"
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
RSpec::Core::RakeTask.new(:spec)
|
3
|
+
APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
|
4
|
+
load "rails/tasks/engine.rake"
|
7
5
|
|
8
|
-
|
6
|
+
load "rails/tasks/statistics.rake"
|
9
7
|
|
10
|
-
|
11
|
-
|
12
|
-
task default: %i(spec rubocop)
|
8
|
+
require "bundler/gem_tasks"
|
@@ -1,27 +1,18 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module
|
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 à 20
|
9
|
-
# DEFAULT_NB_ITEMS_PAR_PAGE = 20
|
3
|
+
module Api
|
10
4
|
module PaginationConcern
|
11
5
|
extend ActiveSupport::Concern
|
12
6
|
|
13
|
-
included do
|
14
|
-
|
15
|
-
|
7
|
+
included do
|
8
|
+
MAX_ITEMS_PAR_PAGE = 100
|
9
|
+
DEFAULT_NB_ITEMS_PAR_PAGE = 10
|
16
10
|
|
17
11
|
def pagination
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
page = (params[:page] || 1).to_i
|
23
|
-
{ page: page, per_page: par_page }
|
24
|
-
end
|
12
|
+
par_page = (params[:per_page] || DEFAULT_NB_ITEMS_PAR_PAGE).to_i
|
13
|
+
par_page = MAX_ITEMS_PAR_PAGE if par_page > MAX_ITEMS_PAR_PAGE
|
14
|
+
page = (params[:page] || 1).to_i
|
15
|
+
@pagination ||= { page: page, per_page: par_page }
|
25
16
|
end
|
26
17
|
end
|
27
18
|
end
|
@@ -1,15 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module
|
4
|
-
##
|
5
|
-
# Permet de catcher des erreurs pour rendre une page d'erreur en json
|
3
|
+
module Api
|
6
4
|
module RenderErrorConcern
|
7
5
|
extend ActiveSupport::Concern
|
8
6
|
|
9
7
|
included do
|
10
8
|
rescue_from ActiveRecord::RecordNotFound, with: :not_found
|
11
|
-
rescue_from ActionController::ParameterMissing, with: :handle_parameter_missing
|
12
|
-
|
13
9
|
rescue_from CanCan::AccessDenied do |exception|
|
14
10
|
render_error_from_exception(exception, status: :forbidden)
|
15
11
|
end
|
@@ -19,12 +15,12 @@ module API
|
|
19
15
|
def render_error_from_object(
|
20
16
|
object,
|
21
17
|
status: :unprocessable_entity,
|
22
|
-
message:
|
18
|
+
message: 'Erreur de validation'
|
23
19
|
)
|
24
20
|
errors = object.errors.messages
|
25
|
-
Rails.logger.error("Impossible de
|
21
|
+
Rails.logger.error("Impossible de sauvagarder l'objet #{object.class} : #{errors}")
|
26
22
|
render_error(
|
27
|
-
message: message, errors: errors, status:
|
23
|
+
message: message, errors: errors, status: :unprocessable_entity
|
28
24
|
)
|
29
25
|
end
|
30
26
|
|
@@ -34,12 +30,8 @@ module API
|
|
34
30
|
)
|
35
31
|
end
|
36
32
|
|
37
|
-
def
|
38
|
-
|
39
|
-
end
|
40
|
-
|
41
|
-
def not_found(exception)
|
42
|
-
render_error(message: "#{exception.model} not found", status: :not_found)
|
33
|
+
def not_found
|
34
|
+
render_error(message: 'Erreur not found', status: :not_found)
|
43
35
|
end
|
44
36
|
|
45
37
|
def render_error(message:, status:, errors: [], code: nil)
|
data/config/routes.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
Captive::
|
1
|
+
Captive::Api::Engine.routes.draw do
|
2
2
|
end
|
data/lib/captive/api/engine.rb
CHANGED
data/lib/captive/api.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: captive-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
- Captive
|
8
7
|
- Clément Prod'homme
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2023-
|
11
|
+
date: 2023-06-29 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rails
|
@@ -39,20 +38,6 @@ dependencies:
|
|
39
38
|
- - ">="
|
40
39
|
- !ruby/object:Gem::Version
|
41
40
|
version: 3.5.0
|
42
|
-
- !ruby/object:Gem::Dependency
|
43
|
-
name: oj
|
44
|
-
requirement: !ruby/object:Gem::Requirement
|
45
|
-
requirements:
|
46
|
-
- - ">="
|
47
|
-
- !ruby/object:Gem::Version
|
48
|
-
version: 3.15.0
|
49
|
-
type: :runtime
|
50
|
-
prerelease: false
|
51
|
-
version_requirements: !ruby/object:Gem::Requirement
|
52
|
-
requirements:
|
53
|
-
- - ">="
|
54
|
-
- !ruby/object:Gem::Version
|
55
|
-
version: 3.15.0
|
56
41
|
description: Code commun des API de Captive
|
57
42
|
email:
|
58
43
|
- clement.prod-homme@captive.fr
|
@@ -69,17 +54,18 @@ files:
|
|
69
54
|
- app/jobs/captive/api/application_job.rb
|
70
55
|
- app/mailers/captive/api/application_mailer.rb
|
71
56
|
- app/models/captive/api/application_record.rb
|
72
|
-
- config/initializers/oj.rb
|
73
57
|
- config/routes.rb
|
74
58
|
- lib/captive/api.rb
|
75
59
|
- lib/captive/api/engine.rb
|
60
|
+
- lib/captive/api/version.rb
|
76
61
|
- lib/tasks/captive/api_tasks.rake
|
77
62
|
homepage: https://www.captive.fr/
|
78
63
|
licenses:
|
79
64
|
- MIT
|
80
65
|
metadata:
|
66
|
+
allowed_push_host: https://rubygems.org/
|
81
67
|
homepage_uri: https://www.captive.fr/
|
82
|
-
source_code_uri: https://github.com/Captive-Studio/captive-
|
68
|
+
source_code_uri: https://github.com/Captive-Studio/captive-api
|
83
69
|
post_install_message:
|
84
70
|
rdoc_options: []
|
85
71
|
require_paths:
|
data/config/initializers/oj.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
Oj.optimize_rails
|