jsonapi_for_rails 0.1.5 → 0.1.6

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: 8f4dd3218dadbf9a805eb8c2436a83167558657a
4
- data.tar.gz: 3688d50e8ddea9629ac56428a59ba10018327f6e
3
+ metadata.gz: 4d66990c4fcd9b30954c5e00c96243eb6faa5a50
4
+ data.tar.gz: c28bb329e60c24f4f914f11678adc073847b9de5
5
5
  SHA512:
6
- metadata.gz: c684e85d591a7961b5bda7a34234fe76674670a0c2e06d45eda50c5c8103469cc3356a1cc489b6440b1e85344cb8010466b1ca7c38e29576f9d439b8acbe8e27
7
- data.tar.gz: be0e92ba9720ca2692cf685e74bac9d041a9591bc554f89e56185d22c7e09fe8736447a9f6ae48215607591d253bee2640dc66ec0a3e00f64473aace84862e98
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.4"
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
- {"data":[{"type":"articles","id":"618037523"},{"type":"articles","id":"184578894"},{"type":"articles","id":"388548390"},{"type":"articles","id":"994552601"}]}
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
- {"data":{"type":"articles","id":"618037523","attributes":{"title":"UK bank pay and bonuses in the spotlight as results season starts","content":"The pay deals handed to the bosses of Britain’s biggest banks will be in focus this week ...","created_at":"2016-02-26T16:18:39.265Z","updated_at":"2016-02-26T16:18:39.265Z"},"relationships":{"author":{"data":{"type":"authors","id":"1023487079"}}}}}
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
- {"data":{"type":"articles","id":"618037523","attributes":{"title":"UK bank pay and bonuses in the spotlight as results season starts"},"relationships":{"author":{"data":{"type":"authors","id":"1023487079"}}}},"include":[{"data":{"type":"authors","id":"1023487079","attributes":{"name":"Jill ..."},"relationships":{}}}]}
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
- @status = 200
29
- @json = object
30
- @content_type = JSONAPI[:content_type]
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
- json: @json,
34
- status: @status,
35
- content_type: @content_type
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
- @status = status
41
- @json = {
43
+ @jsonapi_status = status
44
+ object = {
42
45
  errors: [
43
46
  {title: title}
44
47
  ]
45
48
  }
46
- @content_type = JSONAPI[:content_type]
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
- json: @json,
50
- status: @status,
51
- content_type: @content_type
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.5'
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
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jsonapi_for_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Doga Armangil
metadata.gz.sig CHANGED
Binary file