satz 0.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ef06f388d1b3113f7d709320b4ea4606e5fc9c8c
4
+ data.tar.gz: af63d424f6e74e95418804514075f72886777af5
5
+ SHA512:
6
+ metadata.gz: 8ef33ff001e893d12588c6fbf6f5825434c7cf8599f14db51ddf12b807e95ccb0e6731f9ff4241a80e6b587e6bec31ec827c3f4ddd919fb853eef807317deccc
7
+ data.tar.gz: 4a1df71be2425e688e51ed96dafb3d0a8d1d3be929f8f5c2917e8a7788382942d4c1018b5b1e7846f3d933179c98f6eec6df42a58a24a744598b555c8675dd90
data/.gems ADDED
@@ -0,0 +1,2 @@
1
+ syro -v 2.0.0
2
+ rack-test -v 0.6.3
data/CHANGELOG ADDED
@@ -0,0 +1 @@
1
+
data/CONTRIBUTING ADDED
@@ -0,0 +1,19 @@
1
+ This code tries to solve a particular problem with a very simple
2
+ implementation. We try to keep the code to a minimum while making
3
+ it as clear as possible. The design is very likely finished, and
4
+ if some feature is missing it is possible that it was left out on
5
+ purpose. That said, new usage patterns may arise, and when that
6
+ happens we are ready to adapt if necessary.
7
+
8
+ A good first step for contributing is to meet us on IRC and discuss
9
+ ideas. We spend a lot of time on #lesscode at freenode, always ready
10
+ to talk about code and simplicity. If connecting to IRC is not an
11
+ option, you can create an issue explaining the proposed change and
12
+ a use case. We pay a lot of attention to use cases, because our
13
+ goal is to keep the code base simple. Usually the result of a
14
+ conversation is the creation of a different tool.
15
+
16
+ Please don't start the conversation with a pull request. The code
17
+ should come at last, and even though it may help to convey an idea,
18
+ more often than not it draws the attention to a particular
19
+ implementation.
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2015 Michel Martens
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,69 @@
1
+ Satz
2
+ ====
3
+
4
+ Framework for JSON microservices
5
+
6
+ Description
7
+ -----------
8
+
9
+ Satz is a framework for writing microservices that serve and read
10
+ JSON. It uses [Syro][syro] for routing requests. Check the [Syro
11
+ tutorial][tutorial] to learn more about how the routing works.
12
+
13
+ [syro]: http://soveran.github.io/syro/
14
+ [tutorial]: http://files.soveran.com/syro/
15
+
16
+ Usage
17
+ -----
18
+
19
+ An example of a Satz application would look like this:
20
+
21
+ ```ruby
22
+ App = Satz.new do
23
+ on "players" do
24
+ on :player_id do
25
+ get do
26
+ @player = Player[inbox[:player_id]]
27
+
28
+ reply @player
29
+ end
30
+ end
31
+
32
+ get do
33
+ reply Player.all.to_a
34
+ end
35
+
36
+ post do
37
+ @player = Player.new(read)
38
+
39
+ on @player.valid? do
40
+ @player.create
41
+
42
+ reply @player
43
+ end
44
+
45
+ default do
46
+ reply @player.errors
47
+ end
48
+ end
49
+ end
50
+ end
51
+ ```
52
+
53
+ The argument to `reply` is served as JSON by calling `JSON.dump(arg)`.
54
+ In user defined objects, you can define the method `to_json` according
55
+ to your needs. Most ORMs already provide meaningful definitions for
56
+ that method.
57
+
58
+ API
59
+ ---
60
+
61
+ Apart from [Syro][syro]'s API, the following methods are available:
62
+
63
+ `read`: Reads the body of the requst and parses it as JSON.
64
+
65
+ `reply`: Writes to the response its argument encoded as JSON.
66
+
67
+ ```
68
+ $ gem install satz
69
+ ```
data/lib/satz.rb ADDED
@@ -0,0 +1,49 @@
1
+ # encoding: UTF-8
2
+ #
3
+ # Copyright (c) 2015 Michel Martens
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in
13
+ # all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ # THE SOFTWARE.
22
+
23
+ require "syro"
24
+ require "json"
25
+
26
+ class Satz
27
+ class Deck < Syro::Deck
28
+
29
+ # Respond by default with JSON.
30
+ def default_headers
31
+ { "Content-Type" => "application/json" }
32
+ end
33
+
34
+ # Read JSON data from the POST request.
35
+ def read
36
+ body = req.body.read
37
+ body && JSON.parse(body)
38
+ end
39
+
40
+ # Write JSON data to the response.
41
+ def reply(data)
42
+ res.write(JSON.dump(data))
43
+ end
44
+ end
45
+
46
+ def self.define(&code)
47
+ Syro.new(Deck, &code)
48
+ end
49
+ end
data/makefile ADDED
@@ -0,0 +1,4 @@
1
+ .PHONY: test
2
+
3
+ test:
4
+ cutest -r ./test/helper.rb ./test/*.rb
data/satz.gemspec ADDED
@@ -0,0 +1,16 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "satz"
3
+ s.version = "0.0.1"
4
+ s.summary = "Framework for JSON microservices"
5
+ s.description = "Framework for JSON microservices"
6
+ s.authors = ["Michel Martens"]
7
+ s.email = ["michel@soveran.com"]
8
+ s.homepage = "https://github.com/soveran/satz"
9
+ s.license = "MIT"
10
+
11
+ s.files = `git ls-files`.split("\n")
12
+
13
+ s.add_dependency "syro", "~> 2.0"
14
+ s.add_development_dependency "cutest"
15
+ s.add_development_dependency "rack-test"
16
+ end
data/test/all.rb ADDED
@@ -0,0 +1,29 @@
1
+ App = Satz.define do
2
+ get do
3
+ reply(true)
4
+ end
5
+
6
+ post do
7
+ reply(read)
8
+ end
9
+ end
10
+
11
+ setup do
12
+ Driver.new(App)
13
+ end
14
+
15
+ test "get" do |app|
16
+ app.get("/")
17
+
18
+ assert_equal 200, app.last_response.status
19
+ assert_equal %Q(true), app.last_response.body
20
+ end
21
+
22
+ test "post" do |app|
23
+ data = { "foo" => "bar" }.to_json
24
+
25
+ app.post("/", data)
26
+
27
+ assert_equal data, app.last_response.body
28
+ assert_equal 200, app.last_response.status
29
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,15 @@
1
+ require_relative "../lib/satz"
2
+ require "rack/test"
3
+
4
+ class Driver
5
+ include Rack::Test::Methods
6
+
7
+ def initialize(app)
8
+ @app = app
9
+ end
10
+
11
+ def app
12
+ @app
13
+ end
14
+ end
15
+
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: satz
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Michel Martens
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-12-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: syro
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: cutest
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rack-test
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Framework for JSON microservices
56
+ email:
57
+ - michel@soveran.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gems"
63
+ - CHANGELOG
64
+ - CONTRIBUTING
65
+ - LICENSE
66
+ - README.md
67
+ - lib/satz.rb
68
+ - makefile
69
+ - satz.gemspec
70
+ - test/all.rb
71
+ - test/helper.rb
72
+ homepage: https://github.com/soveran/satz
73
+ licenses:
74
+ - MIT
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 2.4.5.1
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: Framework for JSON microservices
96
+ test_files: []