jsonapi-hanami 0.1.1.beta1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 94e7c1facd5e28912e6075ba466857778aa4bea7
4
+ data.tar.gz: 9a59bdd9aa7c79c08fb6f0cf7b3da9b4092a268f
5
+ SHA512:
6
+ metadata.gz: 4af00dfe4cc9636eb6960a93cf5f8752310fa125c2f2d22ea06a76051e20fd81af970a3eae760c5962926fbc521b9737f37add926686798de865055cfa8ef423
7
+ data.tar.gz: c78e95aaff61c47b5a28890e2d694910e1a081e66c4f6093b91e64b16d80e7cd019940e822197f632ba699403af0e9478d804c0d9b9ea11ca9534c69ce6b8fce
data/README.md ADDED
@@ -0,0 +1,53 @@
1
+ # jsonapi-hanami
2
+ Hanami integration for [jsonapi-rb](https://github.com/jsonapi-rb/jsonapi-rb).
3
+
4
+ ## Status
5
+
6
+ [![Gem Version](https://badge.fury.io/rb/jsonapi-hanami.svg)](https://badge.fury.io/rb/jsonapi-hanami)
7
+ [![Build Status](https://secure.travis-ci.org/jsonapi-rb/hanami.svg?branch=master)](http://travis-ci.org/jsonapi-rb/hanami?branch=master)
8
+
9
+ ## Installation
10
+
11
+ Add the following to your application's Gemfile:
12
+ ```ruby
13
+ gem 'jsonapi-hanami'
14
+ ```
15
+ And then execute:
16
+ ```
17
+ $ bundle
18
+ ```
19
+ Or install it manually as:
20
+ ```
21
+ $ gem install jsonapi-hanami
22
+ ```
23
+
24
+ ## Usage
25
+
26
+ ```ruby
27
+ module API::Controllers::Posts
28
+ class Create
29
+ include API::Action
30
+ include JSONAPI::Hanami::Action
31
+
32
+ deserializable_resource :user, DeserializableCreatePost
33
+ # or
34
+ deserializable_resource :user do
35
+ # ...
36
+ end
37
+
38
+ params do
39
+ # ...
40
+ end
41
+
42
+ def call(params)
43
+ User.new(params[:user])
44
+ # ...
45
+ self.body = jsonapi_render(resources)
46
+ end
47
+ end
48
+ end
49
+ ```
50
+
51
+ ## License
52
+
53
+ jsonapi-hanami is released under the [MIT License](http://www.opensource.org/licenses/MIT).
File without changes
@@ -0,0 +1,15 @@
1
+ require 'jsonapi/hanami/renderer'
2
+ require 'jsonapi/hanami/deserializable'
3
+
4
+ module JSONAPI
5
+ module Hanami
6
+ module Action
7
+ def self.included(base)
8
+ base.class_eval do
9
+ include Renderer
10
+ include Deserializable
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,59 @@
1
+ require 'jsonapi/deserializable'
2
+ require 'jsonapi/parser'
3
+
4
+ module JSONAPI
5
+ module Hanami
6
+ module Deserializable
7
+ def self.included(base)
8
+ base.extend ClassMethods
9
+ end
10
+
11
+ module ClassMethods
12
+ def deserializable_resource(key, klass = nil, &block)
13
+ if klass.nil?
14
+ klass = Class.new(JSONAPI::Deserializable::Resource, &block)
15
+ end
16
+ use DeserializableResource, key, klass
17
+ end
18
+
19
+ def deserializable_relationship(key, klass = nil, &block)
20
+ if klass.nil?
21
+ klass = Class.new(JSONAPI::Deserializable::Relationship, &block)
22
+ end
23
+ use DeserializableRelationship, key, klass
24
+ end
25
+ end
26
+
27
+ class DeserializableMiddleware
28
+ ROUTER_PARAMS = 'router.params'.freeze
29
+
30
+ def initialize(app, key, klass)
31
+ @app = app
32
+ @deserializable_key = key
33
+ @deserializable_class = klass
34
+ end
35
+
36
+ def call(env)
37
+ env[ROUTER_PARAMS].tap do |body|
38
+ parser.parse!(body)
39
+ deserialized_hash = @deserializable_class.call(body)
40
+ body.replace(@deserializable_key => deserialized_hash)
41
+ end
42
+ @app.call(env)
43
+ end
44
+ end
45
+
46
+ class DeserializableResource < DeserializableMiddleware
47
+ def parser
48
+ JSONAPI::Parser::Resource
49
+ end
50
+ end
51
+
52
+ class DeserializableRelationship < DeserializableMiddleware
53
+ def parser
54
+ JSONAPI::Parser::Relationship
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,13 @@
1
+ require 'jsonapi/renderer'
2
+
3
+ module JSONAPI
4
+ module Hanami
5
+ module Renderer
6
+ def jsonapi_render(resources, params = {})
7
+ # TODO(beauby): Serializable inference with helpers injection.
8
+ # TODO(beauby): Inject global params (toplevel jsonapi, etc.).
9
+ JSONAPI::Renderer.new(resources, params).as_json
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1 @@
1
+ require 'jsonapi/hanami/action'
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jsonapi-hanami
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1.beta1
5
+ platform: ruby
6
+ authors:
7
+ - Lucas Hosseini
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-10-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: jsonapi-renderer
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.1.1.beta2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.1.1.beta2
27
+ - !ruby/object:Gem::Dependency
28
+ name: jsonapi-parser
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 0.1.1.beta3
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 0.1.1.beta3
41
+ - !ruby/object:Gem::Dependency
42
+ name: jsonapi-serializable
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 0.1.1.beta2
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 0.1.1.beta2
55
+ - !ruby/object:Gem::Dependency
56
+ name: jsonapi-deserializable
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 0.1.1.beta3
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: 0.1.1.beta3
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0.9'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0.9'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.4'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.4'
97
+ description: Efficiently build and consume JSON API documents.
98
+ email: lucas.hosseini@gmail.com
99
+ executables: []
100
+ extensions: []
101
+ extra_rdoc_files: []
102
+ files:
103
+ - README.md
104
+ - lib/generators/hanami/serializable.rb
105
+ - lib/jsonapi/hanami.rb
106
+ - lib/jsonapi/hanami/action.rb
107
+ - lib/jsonapi/hanami/deserializable.rb
108
+ - lib/jsonapi/hanami/renderer.rb
109
+ homepage: https://github.com/jsonapi-rb/hanami
110
+ licenses:
111
+ - MIT
112
+ metadata: {}
113
+ post_install_message:
114
+ rdoc_options: []
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">"
125
+ - !ruby/object:Gem::Version
126
+ version: 1.3.1
127
+ requirements: []
128
+ rubyforge_project:
129
+ rubygems_version: 2.5.1
130
+ signing_key:
131
+ specification_version: 4
132
+ summary: Hanami plugin for (de)serialization of JSON API resources.
133
+ test_files: []