jsonapi_for_rails 0.1.5 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/README.md +66 -5
- data/lib/jsonapi_for_rails/controller/utils/render.rb +17 -12
- data/lib/jsonapi_for_rails/version.rb +1 -6
- metadata +1 -1
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4d66990c4fcd9b30954c5e00c96243eb6faa5a50
|
4
|
+
data.tar.gz: c28bb329e60c24f4f914f11678adc073847b9de5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f803e8bf7143d0e415c6839ff692c19c2adcf2edfc3f9098fc6f798b05315f490b833a9062b8cc749d514f4f54d25ccf5d676a187dc9a3371981732e4f4b63c8
|
7
|
+
data.tar.gz: 8b9fb2cd302183d76b57f8958eb93a62062d9042eebfd6be40a6f1c508e55d02b4acf68b4b99a6d6eb1e84f1add2305af403861a3895777b2375e2f78c4f243d
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/README.md
CHANGED
@@ -28,13 +28,13 @@ $ cat >> Gemfile
|
|
28
28
|
gem 'jsonapi_for_rails'
|
29
29
|
$
|
30
30
|
$ # Install
|
31
|
-
$ # Optional security paramater: --trust-policy MediumSecurity
|
31
|
+
$ # (Optional security paramater: --trust-policy MediumSecurity)
|
32
32
|
$ bundle install --trust-policy MediumSecurity
|
33
33
|
$
|
34
34
|
$ # Check the used version
|
35
35
|
$ bin/rails console
|
36
36
|
irb(main):001:0> JsonapiForRails::VERSION
|
37
|
-
=> "0.1.
|
37
|
+
=> "0.1.6"
|
38
38
|
irb(main):002:0> exit
|
39
39
|
$
|
40
40
|
```
|
@@ -128,16 +128,77 @@ After populating your database and launching the built-in Rails server with the
|
|
128
128
|
|
129
129
|
```bash
|
130
130
|
$ # Get the list of articles
|
131
|
+
$ # (the response body is prettified when the Rails environment is 'development' or 'test')
|
131
132
|
$ curl 'http://localhost:3000/api/v1/articles'
|
132
|
-
{
|
133
|
+
{
|
134
|
+
"data": [
|
135
|
+
{
|
136
|
+
"type": "articles",
|
137
|
+
"id": "618037523"
|
138
|
+
},
|
139
|
+
{
|
140
|
+
"type": "articles",
|
141
|
+
"id": "994552601"
|
142
|
+
}
|
143
|
+
]
|
144
|
+
}
|
133
145
|
$
|
134
146
|
$ # Get an article
|
135
147
|
$ curl 'http://localhost:3000/api/v1/articles/618037523'
|
136
|
-
{
|
148
|
+
{
|
149
|
+
"data": {
|
150
|
+
"type": "articles",
|
151
|
+
"id": "618037523",
|
152
|
+
"attributes": {
|
153
|
+
"title": "UK bank pay and bonuses in the spotlight as results season starts",
|
154
|
+
"content": "The pay deals handed to the bosses of Britain’s biggest banks ...",
|
155
|
+
"created_at": "2016-03-02 14:33:49 UTC",
|
156
|
+
"updated_at": "2016-03-02 14:33:49 UTC"
|
157
|
+
},
|
158
|
+
"relationships": {
|
159
|
+
"author": {
|
160
|
+
"data": {
|
161
|
+
"type": "authors",
|
162
|
+
"id": "1023487079"
|
163
|
+
}
|
164
|
+
},
|
165
|
+
}
|
166
|
+
}
|
167
|
+
}
|
137
168
|
$
|
138
169
|
$ # Get only the title and author of an article, include the author's name
|
139
170
|
$ curl 'http://localhost:3000/api/v1/articles/618037523?filter%5Barticles%5D=title,author;include=author;filter%5Bauthors%5D=name'
|
140
|
-
{
|
171
|
+
{
|
172
|
+
"data": {
|
173
|
+
"type": "articles",
|
174
|
+
"id": "618037523",
|
175
|
+
"attributes": {
|
176
|
+
"title": "UK bank pay and bonuses in the spotlight as results season starts"
|
177
|
+
},
|
178
|
+
"relationships": {
|
179
|
+
"author": {
|
180
|
+
"data": {
|
181
|
+
"type": "authors",
|
182
|
+
"id": "1023487079"
|
183
|
+
}
|
184
|
+
}
|
185
|
+
}
|
186
|
+
},
|
187
|
+
"include": [
|
188
|
+
{
|
189
|
+
"data": {
|
190
|
+
"type": "authors",
|
191
|
+
"id": "1023487079",
|
192
|
+
"attributes": {
|
193
|
+
"name": "Jill T..."
|
194
|
+
},
|
195
|
+
"relationships": {
|
196
|
+
}
|
197
|
+
}
|
198
|
+
}
|
199
|
+
]
|
200
|
+
}
|
201
|
+
$
|
141
202
|
```
|
142
203
|
|
143
204
|
## Modifying the default API behaviour
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
1
3
|
module JsonapiForRails::Controller
|
2
4
|
|
3
5
|
module Utils
|
@@ -25,30 +27,33 @@ module JsonapiForRails::Controller
|
|
25
27
|
return
|
26
28
|
end
|
27
29
|
|
28
|
-
@
|
29
|
-
@
|
30
|
-
@
|
30
|
+
@jsonapi_status = 200
|
31
|
+
@jsonapi_json = ['development', 'test'].include?(Rails.env) ? JSON.pretty_generate(object) : JSON.generate(object)
|
32
|
+
@jsonapi_content_type = JSONAPI[:content_type]
|
31
33
|
|
32
34
|
render(
|
33
|
-
|
34
|
-
|
35
|
-
|
35
|
+
plain: @jsonapi_json,
|
36
|
+
#json: @jsonapi_json,
|
37
|
+
status: @jsonapi_status,
|
38
|
+
content_type: @jsonapi_content_type
|
36
39
|
)
|
37
40
|
end
|
38
41
|
|
39
42
|
def render_error status, title
|
40
|
-
@
|
41
|
-
|
43
|
+
@jsonapi_status = status
|
44
|
+
object = {
|
42
45
|
errors: [
|
43
46
|
{title: title}
|
44
47
|
]
|
45
48
|
}
|
46
|
-
@
|
49
|
+
@jsonapi_json = ['development', 'test'].include?(Rails.env) ? JSON.pretty_generate(object) : JSON.generate(object)
|
50
|
+
@jsonapi_content_type = JSONAPI[:content_type]
|
47
51
|
|
48
52
|
render(
|
49
|
-
|
50
|
-
|
51
|
-
|
53
|
+
plain: @jsonapi_json,
|
54
|
+
#json: @jsonapi_json,
|
55
|
+
status: @jsonapi_status,
|
56
|
+
content_type: @jsonapi_content_type
|
52
57
|
)
|
53
58
|
end
|
54
59
|
end
|
@@ -1,8 +1,3 @@
|
|
1
1
|
module JsonapiForRails
|
2
|
-
VERSION = '0.1.
|
3
|
-
# 0.1.5: add digital signature
|
4
|
-
# 0.1.4: gem now requires rails >= 4 instead of 5.0.0.beta2
|
5
|
-
# 0.1.3: fix non-string id bug (http://jsonapi.org/format/1.0/#document-resource-object-identification)
|
6
|
-
# 0.1.2: add ruby 2.0 dependency to gem
|
7
|
-
# 0.1.1: fix @jsonapi_relationship[:params] bug, it is now set correctly
|
2
|
+
VERSION = '0.1.6'
|
8
3
|
end
|
metadata
CHANGED
metadata.gz.sig
CHANGED
Binary file
|