jsonapi-utils 0.4.8 → 0.4.9

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
  SHA1:
3
- metadata.gz: 17de793a78cef4a0b86e1fc100ebae4333ed18f6
4
- data.tar.gz: 5a46049114450f913cddd2e2c7679a809772847b
3
+ metadata.gz: 9e79dcc432ea412e938f711f040d12c70cb5196f
4
+ data.tar.gz: e34a24d48a769016f737c156311523935b4714a7
5
5
  SHA512:
6
- metadata.gz: 2dc69b2394872cf5e66317f4719f03fafcd1be2ec24e14a99ed57416ec128fcfc24430a444c3365306cf139595124581aca369dc1c14721340974783b269f929
7
- data.tar.gz: 1a19b7118d7396bdb61f12f0c134cc503ac8906952d627740ed7d3da66053230547c1724e68ab5069662bc33138cdbdf33d180d65c9c0c5866726c6ab288d86d
6
+ metadata.gz: 9b4222af57feada6a8c45b7385e8c889535e8000e229093e4053ce2812ef041aaf799216267e5105195282b027d516cf5b01db12204697f33d92c169a3b2ecd1
7
+ data.tar.gz: 4accdb7433731907f5cd9121c8e8227d916dae0480e1decf56b727208b7ef1537ef765236c4058130c21f74e77e09aceefcc4f1ed18c3d9d152c200b0f773030
@@ -1,48 +1,87 @@
1
- module JSONAPI
2
- module Utils
3
- module Request
4
- def jsonapi_request_handling
5
- setup_request
6
- check_request
7
- end
1
+ module JSONAPI::Utils
2
+ module Request
3
+ # Setup and check request before action gets actually evaluated.
4
+ #
5
+ # @api public
6
+ def jsonapi_request_handling
7
+ setup_request
8
+ check_request
9
+ end
8
10
 
9
- def setup_request
10
- @request ||=
11
- JSONAPI::Request.new(
12
- params.dup,
13
- context: context,
14
- key_formatter: key_formatter,
15
- server_error_callbacks: (self.class.server_error_callbacks || [])
16
- )
17
- end
11
+ # Instantiate the request object.
12
+ #
13
+ # @return [JSONAPI::RequestParser]
14
+ #
15
+ # @api public
16
+ def setup_request
17
+ @request ||= JSONAPI::RequestParser.new(
18
+ params,
19
+ context: context,
20
+ key_formatter: key_formatter,
21
+ server_error_callbacks: (self.class.server_error_callbacks || [])
22
+ )
23
+ end
18
24
 
19
- def check_request
20
- @request.errors.blank? || jsonapi_render_errors(json: @request)
21
- end
25
+ # Render an error response if the parsed request got any error.
26
+ #
27
+ # @api public
28
+ def check_request
29
+ @request.errors.blank? || jsonapi_render_errors(json: @request)
30
+ end
22
31
 
23
- def resource_params
24
- build_params_for(:resource)
25
- end
32
+ # Override the JSONAPI::ActsAsResourceController#process_request method.
33
+ #
34
+ # It might be removed when the following line on JR is fixed:
35
+ # https://github.com/cerebris/jsonapi-resources/blob/release-0-8/lib/jsonapi/acts_as_resource_controller.rb#L62
36
+ #
37
+ # @return [String]
38
+ #
39
+ # @api public
40
+ def process_request
41
+ process_operations
42
+ render_results(@operation_results)
43
+ rescue => e
44
+ handle_exceptions(e)
45
+ end
26
46
 
27
- def relationship_params
28
- build_params_for(:relationship)
29
- end
47
+ # Helper to get params for the main resource.
48
+ #
49
+ # @return [Hash]
50
+ #
51
+ # @api public
52
+ def resource_params
53
+ build_params_for(:resource)
54
+ end
55
+
56
+ # Helper to get params for relationship params.
57
+ #
58
+ # @return [Hash]
59
+ #
60
+ # @api public
61
+ def relationship_params
62
+ build_params_for(:relationship)
63
+ end
30
64
 
31
- private
65
+ private
32
66
 
33
- def build_params_for(param_type)
34
- return {} if @request.operations.empty?
67
+ # Extract params from request and build a Hash with params
68
+ # for either the main resource or relationships.
69
+ #
70
+ # @return [Hash]
71
+ #
72
+ # @api private
73
+ def build_params_for(param_type)
74
+ return {} if @request.operations.empty?
35
75
 
36
- keys = %i(attributes to_one to_many)
37
- operation = @request.operations.find { |e| e.data.keys & keys == keys }
76
+ keys = %i(attributes to_one to_many)
77
+ operation = @request.operations.find { |e| e.options[:data].keys & keys == keys }
38
78
 
39
- if operation.nil?
40
- {}
41
- elsif param_type == :relationship
42
- operation.data.values_at(:to_one, :to_many).compact.reduce(&:merge)
43
- else
44
- operation.data[:attributes]
45
- end
79
+ if operation.nil?
80
+ {}
81
+ elsif param_type == :relationship
82
+ operation.options[:data].values_at(:to_one, :to_many).compact.reduce(&:merge)
83
+ else
84
+ operation.options[:data][:attributes]
46
85
  end
47
86
  end
48
87
  end
@@ -1,5 +1,5 @@
1
1
  module JSONAPI
2
2
  module Utils
3
- VERSION = '0.4.8'
3
+ VERSION = '0.4.9'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jsonapi-utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.8
4
+ version: 0.4.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tiago Guedes
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2017-01-20 00:00:00.000000000 Z
12
+ date: 2017-03-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: jsonapi-resources
@@ -17,14 +17,14 @@ dependencies:
17
17
  requirements:
18
18
  - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: 0.7.0
20
+ version: 0.8.0
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - "~>"
26
26
  - !ruby/object:Gem::Version
27
- version: 0.7.0
27
+ version: 0.8.0
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: bundler
30
30
  requirement: !ruby/object:Gem::Requirement