Module: JSONAPI::Utils::Request
- Defined in:
- lib/jsonapi/utils/request.rb
Instance Method Summary collapse
-
#check_request ⇒ Object
Render an error response if the parsed request got any error.
-
#jsonapi_request_handling ⇒ Object
Setup and check request before action gets actually evaluated.
-
#process_request ⇒ String
Override the JSONAPI::ActsAsResourceController#process_request method.
-
#relationship_params ⇒ Hash
Helper to get params for relationship params.
-
#resource_params ⇒ Hash
Helper to get params for the main resource.
-
#setup_request ⇒ JSONAPI::RequestParser
Instantiate the request object.
Instance Method Details
#check_request ⇒ Object
Render an error response if the parsed request got any error.
33 34 35 |
# File 'lib/jsonapi/utils/request.rb', line 33 def check_request @request.errors.blank? || jsonapi_render_errors(json: @request) end |
#jsonapi_request_handling ⇒ Object
Setup and check request before action gets actually evaluated.
6 7 8 9 10 11 12 13 14 |
# File 'lib/jsonapi/utils/request.rb', line 6 def jsonapi_request_handling setup_request check_request rescue JSONAPI::Exceptions::InvalidResource, JSONAPI::Exceptions::InvalidField, JSONAPI::Exceptions::InvalidInclude, JSONAPI::Exceptions::InvalidSortCriteria => err jsonapi_render_errors(json: err) end |
#process_request ⇒ String
Override the JSONAPI::ActsAsResourceController#process_request method.
It might be removed when the following line on JR is fixed: github.com/cerebris/jsonapi-resources/blob/release-0-8/lib/jsonapi/acts_as_resource_controller.rb#L62
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/jsonapi/utils/request.rb', line 45 def process_request operations = @request.operations unless JSONAPI.configuration.resource_cache.nil? operations.each {|op| op.[:cache_serializer] = resource_serializer } end results = process_operations(operations) render_results(results) rescue => e handle_exceptions(e) end |
#relationship_params ⇒ Hash
Helper to get params for relationship params.
70 71 72 |
# File 'lib/jsonapi/utils/request.rb', line 70 def relationship_params build_params_for(:relationship) end |
#resource_params ⇒ Hash
Helper to get params for the main resource.
61 62 63 |
# File 'lib/jsonapi/utils/request.rb', line 61 def resource_params build_params_for(:resource) end |
#setup_request ⇒ JSONAPI::RequestParser
Instantiate the request object.
21 22 23 24 25 26 27 28 |
# File 'lib/jsonapi/utils/request.rb', line 21 def setup_request @request ||= JSONAPI::RequestParser.new( params, context: context, key_formatter: key_formatter, server_error_callbacks: (self.class.server_error_callbacks || []) ) end |