jsonapi-utils 0.3.0 → 0.3.1

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: 4b973c25edc256609e9a73af0eb75610ccbdc73c
4
- data.tar.gz: 2041dfe51b129f936b4bceae828c536f56b60884
3
+ metadata.gz: 787dd4e20ecfc0d81ad5221eee77897c4baece34
4
+ data.tar.gz: 8fb454390a928f5af72ad95334448fc5bac631b3
5
5
  SHA512:
6
- metadata.gz: ee52a5cc6aef9f83190b72ce202fca841dc0f394923f32f371a4703a9dca53b5a5067f6910ed5dba5d0ca30a6df057c0711f5ca8b9660ea692efd36c2d476c4a
7
- data.tar.gz: d32f1cc5923ab3c916040089cdee77c7270b6d1c7c8916c9e90739540f67434880cdb49487679848a7d428f0070d241e309f4728444264f6f822cb353207c281
6
+ metadata.gz: f38a040d3b83edc9f62cd13cd6be0554af7e6d9dd4261cb38d11617affc01c900d0c7f75bf7def9c5420ba9b234440fe5d8ffb570e9e2a07cafb0e661cc91e8d
7
+ data.tar.gz: 772676ea003068c1c5b763e57be30b73266f96d9b5ba8f137202f77612a557196c828a661d60ce334adba1a4ef32b4c5856d6be7c1f185bcb9deac24715e307c
data/lib/jsonapi/utils.rb CHANGED
@@ -16,24 +16,26 @@ module JSONAPI
16
16
  end
17
17
  end
18
18
 
19
- def jsonapi_errors(exception)
20
- JSONAPI::ErrorsOperationResult.new(exception.errors[0].code, exception.errors).as_json
19
+ def jsonapi_render_errors(exception)
20
+ error = jsonapi_format_errors(exception)
21
+ render json: { errors: error.errors }, status: error.code
22
+ end
23
+
24
+ def jsonapi_format_errors(exception)
25
+ JSONAPI::ErrorsOperationResult.new(exception.errors[0].code, exception.errors)
21
26
  end
22
27
 
23
28
  def jsonapi_render_internal_server_error
24
- errors = ::JSONAPI::Utils::Exceptions::InternalServerError.new
25
- render json: jsonapi_errors(errors), status: 500
29
+ jsonapi_render_errors(::JSONAPI::Utils::Exceptions::InternalServerError.new)
26
30
  end
27
31
 
28
32
  def jsonapi_render_bad_request
29
- errors = ::JSONAPI::Utils::Exceptions::BadRequest.new
30
- render json: jsonapi_errors(errors), status: 400
33
+ jsonapi_render_errors(::JSONAPI::Utils::Exceptions::BadRequest.new)
31
34
  end
32
35
 
33
36
  def jsonapi_render_not_found
34
37
  id = extract_ids(@request.params)
35
- exception = JSONAPI::Exceptions::RecordNotFound.new(id)
36
- render json: jsonapi_errors(exception), status: 404
38
+ jsonapi_render_errors(JSONAPI::Exceptions::RecordNotFound.new(id))
37
39
  end
38
40
 
39
41
  def jsonapi_render_not_found_with_null
@@ -1,40 +1,26 @@
1
1
  require 'jsonapi/utils/version'
2
2
 
3
- module JSONAPI
4
- module Utils
5
- module Exceptions
6
- class BadRequest < ::JSONAPI::Exceptions::Error
7
- def code; 400 end
3
+ module JSONAPI::Utils::Exceptions
4
+ class BadRequest < ::JSONAPI::Exceptions::Error
5
+ def code; 400 end
8
6
 
9
- def errors
10
- [JSONAPI::Error.new(code: 400,
11
- status: :bad_request,
12
- title: 'Bad Request',
13
- detail: 'This request is not supported.')]
14
- end
15
- end
16
-
17
- class NotFoundError < ::JSONAPI::Exceptions::Error
18
- def code; 404 end
19
-
20
- def errors
21
- [JSONAPI::Error.new(code: 404,
22
- status: :not_found,
23
- title: 'Not Found',
24
- detail: 'The requested resource was not found.')]
25
- end
26
- end
7
+ def errors
8
+ [JSONAPI::Error.new(code: 400,
9
+ status: :bad_request,
10
+ title: 'Bad Request',
11
+ detail: 'This request is not supported.')]
12
+ end
13
+ end
27
14
 
28
- class InternalServerError < ::JSONAPI::Exceptions::Error
29
- def code; 500 end
15
+ class InternalServerError < ::JSONAPI::Exceptions::Error
16
+ def code; 500 end
30
17
 
31
- def errors
32
- [JSONAPI::Error.new(code: 500,
33
- status: :internal_server_error,
34
- title: 'Internal Server Error',
35
- detail: 'An internal error ocurred while processing the request.')]
36
- end
37
- end
18
+ def errors
19
+ [JSONAPI::Error.new(code: 500,
20
+ status: :internal_server_error,
21
+ title: 'Internal Server Error',
22
+ detail: 'An internal error ocurred while processing the request.')]
38
23
  end
39
24
  end
40
25
  end
26
+
@@ -1,5 +1,5 @@
1
1
  module JSONAPI
2
2
  module Utils
3
- VERSION = '0.3.0'
3
+ VERSION = '0.3.1'
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.3.0
4
+ version: 0.3.1
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: 2015-10-28 00:00:00.000000000 Z
12
+ date: 2015-10-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler