jsonapi_for_rails 0.1.3 → 0.1.4
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
- data/README.md +3 -3
- data/lib/jsonapi_for_rails.rb +1 -3
- data/lib/jsonapi_for_rails/controller.rb +2 -0
- data/lib/jsonapi_for_rails/controller/actions/object.rb +0 -1
- data/lib/jsonapi_for_rails/controller/before_actions/content_negotiation.rb +31 -0
- data/lib/jsonapi_for_rails/version.rb +3 -2
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3e3b34eaf013306f4520bd8beb8ec87594b0dd32
|
4
|
+
data.tar.gz: 5d4a449ef838869e77ac51dc9ee070728595d644
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a423f57386943e320ac84399d33d6bc7e685d6bb5ca25f81644b9e91e2a82732e94dfbaef602f0f584ef0e48c17d30db656d6036e8caba3bde9e10cccf218c8c
|
7
|
+
data.tar.gz: ab6ad71dcc6713779f5a6f40be815d18c2847a241af3011524b743f2a226881d044720891ce9c2fbf2d17a99ae8ad6f8465b82a318503329af7048e4a54313c5
|
data/README.md
CHANGED
@@ -118,14 +118,14 @@ 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":"
|
121
|
+
{"data":[{"type":"articles","id":"618037523"},{"type":"articles","id":"184578894"},{"type":"articles","id":"388548390"},{"type":"articles","id":"994552601"}]}
|
122
122
|
$
|
123
123
|
$ # Get an article
|
124
|
-
$ curl 'http://localhost:3000/api/v1/articles/
|
124
|
+
$ curl 'http://localhost:3000/api/v1/articles/618037523'
|
125
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
|
-
$ curl 'http://localhost:3000/api/v1/articles/
|
128
|
+
$ curl 'http://localhost:3000/api/v1/articles/618037523?filter%5Barticles%5D=title,author;include=author;filter%5Bauthors%5D=name'
|
129
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":{}}}]}
|
130
130
|
```
|
131
131
|
|
data/lib/jsonapi_for_rails.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
|
2
|
-
# TODO: JSONAPI: id of resource object is a string
|
1
|
+
# BUG: convert ids to strings in received data
|
3
2
|
# TODO: JSONAPI: adding optional members to documents ('jsonapi', 'meta')
|
4
3
|
# TODO: JSONAPI: return conformant HTTP status codes
|
5
4
|
# TODO: JSONAPI: conformant and rich 'errors' member
|
@@ -10,7 +9,6 @@
|
|
10
9
|
# TODO: JSONAPI: Location header
|
11
10
|
|
12
11
|
# TODO: README.md: double-check the installation instructions
|
13
|
-
# TODO: README.md: better describe @jsonapi_relationship (what can it contain besides 'definition'?)
|
14
12
|
# TODO: README.md: describe @jsonapi_include?
|
15
13
|
# TODO: README.md: describe @jsonapi_sparse_fieldsets?
|
16
14
|
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require "jsonapi_for_rails/controller/utils/model"
|
2
2
|
require "jsonapi_for_rails/controller/utils/render"
|
3
|
+
require "jsonapi_for_rails/controller/before_actions/content_negotiation"
|
3
4
|
require "jsonapi_for_rails/controller/before_actions/sparse_fieldsets"
|
4
5
|
require "jsonapi_for_rails/controller/before_actions/include"
|
5
6
|
require "jsonapi_for_rails/controller/before_actions/record"
|
@@ -21,6 +22,7 @@ module JsonapiForRails::Controller
|
|
21
22
|
|
22
23
|
include JsonapiForRails::Controller::Utils::Model
|
23
24
|
include JsonapiForRails::Controller::Utils::Render
|
25
|
+
include JsonapiForRails::Controller::BeforeActions::ContentNegotiation
|
24
26
|
include JsonapiForRails::Controller::BeforeActions::SparseFieldsets
|
25
27
|
include JsonapiForRails::Controller::BeforeActions::Include
|
26
28
|
include JsonapiForRails::Controller::BeforeActions::Record
|
@@ -11,7 +11,6 @@ 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]
|
15
14
|
jsonapi_model_class.all.each do |record|
|
16
15
|
@json[:data] << {
|
17
16
|
type: record.class.to_s.underscore.pluralize, # TODO: factor out type generation from class
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module JsonapiForRails::Controller
|
2
|
+
|
3
|
+
module BeforeActions
|
4
|
+
module ContentNegotiation
|
5
|
+
|
6
|
+
def self.included receiver
|
7
|
+
#$stderr.puts "JsonapiForRails::Controller::RecordFromRequest included into #{receiver}"
|
8
|
+
receiver.send :include, InstanceMethods
|
9
|
+
run_macros receiver
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.run_macros receiver
|
13
|
+
receiver.instance_exec do
|
14
|
+
before_action :content_negotiation
|
15
|
+
private :content_negotiation
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
module InstanceMethods
|
20
|
+
def content_negotiation
|
21
|
+
#$stderr.puts "#{request.headers}"
|
22
|
+
# TODO: content negotiation
|
23
|
+
return
|
24
|
+
render_error 401, "Bad request."
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
module JsonapiForRails
|
2
|
-
VERSION = '0.1.
|
2
|
+
VERSION = '0.1.4'
|
3
|
+
# 0.1.4: gem now requires rails >= 4 instead of 5.0.0.beta2
|
3
4
|
# 0.1.3: fix non-string id bug (http://jsonapi.org/format/1.0/#document-resource-object-identification)
|
4
|
-
# 0.1.2: add ruby
|
5
|
+
# 0.1.2: add ruby 2.0 dependency to gem
|
5
6
|
# 0.1.1: fix @jsonapi_relationship[:params] bug, it is now set correctly
|
6
7
|
end
|
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.
|
4
|
+
version: 0.1.4
|
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-
|
11
|
+
date: 2016-02-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -16,7 +16,7 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 4.0.0
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
22
|
version: '5.1'
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
29
|
+
version: 4.0.0
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: '5.1'
|
@@ -59,6 +59,7 @@ files:
|
|
59
59
|
- lib/jsonapi_for_rails/controller.rb
|
60
60
|
- lib/jsonapi_for_rails/controller/actions/object.rb
|
61
61
|
- lib/jsonapi_for_rails/controller/actions/relationship.rb
|
62
|
+
- lib/jsonapi_for_rails/controller/before_actions/content_negotiation.rb
|
62
63
|
- lib/jsonapi_for_rails/controller/before_actions/include.rb
|
63
64
|
- lib/jsonapi_for_rails/controller/before_actions/record.rb
|
64
65
|
- lib/jsonapi_for_rails/controller/before_actions/relationship.rb
|