captive-api 0.2.12 → 1.0.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: 2e8c01528873d2980a29f6cfd4308c74703935baea3f6a87dc663262bb04e180
4
- data.tar.gz: e6227c5524d603405bb70b9c911cc4354f229978002e275c404e54bd391eed31
3
+ metadata.gz: aa071cf3e2b74fa646d99645daa968329f02a82df71344a1dc8bf6f0959b7cab
4
+ data.tar.gz: 8dec67a5234fcacdcf177922403bffa3dc3ed71b61ff66c49e0013eab5516294
5
5
  SHA512:
6
- metadata.gz: 12710c8b7c1ff65e017d03de9ddca94114b7da4d542982677087d044f0cca448e8b7c01f4557feff2c3ac72fcfa2d8f45ec03addb6cc195394ce2933bf163712
7
- data.tar.gz: 4fe3637d1243ce48ed55289f707401ecaa0ca192970d3279fbc0948db013e8c140df1136b093f24d4c2787911fbe986d4968f08a0d000d878a501af3ebbad8c9
6
+ metadata.gz: a35b99b5b24cca392656620b2cb1f3df13e678f00639a9688ddbf43864ddadfcc8cd7bba7bc3c8acac19b44aee89533923f6eff3efd4e382afda746110f6234c
7
+ data.tar.gz: 7a878b264965496688cc8916f644ab1dfa52ff5ad84e11ce06f77f68fd57cc2da5436ba61d11c8f8b3a93c812f94a2d5096e80fc5227dda75d0b51c3d9b779e1
data/README.md CHANGED
@@ -1,60 +1,22 @@
1
- # Captive::API
2
-
3
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
4
- [![Gem Version](https://img.shields.io/gem/v/captive-api.svg)](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 API
10
+ module Api
16
11
  module V1
17
- class BaseController < Captive::API::ApplicationController
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
- # frozen_string_literal: true
1
+ require "bundler/setup"
2
2
 
3
- require "bundler/gem_tasks"
4
- require "rspec/core/rake_task"
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
- require "rubocop/rake_task"
6
+ load "rails/tasks/statistics.rake"
9
7
 
10
- RuboCop::RakeTask.new
11
-
12
- task default: %i(spec rubocop)
8
+ require "bundler/gem_tasks"
@@ -1,8 +1,8 @@
1
1
  module Captive
2
- module API
2
+ module Api
3
3
  class ApplicationController < ActionController::API
4
- include ::API::PaginationConcern
5
- include ::API::RenderErrorConcern
4
+ include ::Api::PaginationConcern
5
+ include ::Api::RenderErrorConcern
6
6
  end
7
7
  end
8
8
  end
@@ -1,27 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
 
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 à 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 |base|
14
- base.const_set :MAX_ITEMS_PAR_PAGE, 100
15
- base.const_set :DEFAULT_NB_ITEMS_PAR_PAGE, 20
7
+ included do
8
+ MAX_ITEMS_PAR_PAGE = 100
9
+ DEFAULT_NB_ITEMS_PAR_PAGE = 10
16
10
 
17
11
  def pagination
18
- @pagination ||=
19
- begin
20
- par_page = (params[:per_page] || self.class::DEFAULT_NB_ITEMS_PAR_PAGE).to_i
21
- par_page = self.class::MAX_ITEMS_PAR_PAGE if par_page > self.class::MAX_ITEMS_PAR_PAGE
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 API
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: "Erreur de validation"
18
+ message: 'Erreur de validation'
23
19
  )
24
20
  errors = object.errors.messages
25
- Rails.logger.error("Impossible de sauvegarder l'objet #{object.class} : #{errors}")
21
+ Rails.logger.error("Impossible de sauvagarder l'objet #{object.class} : #{errors}")
26
22
  render_error(
27
- message: message, errors: errors, status: 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 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)
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)
@@ -1,5 +1,5 @@
1
1
  module Captive
2
- module API
2
+ module Api
3
3
  class ApplicationJob < ActiveJob::Base
4
4
  end
5
5
  end
@@ -1,5 +1,5 @@
1
1
  module Captive
2
- module API
2
+ module Api
3
3
  class ApplicationMailer < ActionMailer::Base
4
4
  default from: "from@example.com"
5
5
  layout "mailer"
@@ -1,5 +1,5 @@
1
1
  module Captive
2
- module API
2
+ module Api
3
3
  class ApplicationRecord < ActiveRecord::Base
4
4
  self.abstract_class = true
5
5
  end
data/config/routes.rb CHANGED
@@ -1,2 +1,2 @@
1
- Captive::API::Engine.routes.draw do
1
+ Captive::Api::Engine.routes.draw do
2
2
  end
@@ -1,7 +1,7 @@
1
1
  module Captive
2
- module API
2
+ module Api
3
3
  class Engine < ::Rails::Engine
4
- isolate_namespace Captive::API
4
+ isolate_namespace Captive::Api
5
5
  config.generators.api_only = true
6
6
  end
7
7
  end
@@ -0,0 +1,5 @@
1
+ module Captive
2
+ module Api
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
data/lib/captive/api.rb CHANGED
@@ -1,7 +1,8 @@
1
+ require "captive/api/version"
1
2
  require "captive/api/engine"
2
3
 
3
4
  module Captive
4
- module API
5
+ module Api
5
6
  # Your code goes here...
6
7
  end
7
8
  end
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.2.12
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-13 00:00:00.000000000 Z
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-sdk/tree/v0.2.12/captive-api
68
+ source_code_uri: https://github.com/Captive-Studio/captive-api
83
69
  post_install_message:
84
70
  rdoc_options: []
85
71
  require_paths:
@@ -1 +0,0 @@
1
- Oj.optimize_rails