jsonapi-realizer 6.0.0 → 6.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +13 -12
- data/lib/jsonapi/realizer/controller.rb +16 -36
- data/lib/jsonapi/realizer/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c68ffbcd4a507dfa58fe1951023e0d1ef4d362b841138542b25a051a8add752c
|
4
|
+
data.tar.gz: f56185a4a2948a3e1ba1364faaf02803ba299c6b1652208ce127fa042a88f5ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e5e346fceeab12188a36fd6c142b54fa8ff41cfa5dc49a55f201f92f454f00b4d2abf9ff32f51d347927f40079572442ed323de6ae4b35ac7c5ca213a38e4ca8
|
7
|
+
data.tar.gz: 9a73e8e119c82793a6f7d1508cb27490cabfa1daffa0b91e2269cd8202c2add58aa1faa6332371eaa39abb643c74e9ce20ab3c0d07f4a06270edcb3a3263c01a
|
data/README.md
CHANGED
@@ -66,7 +66,7 @@ class PhotosController < ApplicationController
|
|
66
66
|
end
|
67
67
|
|
68
68
|
def index
|
69
|
-
realizer = PhotoRealizer.new
|
69
|
+
realizer = PhotoRealizer.new
|
70
70
|
:intent => :index,
|
71
71
|
:parameters => params,
|
72
72
|
:headers => request.headers
|
@@ -213,26 +213,27 @@ You can see this resource controller used below:
|
|
213
213
|
module V1
|
214
214
|
class AccountsController < ::V1::ApplicationController
|
215
215
|
def index
|
216
|
-
realization =
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
216
|
+
realization = PhotoRealizer.new(
|
217
|
+
:intent => :index,
|
218
|
+
:scope => policy_scope(Account),
|
219
|
+
:parameters => policy(Account).sanitize(:index, params),
|
220
|
+
:headers => request.headers
|
221
221
|
)
|
222
222
|
|
223
|
-
authorize realization.
|
223
|
+
authorize realization.object
|
224
224
|
|
225
225
|
render json: serialize(realization)
|
226
226
|
end
|
227
227
|
|
228
228
|
def create
|
229
|
-
realization =
|
230
|
-
|
231
|
-
|
232
|
-
|
229
|
+
realization = PhotoRealizer.new(
|
230
|
+
:intent => :create,
|
231
|
+
:scope => policy_scope(Account),
|
232
|
+
:parameters => policy(Account).sanitize(:create, params),
|
233
|
+
:headers => request.headers
|
233
234
|
)
|
234
235
|
|
235
|
-
authorize realization.
|
236
|
+
authorize realization.object
|
236
237
|
|
237
238
|
render json: serialize(realization)
|
238
239
|
end
|
@@ -3,54 +3,34 @@
|
|
3
3
|
module JSONAPI
|
4
4
|
module Realizer
|
5
5
|
module Controller
|
6
|
-
private def
|
7
|
-
return if request.body.empty?
|
8
|
-
return if request.headers.
|
9
|
-
|
10
|
-
raise(JSONAPI::Realizer.configuration.default_missing_content_type_exception)
|
11
|
-
end
|
12
|
-
|
13
|
-
private def reject_invalid_content_type_header
|
14
|
-
reject_missing_content_type_header
|
15
|
-
|
16
|
-
return if request.headers.fetch("Content-Type").include?(JSONAPI::MEDIA_TYPE)
|
17
|
-
|
18
|
-
raise(JSONAPI::Realizer.configuration.default_invalid_content_type_exception)
|
19
|
-
end
|
20
|
-
|
21
|
-
private def reject_missing_root_property
|
22
|
-
return if request.parameters.key?("body")
|
23
|
-
return if request.paremters.key?("errors")
|
24
|
-
return if request.paremters.key?("meta")
|
6
|
+
private def reject_missing_accept_type_header
|
7
|
+
return if request.body.read.empty?
|
8
|
+
return if request.headers.key?("HTTP_ACCEPT")
|
25
9
|
|
26
|
-
raise(
|
10
|
+
raise(JSONAPI::Realizer.configuration.default_missing_accept_type_exception)
|
27
11
|
end
|
28
12
|
|
29
|
-
private def
|
30
|
-
|
13
|
+
private def reject_invalid_accept_type_header
|
14
|
+
reject_missing_accept_type_header
|
31
15
|
|
32
|
-
return
|
33
|
-
return unless request.parameters.key?("errors") && request.parameters.fetch("errors").is_a?(Array)
|
16
|
+
return if request.headers.fetch("HTTP_ACCEPT").include?(JSONAPI::MEDIA_TYPE)
|
34
17
|
|
35
|
-
raise(
|
18
|
+
raise(JSONAPI::Realizer.configuration.default_invalid_accept_type_exception)
|
36
19
|
end
|
37
20
|
|
38
|
-
private def
|
39
|
-
|
40
|
-
|
41
|
-
return if request.parameters.fetch("data").is_a?(Hash) && request.parameters.fetch("data").key?("type")
|
42
|
-
return if request.parameters.fetch("data").is_a?(Array) && request.parameters.fetch("data").all? { |data| data.key?("type") }
|
21
|
+
private def reject_missing_content_type_header
|
22
|
+
return if request.body.read.empty?
|
23
|
+
return if request.headers.key?("Content-Type")
|
43
24
|
|
44
|
-
raise(
|
25
|
+
raise(JSONAPI::Realizer.configuration.default_missing_content_type_exception)
|
45
26
|
end
|
46
27
|
|
47
|
-
private def
|
48
|
-
|
28
|
+
private def reject_invalid_content_type_header
|
29
|
+
reject_missing_content_type_header
|
49
30
|
|
50
|
-
return if request.
|
51
|
-
return if request.parameters.fetch("data").is_a?(Array) && request.parameters.fetch("data").map { |data| data.fetch("type") }.all? { |type| type.is_a?(String) && type.present? }
|
31
|
+
return if request.headers.fetch("Content-Type").include?(JSONAPI::MEDIA_TYPE)
|
52
32
|
|
53
|
-
raise(
|
33
|
+
raise(JSONAPI::Realizer.configuration.default_invalid_content_type_exception)
|
54
34
|
end
|
55
35
|
end
|
56
36
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jsonapi-realizer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 6.
|
4
|
+
version: 6.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kurtis Rainbolt-Greene
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-09-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -88,7 +88,7 @@ files:
|
|
88
88
|
- lib/jsonapi/realizer/resource_spec.rb
|
89
89
|
- lib/jsonapi/realizer/version.rb
|
90
90
|
- lib/jsonapi/realizer_spec.rb
|
91
|
-
homepage:
|
91
|
+
homepage: https://github.com/krainboltgreene/jsonapi-realizer.rb
|
92
92
|
licenses:
|
93
93
|
- HL3
|
94
94
|
metadata:
|