terminalwire 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/lib/terminalwire.rb CHANGED
@@ -3,17 +3,10 @@
3
3
  require_relative "terminalwire/version"
4
4
 
5
5
  require 'socket'
6
- require 'msgpack'
7
- require 'launchy'
8
- require 'logger'
9
- require 'io/console'
10
6
  require 'forwardable'
11
7
  require 'uri'
12
8
  require 'zeitwerk'
13
9
 
14
- require 'thor'
15
- require 'fileutils'
16
-
17
10
  require 'async'
18
11
  require 'async/http/endpoint'
19
12
  require 'async/websocket/client'
@@ -27,123 +20,35 @@ module Terminalwire
27
20
  loader.setup
28
21
  end
29
22
 
30
- module Logging
31
- DEVICE = Logger.new($stdout, level: ENV.fetch("LOG_LEVEL", "info"))
32
- def logger = DEVICE
33
- end
34
-
35
- class Connection
36
- include Logging
37
-
38
- attr_reader :transport
39
-
40
- def initialize(transport)
41
- @transport = transport
42
- end
43
-
44
- def write(data)
45
- logger.debug "Connection: Sending #{data.inspect}"
46
- packed_data = MessagePack.pack(data, symbolize_keys: true)
47
- @transport.write(packed_data)
48
- end
49
-
50
- def recv
51
- logger.debug "Connection: Reading"
52
- packed_data = @transport.read
53
- return nil if packed_data.nil?
54
- data = MessagePack.unpack(packed_data, symbolize_keys: true)
55
- logger.debug "Connection: Recieved #{data.inspect}"
56
- data
57
- end
58
-
59
- def close
60
- @transport.close
61
- end
62
- end
63
-
64
- class ResourceRegistry
65
- def initialize
66
- @resources = Hash.new
67
- end
68
-
69
- def register(name, to: nil)
70
- @resources[name.to_s] = to
71
- end
72
-
73
- def <<(resource_class)
74
- register resource_class.protocol_key, to: resource_class
75
- end
76
-
77
- def find(name)
78
- @resources.fetch(name.to_s)
79
- end
80
- end
81
-
82
23
  module Resource
83
24
  class Base
84
- attr_reader :id, :connection
25
+ attr_reader :name, :adapter
85
26
 
86
- def initialize(id, connection)
87
- @id = Integer(id)
88
- @connection = connection
27
+ def initialize(name, adapter)
28
+ @name = name.to_s
29
+ @adapter = adapter
89
30
  end
90
31
 
91
32
  def connect; end
92
- def dispatch(action, data); end
93
33
  def disconnect; end
94
34
 
95
- def respond(response, status: :success)
96
- connection.write(event: "device", id: @id, status:, response:)
35
+ def fail(response, **data)
36
+ respond(status: "failure", response:, **data)
97
37
  end
98
38
 
99
- def self.protocol_key
100
- name.split("::").last.downcase
39
+ def succeed(response, **data)
40
+ respond(status: "success", response:, **data)
101
41
  end
102
- end
103
- end
104
-
105
- module WebSocket
106
- class Server
107
- include Logging
108
42
 
109
- def call(env)
110
- Async::WebSocket::Adapters::Rack.open(env, protocols: ['ws']) do |connection|
111
- run(Connection.new(Terminalwire::Transport::WebSocket.new(connection)))
112
- end or [200, { "Content-Type" => "text/plain" }, ["Connect via WebSockets"]]
43
+ def self.protocol_key
44
+ name.split("::").last.downcase
113
45
  end
114
46
 
115
47
  private
116
48
 
117
- def run(connection)
118
- while message = connection.recv
119
- puts message
120
- end
121
- end
122
- end
123
-
124
- class ThorServer < Server
125
- include Logging
126
-
127
- def initialize(cli_class)
128
- @cli_class = cli_class
129
-
130
- # Check if the Terminalwire::Thor module is already included
131
- unless @cli_class.included_modules.include?(Terminalwire::Thor)
132
- raise 'Add `include Terminalwire::Thor` to the #{@cli_class.inspect} class.'
133
- end
134
- end
135
-
136
- def run(connection)
137
- logger.info "ThorServer: Running #{@cli_class.inspect}"
138
- while message = connection.recv
139
- case message
140
- in { event: "initialize", protocol: { version: _ }, arguments:, program_name: }
141
- Terminalwire::Server::Session.new(connection: connection) do |session|
142
- @cli_class.start(arguments, session: session)
143
- end
144
- end
145
- end
49
+ def respond(**response)
50
+ adapter.write(event: "resource", name: @name, **response)
146
51
  end
147
52
  end
148
53
  end
149
- end
54
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: terminalwire
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brad Gessler
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-09-07 00:00:00.000000000 Z
11
+ date: 2024-09-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: async-websocket
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: jwt
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '2.0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '2.0'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: rake
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -143,8 +157,13 @@ files:
143
157
  - lib/generators/terminalwire/install/templates/application_terminal.rb.tt
144
158
  - lib/generators/terminalwire/install/templates/bin/terminalwire
145
159
  - lib/terminalwire.rb
160
+ - lib/terminalwire/adapter.rb
146
161
  - lib/terminalwire/client.rb
147
- - lib/terminalwire/client/binary.rb
162
+ - lib/terminalwire/client/entitlement.rb
163
+ - lib/terminalwire/client/exec.rb
164
+ - lib/terminalwire/client/resource.rb
165
+ - lib/terminalwire/logging.rb
166
+ - lib/terminalwire/rails.rb
148
167
  - lib/terminalwire/server.rb
149
168
  - lib/terminalwire/thor.rb
150
169
  - lib/terminalwire/transport.rb
@@ -173,7 +192,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
173
192
  - !ruby/object:Gem::Version
174
193
  version: '0'
175
194
  requirements: []
176
- rubygems_version: 3.5.6
195
+ rubygems_version: 3.5.9
177
196
  signing_key:
178
197
  specification_version: 4
179
198
  summary: Ship a CLI for your web app. No API required.