jsonapi_for_rails 0.1.2 → 0.1.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 93a2ddec3ac6ff246183b9687fc7b0bc7252503c
4
- data.tar.gz: 20a759301147ae6b652ef7c5ba0d046b9c94c0cc
3
+ metadata.gz: 794bfadafffbe093f0b1db6199da1a91ceaa8ed8
4
+ data.tar.gz: 84cc03b0fd7b33160d1cc5a4a90c35b0754fa7ca
5
5
  SHA512:
6
- metadata.gz: 2d9795ba3d003df4e7a2c403a4d2b7140e74f219eaae1e977c334c43af4b2dec8c4fa994c0697e2427cf852cb3210bcc60443418ce89570024c11e00bad7223a
7
- data.tar.gz: beb93088916a4833d04f1996b7879b18223dd4439189a4c2b7cf4414a38dc72297b214ff9b2f0ce567592909a48848bcf4749d4cf7fcc3fd2ae39a3efec28059
6
+ metadata.gz: 6dc9c92dd8992facc8c92f845cd183da112115c0a878f0ce2f10930b73d7f3dbb04353dec5ef603378726222237cb11a3296f54bb31fc9481313d48d57f033e5
7
+ data.tar.gz: c971dcd15bc2bebb5cd19c139fbd12d79002fa3a6b7e56d972839324b32931918e250bda38ee969bafc3c5fe34f7ed02ca96e5b8166978a64d172c7b4fe0364c
data/README.md CHANGED
@@ -118,16 +118,15 @@ After populating your database and launching the built-in Rails server with the
118
118
  ```bash
119
119
  $ # Get the list of articles
120
120
  $ curl 'http://localhost:3000/api/v1/articles'
121
- {"data":[{"type":"articles","id":184578894},{"type":"articles","id":388548390},{"type":"articles","id":618037523},{"type":"articles","id":994552601}]}
121
+ {"data":[{"type":"articles","id":"184578894"},{"type":"articles","id":"388548390"},{"type":"articles","id":"618037523"},{"type":"articles","id":"994552601"}]}
122
122
  $
123
123
  $ # Get an article
124
124
  $ curl 'http://localhost:3000/api/v1/articles/184578894'
125
- {"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 ...","created_at":"2016-02-22T16:57:43.401Z","updated_at":"2016-02-22T16:57:43.401Z"},"relationships":{"author":{"data":{"type":"authors","id":1023487079}}}}}
125
+ {"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"}}}}}
126
126
  $
127
127
  $ # Get only the title and author of an article, include the author's name
128
128
  $ curl 'http://localhost:3000/api/v1/articles/184578894?filter%5Barticles%5D=title,author;include=author;filter%5Bauthors%5D=name'
129
- {"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":"..."},"relationships":{}}}]}
130
-
129
+ {"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":{}}}]}
131
130
  ```
132
131
 
133
132
  ## Modifying the default API behaviour
@@ -215,8 +214,8 @@ class ArticlesController < JsonapiResourcesController
215
214
  def relationship_update
216
215
  # @jsonapi_relationship[:params] contains the parsed request body.
217
216
  # It is available for all relationship actions except relationship_show.
218
- # @jsonapi_relationship[:params][:data] is a Hash for relationships
219
- # of type :to_one, and an Array for relationships of type :to_many.
217
+ # @jsonapi_relationship[:params][:data] behaves like a Hash for relationships of type :to_one,
218
+ # and as an Array for relationships of type :to_many.
220
219
  @jsonapi_relationship # => {:definition=>{...}, :params=>{"data"=>{"type"=>"authors", "id"=>"234455384"}}}
221
220
 
222
221
  # ...
@@ -11,10 +11,11 @@ module JsonapiForRails::Controller
11
11
  # TODO: pagination
12
12
  def index
13
13
  @json = {data: []}
14
+ @jsonapi_debug=[jsonapi_model_class,jsonapi_model_class.all]
14
15
  jsonapi_model_class.all.each do |record|
15
16
  @json[:data] << {
16
17
  type: record.class.to_s.underscore.pluralize, # TODO: factor out type generation from class
17
- id: record.id
18
+ id: record.id.to_s
18
19
  }
19
20
  end
20
21
  render_json @json
@@ -17,13 +17,13 @@ module JsonapiForRails::Controller
17
17
  if @jsonapi_relationship[:definition][:type] == :to_one
18
18
  @json = {
19
19
  type: @jsonapi_relationship[:definition][:receiver][:type],
20
- id: rel.id
20
+ id: rel.id.to_s
21
21
  }
22
22
  elsif @jsonapi_relationship[:definition][:type] == :to_many
23
23
  @json = rel.collect do |r|
24
24
  {
25
25
  type: @jsonapi_relationship[:definition][:receiver][:type],
26
- id: r.id
26
+ id: r.id.to_s
27
27
  }
28
28
  end
29
29
  end
@@ -21,8 +21,6 @@ module JsonapiForRails::Controller
21
21
 
22
22
  module InstanceMethods
23
23
  def jsonapi_require_record
24
- #$stderr.puts "@jsonapi_sparse_fieldsets: #{@jsonapi_sparse_fieldsets.inspect}"
25
- #$stderr.puts "JsonapiForRails::Controller::RecordFromRequest#jsonapi_require_record called"
26
24
  if params[:relationship]
27
25
  # relationship action
28
26
  @jsonapi_record = jsonapi_model_class.find_by_id params["#{jsonapi_model_class_name.underscore}_id"].to_i
@@ -40,7 +38,6 @@ module JsonapiForRails::Controller
40
38
  end
41
39
  #$stderr.puts "@jsonapi_record: #{@jsonapi_record.inspect}"
42
40
  return if @jsonapi_record
43
-
44
41
  render_error 401, "Bad request."
45
42
  end
46
43
 
@@ -41,7 +41,7 @@ module JsonapiForRails::Model
41
41
  #$stderr.puts "self.#{association.name}: #{record.class}"
42
42
  relationship[:data] << {
43
43
  type: record.class.to_s.underscore.pluralize, # TODO: factor out type generation from class
44
- id: record.id
44
+ id: record.id.to_s
45
45
  }
46
46
  end
47
47
 
@@ -58,7 +58,7 @@ module JsonapiForRails::Model
58
58
  if record = self.send(association.name)
59
59
  relationship[:data] = {
60
60
  type: record.class.to_s.underscore.pluralize, # TODO: factor out type generation from class
61
- id: record.id
61
+ id: record.id.to_s
62
62
  }
63
63
  end
64
64
  end
@@ -73,7 +73,7 @@ module JsonapiForRails::Model
73
73
  =end
74
74
  data: {
75
75
  type: jsonapi_model_type,
76
- id: self.id,
76
+ id: self.id.to_s,
77
77
 
78
78
  attributes: attrs,
79
79
 
@@ -1,5 +1,6 @@
1
1
  module JsonapiForRails
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.3'
3
+ # 0.1.3: fix non-string id bug (http://jsonapi.org/format/1.0/#document-resource-object-identification)
3
4
  # 0.1.2: add ruby version dependency to gem
4
5
  # 0.1.1: fix @jsonapi_relationship[:params] bug, it is now set correctly
5
6
  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.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Doga Armangil