jsonapi_for_rails 0.1.0 → 0.1.1

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: f9cfc12b29fbd2b7976e2f8afdd25efd52b8f1e3
4
- data.tar.gz: 4a677ebb54f964c8e339b56dfe2c03d886f669b9
3
+ metadata.gz: ab53c32125f8532906979ab579f4a60532a47b63
4
+ data.tar.gz: ef207d433646246f46a7dbeb2b4810cab9ea8f9e
5
5
  SHA512:
6
- metadata.gz: 9ded9261047e1a2f118251b7003ee0113722c3ef9086d9228d8d1a4943c75633ea509e91519f987c6ea93e664e86beadc55c53c8f86e61bf1b9af2546f6f9628
7
- data.tar.gz: b5b734f5214dbde8371c756974a335e92deba05bf18888687b8a7701eac471b16e99190c863151022fe7b7f46ebbf5634b6d8ed056824b2469cf2c84c4b5b06a
6
+ metadata.gz: 21223af6d72a1bd0e7704894745e41c7bf23c52bb5c0c2a4954ee187006e76de3ef24f1c02719d2057110267abdee2a910f10b4af07a2af9b5a61ce76714257f
7
+ data.tar.gz: 8b42752921a41e1c8f403158de7407eb7e25bb4a76e6ed0e41ba8a81bcb4b29b5ce7eab4c7e254973997102de739bbae6e2d13c4c3515dc2f46ddc58530db55e
data/README.md CHANGED
@@ -1,6 +1,33 @@
1
1
  # JsonapiForRails
2
2
  A [Rails](http://rubyonrails.org/) 5+ plugin for providing a [JSONAPI v1.0](http://jsonapi.org/format/1.0/) API from your application with very little coding.
3
3
 
4
+ ## Installation
5
+
6
+ ### Official version
7
+
8
+ ```bash
9
+ $ # Go to the root directory of your existing Rails application
10
+ $ cd path/to/railsapp
11
+ $
12
+ $ # Update the gem file
13
+ $ cat >> Gemfile
14
+ gem 'jsonapi_for_rails'
15
+ $
16
+ $ # Install
17
+ $ bundle install
18
+ ```
19
+
20
+ ### Edge version
21
+
22
+ ```bash
23
+ $ cd path/to/railsapp
24
+ $ cat >> Gemfile
25
+ group :development do
26
+ gem 'jsonapi_for_rails', git: 'https://github.com/doga/jsonapi_for_rails.git'
27
+ end
28
+ $ bundle install
29
+ ```
30
+
4
31
  ## Usage
5
32
 
6
33
  ### 1. Set up one API controller per model
@@ -8,16 +35,15 @@ A [Rails](http://rubyonrails.org/) 5+ plugin for providing a [JSONAPI v1.0](http
8
35
  Generate a controller for each model that will be accessible from your API. Controller names need to be the plural version of your model names.
9
36
 
10
37
  ```bash
11
- $ # Go to the root directory of your existing Rails application
12
38
  $ cd path/to/railsapp
13
39
  $
14
40
  $ # Generate your models
15
- $ bin/rails generate model author
16
41
  $ bin/rails generate model article
42
+ $ bin/rails generate model author
17
43
  $
18
44
  $ # Generate your API controllers
19
- $ bin/rails generate controller authors
20
45
  $ bin/rails generate controller articles
46
+ $ bin/rails generate controller authors
21
47
  ```
22
48
 
23
49
  Then enable JSONAPI in a parent class of your API controllers.
@@ -46,14 +72,14 @@ end
46
72
  ```
47
73
 
48
74
  ```ruby
49
- # app/controllers/authors_controller.rb
75
+ # app/controllers/articles_controller.rb
50
76
 
51
77
  # Change the API controller's parent class
52
- class AuthorsController < JsonapiResourcesController
78
+ class ArticlesController < JsonapiResourcesController
53
79
  # ...
54
80
  end
55
81
 
56
- # Do the same with ArticlesController
82
+ # Do the same with AuthorsController
57
83
  ```
58
84
 
59
85
  ### 2. Configure your API controller routes
@@ -67,7 +93,7 @@ Rails.application.routes.draw do
67
93
  scope '/api/v1' do # Optional scoping
68
94
 
69
95
  [ # List your API controllers here
70
- :authors, :articles
96
+ :articles, :authors
71
97
  ].each do |resources_name|
72
98
  resources resources_name do
73
99
  controller resources_name do
@@ -98,7 +124,7 @@ $ # Get an article
98
124
  $ curl 'http://localhost:3000/api/v1/articles/184578894'
99
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}}}}}
100
126
  $
101
- $ # Get only the title of an article, include the author name
127
+ $ # Get only the title and author of an article, include the author's name
102
128
  $ curl 'http://localhost:3000/api/v1/articles/184578894?filter%5Barticles%5D=title,author;include=author;filter%5Bauthors%5D=name'
103
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":{}}}]}
104
130
 
@@ -167,7 +193,6 @@ class ArticlesController < JsonapiResourcesController
167
193
 
168
194
  def index
169
195
  jsonapi_model_class # => Article
170
- jsonapi_model_class_name # => "Article"
171
196
  jsonapi_model_type # => :articles
172
197
 
173
198
  # ...
@@ -180,7 +205,19 @@ class ArticlesController < JsonapiResourcesController
180
205
  end
181
206
 
182
207
  def relationship_show
183
- @jsonapi_relationship # => {:definition=>{:name=>:author, :type=>:to_one, :receiver=>{:type=>:authors, :class=>Author}}
208
+ # @jsonapi_relationship is available in all relationship actions.
209
+ # @jsonapi_relationship[:definition] describes the current relationship.
210
+ @jsonapi_relationship # => {:definition=>{:name=>:author, :type=>:to_one, :receiver=>{:type=>:authors, :class=>Author}}}
211
+
212
+ # ...
213
+ end
214
+
215
+ def relationship_update
216
+ # @jsonapi_relationship[:params] contains the parsed request body.
217
+ # 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.
220
+ @jsonapi_relationship # => {:definition=>{...}, :params=>{"data"=>{"type"=>"authors", "id"=>"234455384"}}}
184
221
 
185
222
  # ...
186
223
  end
@@ -196,34 +233,8 @@ end
196
233
  * [Deleting resources](http://jsonapi.org/format/1.0/#crud-deleting) is currently not implemented.
197
234
  * Test coverage is sparse.
198
235
 
199
- ## Installation
200
-
201
- ### Edge version
202
-
203
- ```bash
204
- $ # Clone this repository
205
- $ git clone 'https://github.com/doga/jsonapi_for_rails.git'
206
- $
207
- $ # Update your Rails application's gem file
208
- $ cat >> path/to/Gemfile
209
-
210
- group :development do
211
- gem 'jsonapi_for_rails', path: 'path/to/jsonapi_for_rails'
212
- #gem 'jsonapi_for_rails', git: 'https://github.com/doga/jsonapi_for_rails.git'
213
- end
214
- ```
215
-
216
- ### Latest stable version
217
-
218
- ```bash
219
- $ # Update your Rails application's gem file
220
- $ cat >> path/to/Gemfile
221
-
222
- gem 'jsonapi_for_rails'
223
- ```
224
-
225
236
  ## Contributing
226
- If you find a bug in this project, have trouble following the documentation or have a question about the project – create an [issue](https://guides.github.com/activities/contributing-to-open-source/#contributing).
237
+ If you find a bug in this project, have trouble following the documentation or have a question about the project – create an [issue](https://github.com/doga/jsonapi_for_rails/issues).
227
238
 
228
239
  ## License
229
240
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -170,6 +170,7 @@ module JsonapiForRails::Controller
170
170
  end.compact
171
171
  end
172
172
 
173
+ # TODO: define a separate method for relationship actions (i.e. when params[:relationship] != nil)
173
174
  def received_relationships
174
175
  rels = relationships
175
176
  if params[:relationship] # only one relationship received for relationship action
@@ -230,7 +231,7 @@ module JsonapiForRails::Controller
230
231
  conformant = false
231
232
  break
232
233
  end
233
- conformant = false unless received_params[:data][:type] == relationship[:receiver][:type]
234
+ conformant = false unless received_params[:data][:type].to_sym == relationship[:receiver][:type]
234
235
 
235
236
  break
236
237
  end
@@ -1,3 +1,3 @@
1
1
  module JsonapiForRails
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
@@ -1,7 +1,19 @@
1
1
 
2
- # TODO: send pull request to add jsonapi_for_rails to JSON API implementations list (http://jsonapi.org/implementations/)
3
- # TODO: double-check the installation instructions in README.md
4
- # TODO: 'Contributing' section in README.md
2
+ # TODO: JSONAPI: id of resource object is a string
3
+ # TODO: JSONAPI: adding optional members to documents ('jsonapi', 'meta')
4
+ # TODO: JSONAPI: return conformant HTTP status codes
5
+ # TODO: JSONAPI: conformant and rich 'errors' member
6
+ # TODO: JSONAPI: content negotiation
7
+ # TODO: JSONAPI: apply sparse fieldsets _after_ including related resources
8
+ # TODO: JSONAPI: should included resources list their relationships (which links to primary object)?
9
+ # TODO: JSONAPI: do not support Client-Generated IDs?
10
+ # TODO: JSONAPI: Location header
11
+
12
+ # TODO: README.md: double-check the installation instructions
13
+ # TODO: README.md: better describe @jsonapi_relationship (what can it contain besides 'definition'?)
14
+ # TODO: README.md: describe @jsonapi_include?
15
+ # TODO: README.md: describe @jsonapi_sparse_fieldsets?
16
+
5
17
 
6
18
  require "jsonapi_for_rails/version"
7
19
  require "jsonapi_for_rails/controller"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jsonapi_for_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Doga Armangil
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-23 00:00:00.000000000 Z
11
+ date: 2016-02-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -44,8 +44,8 @@ dependencies:
44
44
  - - ">="
45
45
  - !ruby/object:Gem::Version
46
46
  version: '0'
47
- description: Jsonapi for Rails empowers your JSON API (http://jsonapi.org/format/)
48
- compliant Rails APIs. Implement your REST API with very little coding.
47
+ description: Jsonapi for Rails empowers your JSON API compliant APIs. Requires with
48
+ very little coding. http://jsonapi.org/format/
49
49
  email:
50
50
  - doga.armangil@alumni.epfl.ch
51
51
  executables: []
@@ -91,5 +91,5 @@ rubyforge_project:
91
91
  rubygems_version: 2.5.1
92
92
  signing_key:
93
93
  specification_version: 4
94
- summary: A Rails plugin for providing JSON API compliant APIs with very little coding.
94
+ summary: Jsonapi for Rails empowers your JSON API compliant APIs
95
95
  test_files: []