pytty 0.0.2 → 0.1.0

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
  SHA256:
3
- metadata.gz: f056f1916a3e2d18ae831ff16b1f5263cbed79df4363b7eeab8115f1fa656940
4
- data.tar.gz: 4c0898d8a1857f247bd841194ec63a18f9ce7dd95e92f7e20e97aa44df9ff11c
3
+ metadata.gz: d925871a8895ef6e93d35a265e5c44c3874d14241e08d2474b884acf4352c6b2
4
+ data.tar.gz: 9821b6759f9d57b89ed99c199b435c34f93196334be72c4fd5fe53973d348882
5
5
  SHA512:
6
- metadata.gz: 14a532b686dd65d93987fe521e458532f120477e756028613addfe0a74be48469e1e66e2121cdcfa55740862a37619e6e4db91f8b5ed78fce894ba98238fb185
7
- data.tar.gz: 768b880bda99b602e3b3717025e443226f97149216afd4ba2e4f79a0928b44ea52cc59f1559eb8ec3975900251cfefbc78d2a17d942de2f47b6b831082a7e522
6
+ metadata.gz: 6d2e382324e2882f6e394b7db0f9358600bc76057c2d611ac1c7c4d7e248429d984bcd624554cf684a6c1fa42a771127fa088b4ed57a6d88b62e31e9214145f7
7
+ data.tar.gz: be054067981dd164378fcd1ad83fbb948ebd9035fc1decb2a559b75332768e21a46426c8332bbe89e5dacad2db32b9aaf85b2e19235a30868f683b5f3789533e
data/Gemfile.lock CHANGED
@@ -1,15 +1,40 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pytty (0.0.2)
4
+ pytty (0.1.0)
5
+ async-websocket
5
6
  clamp (~> 1.3)
7
+ falcon
6
8
 
7
9
  GEM
8
10
  remote: https://rubygems.org/
9
11
  specs:
12
+ async (1.12.0)
13
+ nio4r (~> 2.3)
14
+ timers (~> 4.1)
15
+ async-container (0.8.1)
16
+ async (~> 1.0)
17
+ async-io (~> 1.4)
18
+ async-http (0.37.7)
19
+ async (~> 1.6)
20
+ async-io (~> 1.16)
21
+ http-protocol (~> 0.10)
22
+ async-io (1.17.2)
23
+ async (~> 1.3)
24
+ async-websocket (0.6.1)
25
+ async-io
26
+ websocket-driver (~> 0.7.0)
10
27
  clamp (1.3.0)
11
28
  coderay (1.1.2)
12
29
  diff-lcs (1.3)
30
+ falcon (0.19.6)
31
+ async-container (~> 0.8.0)
32
+ async-http (~> 0.37.2)
33
+ async-io (~> 1.9)
34
+ http-protocol (~> 0.10.0)
35
+ localhost (~> 1.1)
36
+ rack (>= 1.0)
37
+ samovar (~> 1.3)
13
38
  ffi (1.10.0)
14
39
  formatador (0.2.5)
15
40
  guard (2.15.0)
@@ -30,20 +55,28 @@ GEM
30
55
  guard (~> 2.1)
31
56
  guard-compat (~> 1.1)
32
57
  rspec (>= 2.99.0, < 4.0)
58
+ http-hpack (0.1.1)
59
+ http-protocol (0.10.1)
60
+ http-hpack (~> 0.1.0)
33
61
  kommando (0.1.2)
34
62
  listen (3.1.5)
35
63
  rb-fsevent (~> 0.9, >= 0.9.4)
36
64
  rb-inotify (~> 0.9, >= 0.9.7)
37
65
  ruby_dep (~> 1.2)
66
+ localhost (1.1.4)
38
67
  lumberjack (1.0.13)
68
+ mapping (1.1.1)
39
69
  method_source (0.9.2)
40
70
  nenv (0.3.0)
71
+ nio4r (2.3.1)
41
72
  notiffany (0.1.1)
42
73
  nenv (~> 0.1)
43
74
  shellany (~> 0.0)
44
75
  pry (0.12.2)
45
76
  coderay (~> 1.1.0)
46
77
  method_source (~> 0.9.0)
78
+ rack (2.0.6)
79
+ rainbow (3.0.0)
47
80
  rake (10.5.0)
48
81
  rb-fsevent (0.10.3)
49
82
  rb-inotify (0.10.0)
@@ -62,8 +95,15 @@ GEM
62
95
  rspec-support (~> 3.8.0)
63
96
  rspec-support (3.8.0)
64
97
  ruby_dep (1.5.0)
98
+ samovar (1.9.1)
99
+ mapping (~> 1.0)
100
+ rainbow (>= 2.0, < 4.0)
65
101
  shellany (0.0.1)
66
102
  thor (0.20.3)
103
+ timers (4.2.0)
104
+ websocket-driver (0.7.0)
105
+ websocket-extensions (>= 0.1.0)
106
+ websocket-extensions (0.1.3)
67
107
 
68
108
  PLATFORMS
69
109
  ruby
@@ -12,6 +12,7 @@ module Pytty
12
12
  end
13
13
 
14
14
  subcommand ["version"], "Show version information", Pytty::Common::Cli::VersionCommand
15
+ subcommand ["run"], "run", RunCommand
15
16
 
16
17
  def self.run
17
18
  super
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+ require 'async'
3
+ require 'async/http'
4
+ require 'async/http/internet'
5
+
6
+ module Pytty
7
+ module Client
8
+ module Cli
9
+ class RunCommand < Clamp::Command
10
+ def execute
11
+ Async.run do
12
+ internet = Async::HTTP::Internet.new
13
+ headers = [['accept', 'application/json']]
14
+ body = []
15
+ response = internet.post("http://localhost:1234/v1/run", headers, body)
16
+ response.read
17
+ ensure
18
+ internet.close
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+
@@ -1,4 +1,5 @@
1
1
  require "clamp"
2
2
 
3
3
  require_relative "../common/cli/version_command"
4
+ require_relative "cli/run_command"
4
5
  require_relative "cli/root_command"
@@ -0,0 +1,32 @@
1
+ require_relative "web_sockets"
2
+ require_relative "../components"
3
+
4
+ module Pytty
5
+ module Daemon
6
+ module Api
7
+ class Router
8
+ def call(env)
9
+ req = Rack::Request.new(env)
10
+ resp = case req.path_info
11
+ when "/run"
12
+ handler = Pytty::Daemon::Components::WebHandler.new(env)
13
+ handler.handle
14
+
15
+ [200, {"Content-Type" => "text/html"}, ["ok"]]
16
+ when "/ws"
17
+ if env["HTTP_UPGRADE"] == "websocket"
18
+ ws = WebSockets.new env
19
+ ws.handle
20
+ end
21
+
22
+ [200, {"Content-Type" => "text/html"}, ["ws"]]
23
+ else
24
+ [404, {"Content-Type" => "text/html"}, ["unknown: #{req.path_info}"]]
25
+ end
26
+
27
+ resp
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,35 @@
1
+ require "falcon"
2
+ require_relative "router"
3
+
4
+ module Pytty
5
+ module Daemon
6
+ module Api
7
+ class Server
8
+ def initialize
9
+ end
10
+
11
+ def run
12
+ rack_app = Rack::Builder.new do
13
+ use Rack::CommonLogger
14
+ map "/v1" do
15
+ run Router.new
16
+ end
17
+ end
18
+
19
+ app = Falcon::Server.middleware rack_app, verbose: true
20
+
21
+ endpoint = Async::HTTP::URLEndpoint.parse "http://0.0.0.0:1234"
22
+ bound_endpoint = Async::Reactor.run do
23
+ Async::IO::SharedEndpoint.bound(endpoint)
24
+ end.result
25
+
26
+ server = Falcon::Server.new(app, bound_endpoint, endpoint.protocol, endpoint.scheme)
27
+ Async::Reactor.run do
28
+ server.run
29
+ puts "serving..."
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,36 @@
1
+ require 'async/websocket/server'
2
+
3
+ module Pytty
4
+ module Daemon
5
+ module Api
6
+ class WebSockets
7
+ @@connections = []
8
+ def initialize(env)
9
+ @env = env
10
+
11
+ @connection = Async::WebSocket::Server.open(env)
12
+ @@connections << @connection
13
+ end
14
+
15
+ def handle
16
+ while message = @connection.next_event
17
+ type = case message
18
+ when WebSocket::Driver::OpenEvent
19
+ puts "ws: open #{@env["REMOTE_ADDR"]}"
20
+ when WebSocket::Driver::CloseEvent
21
+ puts "ws: close #{@env["REMOTE_ADDR"]}"
22
+ @@connections.delete @connection
23
+ when WebSocket::Driver::MessageEvent
24
+ puts "ws: message #{@env["REMOTE_ADDR"]}"
25
+ @@connections.each do |connection|
26
+ connection.send_message(message.data.reverse)
27
+ end
28
+ else
29
+ raise "ws: unknown #{message.inspect}"
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -12,6 +12,7 @@ module Pytty
12
12
  end
13
13
 
14
14
  subcommand ["version"], "Show version information", Pytty::Common::Cli::VersionCommand
15
+ subcommand ["serve"], "serve", ServeCommand
15
16
 
16
17
  def self.run
17
18
  super
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../api/server"
4
+ module Pytty
5
+ module Daemon
6
+ module Cli
7
+ class ServeCommand < Clamp::Command
8
+ def execute
9
+ s = Pytty::Daemon::Api::Server.new
10
+ s.run
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
16
+
@@ -1,4 +1,6 @@
1
1
  require "clamp"
2
2
 
3
3
  require_relative "../common/cli/version_command"
4
+ require_relative "cli/serve_command"
5
+
4
6
  require_relative "cli/root_command"
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pytty
4
+ module Daemon
5
+ module Components
6
+ class Run
7
+ def run
8
+ `say hello`
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
14
+
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+ require "rack/request"
3
+
4
+ module Pytty
5
+ module Daemon
6
+ module Components
7
+ class WebHandler
8
+ def initialize(env)
9
+ @env = env
10
+ end
11
+
12
+ def handle
13
+ req = Rack::Request.new(@env)
14
+ case req.path_info
15
+ when "/run"
16
+ Run.new.run
17
+ else
18
+ raise "Unknown: #{req.path_info}"
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+
@@ -0,0 +1,3 @@
1
+
2
+ require_relative "components/run"
3
+ require_relative "components/web_handler"
data/lib/pytty/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Pytty
2
- VERSION = "0.0.2"
2
+ VERSION = "0.1.0"
3
3
  end
data/pytty.gemspec CHANGED
@@ -23,6 +23,8 @@ Gem::Specification.new do |spec|
23
23
  spec.require_paths = ["lib"]
24
24
 
25
25
  spec.add_runtime_dependency "clamp", "~> 1.3"
26
+ spec.add_runtime_dependency "falcon"
27
+ spec.add_runtime_dependency "async-websocket"
26
28
 
27
29
  spec.add_development_dependency "bundler", "~> 1.16"
28
30
  spec.add_development_dependency "rake", "~> 10.0"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pytty
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matti Paksula
@@ -24,6 +24,34 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: falcon
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
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: async-websocket
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
27
55
  - !ruby/object:Gem::Dependency
28
56
  name: bundler
29
57
  requirement: !ruby/object:Gem::Requirement
@@ -149,9 +177,17 @@ files:
149
177
  - lib/pytty.rb
150
178
  - lib/pytty/client/cli.rb
151
179
  - lib/pytty/client/cli/root_command.rb
180
+ - lib/pytty/client/cli/run_command.rb
152
181
  - lib/pytty/common/cli/version_command.rb
182
+ - lib/pytty/daemon/api/router.rb
183
+ - lib/pytty/daemon/api/server.rb
184
+ - lib/pytty/daemon/api/web_sockets.rb
153
185
  - lib/pytty/daemon/cli.rb
154
186
  - lib/pytty/daemon/cli/root_command.rb
187
+ - lib/pytty/daemon/cli/serve_command.rb
188
+ - lib/pytty/daemon/components.rb
189
+ - lib/pytty/daemon/components/run.rb
190
+ - lib/pytty/daemon/components/web_handler.rb
155
191
  - lib/pytty/version.rb
156
192
  - pytty.gemspec
157
193
  homepage: https://github.com/pyttyhq/pytty-ruby