carioca 2.1.1 → 2.1.3

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: efd32c21848d7ab53724150ebbee9a3347662416fe0ee84ae46f3dd8f80cf4ac
4
- data.tar.gz: 5a34be69f6405a4eae679b26117872f3be4f74181fd188e455044181c2b2b1a3
3
+ metadata.gz: 99e25d909400997565234d097e571a9600cca99dca0880e493ea74a6547573ae
4
+ data.tar.gz: 6c3f581e92b5e9e2f6e91f9f466f2d22ec462ef20ca6799eb1a0304d039a44b6
5
5
  SHA512:
6
- metadata.gz: e9cc6b8643cfc08f0bdb0066dfa1c7344be07474f1138bb2dec79710a2dac2b2f0a828fae2e236196b5137f01e66fc3e3a0693035ad2b1330ef265966c9309e4
7
- data.tar.gz: 8963f1b087355b09c8b364d359d2757c17b561db2f0e9e04d93fc84dd6684bac11ffe533757124ebe44bc7c35616b61c3187f21a4e0bf50f142c5dfd23d3a1e9
6
+ metadata.gz: b9f9bda2f074633447842b10c9cde5ffdf8c157fc9a3e78398b7a70311425b5a2ce8243ef685b03333b9be850d1103bffab5fc2dba69d51fecc6810b74dfce82
7
+ data.tar.gz: 4baf6ce65f7efc84e72c13b66a8ccbacf08a68c4d783770736c5f344d6848440dc11d2894d07474da38e73b777ac668dff5cfb18f3f5f4d29b77ab115df65022
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.1.1
1
+ 2.1.3
@@ -39,6 +39,10 @@ en:
39
39
  already_exist: "Object already exist"
40
40
  status_ok: "Status OK"
41
41
  status_ko: "Status KO"
42
+ no_content: "No content found"
43
+ bad_request: "Bad request"
44
+ created: "Content Successfully created"
45
+ accepted: "Request accepted"
42
46
  bad_usage: "Case must be a return or an exit"
43
47
  setup:
44
48
  error: "Setup operation failed"
@@ -39,6 +39,10 @@ fr:
39
39
  already_exist: "L'objet existé déjà"
40
40
  status_ok: "Status OK"
41
41
  status_ko: "Status KO"
42
+ no_content: "Pas de contenu trouvé"
43
+ bad_request: "Requête incorrecte"
44
+ created: "Contenu créé avec succès"
45
+ accepted: "Requête acceptée"
42
46
  bad_usage: "return_case et exit_case sont incompatibles"
43
47
  setup:
44
48
  error: "Opération en echec durant le setup"
@@ -32,12 +32,16 @@ module Carioca
32
32
  error_exit: { code: 50, key: 'finisher.messages.error_exit' },
33
33
  # events
34
34
  interrupt: { code: 330, key: 'finisher.messages.interrupt' },
35
- # request
35
+ # request & API
36
36
  not_found: { code: 404, key: 'finisher.messages.not_found' },
37
37
  already_exist: { code: 408, key: 'finisher.messages.already_exist' },
38
- # daemon
38
+ # daemon & API
39
39
  status_ok: { code: 200, key: 'finisher.messages.status_ok' },
40
- status_ko: { code: 500, key: 'finisher.messages.status_ko' }
40
+ created: { code: 201, key: 'finisher.messages.created' },
41
+ accepted: { code: 202, key: 'finisher.messages.accepted' },
42
+ bad_request: { code: 400, key: 'finisher.messages.bad_request' },
43
+ status_ko: { code: 500, key: 'finisher.messages.status_ko' },
44
+ no_content: { code: 204, key: 'finisher.messages.no_content' },
41
45
  }
42
46
 
43
47
 
@@ -88,7 +92,7 @@ module Carioca
88
92
  end
89
93
 
90
94
 
91
- def secure_api_return(data: nil, return_case: nil, structured: false, json: true)
95
+ def secure_api_return(data: nil, return_case: nil, structured: false, json: true, status: true)
92
96
  result = {}
93
97
  begin
94
98
  data = yield if block_given?
@@ -98,8 +102,14 @@ module Carioca
98
102
  more = (e.respond_to? :error_case)? e.message : "#{e.class.to_s} : #{e.message}"
99
103
  result = do_return return_case: key, more: more
100
104
  end
101
- result = JSON.pretty_generate(JSON.parse(result.to_json)) if json
102
- return result
105
+ if status and structured and json then
106
+ p result
107
+ return {status: result[:code], data: JSON.pretty_generate(JSON.parse(result.to_json))}
108
+ elsif json then
109
+ return JSON.pretty_generate(JSON.parse(result.to_json)) if json
110
+ else
111
+ return result
112
+ end
103
113
  end
104
114
 
105
115
 
data/samples/test.rb CHANGED
@@ -188,12 +188,21 @@ test = finisher.secure_api_return(return_case: :status_ok, structured: true, jso
188
188
  finisher.secure_raise message: "error !", error_case: :status_ko
189
189
  "test"
190
190
  end
191
- puts test
191
+ puts test[:status]
192
+ puts test[:data]
192
193
 
193
194
  output.item "api return, json, structured"
194
195
  test = finisher.secure_api_return(return_case: :status_ok, structured: true, json: true) do
195
196
  "test"
196
197
  end
198
+ puts test[:status]
199
+ puts test[:data]
200
+
201
+
202
+ output.item "api return, json, structured with status=false"
203
+ test = finisher.secure_api_return(return_case: :status_ok, structured: true, json: true, status: false) do
204
+ "test"
205
+ end
197
206
  puts test
198
207
 
199
208
  puts "\nTest 18 : Service finisher : exit case in success"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: carioca
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
4
+ version: 2.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Romain GEORGES
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-10-02 00:00:00.000000000 Z
11
+ date: 2023-10-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: deep_merge