jsonapi-utils 0.4.3 → 0.4.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -1
- data/lib/jsonapi/utils.rb +13 -13
- data/lib/jsonapi/utils/version.rb +1 -1
- metadata +16 -36
- data/.gitignore +0 -22
- data/.rspec +0 -2
- data/.travis.yml +0 -9
- data/Gemfile +0 -4
- data/Rakefile +0 -8
- data/jsonapi-utils.gemspec +0 -32
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e4f9e4f00521de390580aa6cc15c92f785ae0a5
|
4
|
+
data.tar.gz: 42c4dc5facd04f531fe5e19790463785e45962d2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ea64cf3d3f5900d25b194047f045ccc0450315108223250cbfab943e89f8ccd25ecff1aca8d056bb1454aa2e9e933abc08177688f110f02f4b91095f99ffdcae
|
7
|
+
data.tar.gz: 249e6f9b09eb464091f0c4aa38fb19920f42a3b62ad3d0d547d7274d2cdb2712230a5493711ec83e5efcea0efd5efe52bdc3b040339c5cf51d73c60bfb75381e
|
data/README.md
CHANGED
@@ -44,6 +44,9 @@ jsonapi_render json: User.find(params[:id])
|
|
44
44
|
# Collection rendering
|
45
45
|
jsonapi_render json: User.all
|
46
46
|
|
47
|
+
# Specify a particular HTTP status code
|
48
|
+
jsonapi_render json: new_user, status: :created
|
49
|
+
|
47
50
|
# Forcing a different resource
|
48
51
|
jsonapi_render json: User.all, options: { resource: V2::UserResource }
|
49
52
|
|
@@ -194,7 +197,7 @@ class PostsController < BaseController
|
|
194
197
|
end
|
195
198
|
```
|
196
199
|
|
197
|
-
###
|
200
|
+
### Errors
|
198
201
|
|
199
202
|
#### Not found
|
200
203
|
|
data/lib/jsonapi/utils.rb
CHANGED
@@ -5,18 +5,15 @@ require 'jsonapi/utils/exceptions'
|
|
5
5
|
module JSONAPI
|
6
6
|
module Utils
|
7
7
|
def self.included(base)
|
8
|
-
base.helper_method
|
8
|
+
if base.respond_to?(:helper_method)
|
9
|
+
base.before_action :setup_request, :check_request
|
10
|
+
base.helper_method :jsonapi_render, :jsonapi_serialize
|
11
|
+
end
|
9
12
|
end
|
10
13
|
|
11
14
|
def jsonapi_render(json:, status: nil, options: {})
|
12
|
-
|
13
|
-
|
14
|
-
if @request.errors.present?
|
15
|
-
render_errors(@request.errors)
|
16
|
-
else
|
17
|
-
body = jsonapi_serialize(json, options)
|
18
|
-
render json: body, status: status || @_response_document.status
|
19
|
-
end
|
15
|
+
body = jsonapi_serialize(json, options)
|
16
|
+
render json: body, status: status || @_response_document.status
|
20
17
|
rescue => e
|
21
18
|
handle_exceptions(e)
|
22
19
|
ensure
|
@@ -26,8 +23,9 @@ module JSONAPI
|
|
26
23
|
end
|
27
24
|
|
28
25
|
def jsonapi_render_errors(exception)
|
29
|
-
|
30
|
-
|
26
|
+
result = jsonapi_format_errors(exception)
|
27
|
+
errors = result.errors
|
28
|
+
render json: { errors: errors }, status: errors.first.status
|
31
29
|
end
|
32
30
|
|
33
31
|
def jsonapi_format_errors(exception)
|
@@ -52,8 +50,6 @@ module JSONAPI
|
|
52
50
|
end
|
53
51
|
|
54
52
|
def jsonapi_serialize(records, options = {})
|
55
|
-
setup_request
|
56
|
-
|
57
53
|
if records.is_a?(Hash)
|
58
54
|
hash = records.with_indifferent_access
|
59
55
|
records = hash_to_active_record(hash[:data], options[:model])
|
@@ -256,5 +252,9 @@ module JSONAPI
|
|
256
252
|
server_error_callbacks: (self.class.server_error_callbacks || [])
|
257
253
|
)
|
258
254
|
end
|
255
|
+
|
256
|
+
def check_request
|
257
|
+
@request.errors.blank? || render_errors(@request.errors)
|
258
|
+
end
|
259
259
|
end
|
260
260
|
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.
|
4
|
+
version: 0.4.4
|
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: 2016-
|
12
|
+
date: 2016-05-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: jsonapi-resources
|
@@ -53,20 +53,6 @@ dependencies:
|
|
53
53
|
- - "~>"
|
54
54
|
- !ruby/object:Gem::Version
|
55
55
|
version: '10.0'
|
56
|
-
- !ruby/object:Gem::Dependency
|
57
|
-
name: rspec-rails
|
58
|
-
requirement: !ruby/object:Gem::Requirement
|
59
|
-
requirements:
|
60
|
-
- - "~>"
|
61
|
-
- !ruby/object:Gem::Version
|
62
|
-
version: '3.1'
|
63
|
-
type: :development
|
64
|
-
prerelease: false
|
65
|
-
version_requirements: !ruby/object:Gem::Requirement
|
66
|
-
requirements:
|
67
|
-
- - "~>"
|
68
|
-
- !ruby/object:Gem::Version
|
69
|
-
version: '3.1'
|
70
56
|
- !ruby/object:Gem::Dependency
|
71
57
|
name: sqlite3
|
72
58
|
requirement: !ruby/object:Gem::Requirement
|
@@ -82,61 +68,61 @@ dependencies:
|
|
82
68
|
- !ruby/object:Gem::Version
|
83
69
|
version: '0'
|
84
70
|
- !ruby/object:Gem::Dependency
|
85
|
-
name:
|
71
|
+
name: rails
|
86
72
|
requirement: !ruby/object:Gem::Requirement
|
87
73
|
requirements:
|
88
74
|
- - "~>"
|
89
75
|
- !ruby/object:Gem::Version
|
90
|
-
version: '4.
|
76
|
+
version: '4.2'
|
91
77
|
type: :development
|
92
78
|
prerelease: false
|
93
79
|
version_requirements: !ruby/object:Gem::Requirement
|
94
80
|
requirements:
|
95
81
|
- - "~>"
|
96
82
|
- !ruby/object:Gem::Version
|
97
|
-
version: '4.
|
83
|
+
version: '4.2'
|
98
84
|
- !ruby/object:Gem::Dependency
|
99
|
-
name:
|
85
|
+
name: rspec-rails
|
100
86
|
requirement: !ruby/object:Gem::Requirement
|
101
87
|
requirements:
|
102
88
|
- - "~>"
|
103
89
|
- !ruby/object:Gem::Version
|
104
|
-
version:
|
90
|
+
version: '3.1'
|
105
91
|
type: :development
|
106
92
|
prerelease: false
|
107
93
|
version_requirements: !ruby/object:Gem::Requirement
|
108
94
|
requirements:
|
109
95
|
- - "~>"
|
110
96
|
- !ruby/object:Gem::Version
|
111
|
-
version:
|
97
|
+
version: '3.1'
|
112
98
|
- !ruby/object:Gem::Dependency
|
113
|
-
name:
|
99
|
+
name: factory_girl
|
114
100
|
requirement: !ruby/object:Gem::Requirement
|
115
101
|
requirements:
|
116
102
|
- - "~>"
|
117
103
|
- !ruby/object:Gem::Version
|
118
|
-
version: '4.
|
104
|
+
version: '4.5'
|
119
105
|
type: :development
|
120
106
|
prerelease: false
|
121
107
|
version_requirements: !ruby/object:Gem::Requirement
|
122
108
|
requirements:
|
123
109
|
- - "~>"
|
124
110
|
- !ruby/object:Gem::Version
|
125
|
-
version: '4.
|
111
|
+
version: '4.5'
|
126
112
|
- !ruby/object:Gem::Dependency
|
127
|
-
name:
|
113
|
+
name: smart_rspec
|
128
114
|
requirement: !ruby/object:Gem::Requirement
|
129
115
|
requirements:
|
130
|
-
- - "
|
116
|
+
- - "~>"
|
131
117
|
- !ruby/object:Gem::Version
|
132
|
-
version:
|
118
|
+
version: 0.1.4
|
133
119
|
type: :development
|
134
120
|
prerelease: false
|
135
121
|
version_requirements: !ruby/object:Gem::Requirement
|
136
122
|
requirements:
|
137
|
-
- - "
|
123
|
+
- - "~>"
|
138
124
|
- !ruby/object:Gem::Version
|
139
|
-
version:
|
125
|
+
version: 0.1.4
|
140
126
|
description: A Rails way to get your API's data serialized through JSON API's specs
|
141
127
|
(http://jsosapi.org)
|
142
128
|
email:
|
@@ -146,17 +132,11 @@ executables: []
|
|
146
132
|
extensions: []
|
147
133
|
extra_rdoc_files: []
|
148
134
|
files:
|
149
|
-
- ".gitignore"
|
150
|
-
- ".rspec"
|
151
|
-
- ".travis.yml"
|
152
135
|
- CODE_OF_CONDUCT.md
|
153
|
-
- Gemfile
|
154
136
|
- LICENSE.txt
|
155
137
|
- README.md
|
156
|
-
- Rakefile
|
157
138
|
- bin/console
|
158
139
|
- bin/setup
|
159
|
-
- jsonapi-utils.gemspec
|
160
140
|
- lib/jsonapi/utils.rb
|
161
141
|
- lib/jsonapi/utils/exceptions.rb
|
162
142
|
- lib/jsonapi/utils/version.rb
|
data/.gitignore
DELETED
data/.rspec
DELETED
data/.travis.yml
DELETED
data/Gemfile
DELETED
data/Rakefile
DELETED
data/jsonapi-utils.gemspec
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'jsonapi/utils/version'
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = 'jsonapi-utils'
|
8
|
-
spec.version = JSONAPI::Utils::VERSION
|
9
|
-
spec.authors = ['Tiago Guedes', 'Douglas André']
|
10
|
-
spec.email = ['tiagopog@gmail.com', 'douglas@beautydate.com.br']
|
11
|
-
|
12
|
-
spec.summary = %q{JSON::Utils is a simple way to get a full-featured JSON API serialization for your controller's responses.}
|
13
|
-
spec.description = %q{A Rails way to get your API's data serialized through JSON API's specs (http://jsosapi.org)}
|
14
|
-
spec.homepage = 'https://github.com/b2beauty/jsonapi-utils'
|
15
|
-
spec.license = 'MIT'
|
16
|
-
|
17
|
-
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
-
spec.bindir = 'exe'
|
19
|
-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
-
spec.require_paths = ['lib']
|
21
|
-
|
22
|
-
spec.add_runtime_dependency 'jsonapi-resources', '~> 0.7.0'
|
23
|
-
|
24
|
-
spec.add_development_dependency 'bundler', '~> 1.10'
|
25
|
-
spec.add_development_dependency 'rake', '~> 10.0'
|
26
|
-
spec.add_development_dependency 'rspec-rails', '~> 3.1'
|
27
|
-
spec.add_development_dependency 'sqlite3'
|
28
|
-
spec.add_development_dependency 'factory_girl', '~> 4.5'
|
29
|
-
spec.add_development_dependency 'jsonapi-resources', '~> 0.7.0'
|
30
|
-
spec.add_development_dependency 'rails', '~> 4.2'
|
31
|
-
spec.add_development_dependency 'pry'
|
32
|
-
end
|