Class: Pytty::Client::Api::Yield

Inherits:
Object
  • Object
show all
Defined in:
lib/pytty/client/api/yield.rb

Class Method Summary collapse

Class Method Details

.run(cmd:, id:, env:) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/pytty/client/api/yield.rb', line 5

def self.run(cmd:, id:, env:)
  internet = Async::HTTP::Internet.new
  headers = [['accept', 'application/json']]

  term_env = {
    "LINES" => IO.console.winsize.first.to_s,
    "COLUMNS" => IO.console.winsize.last.to_s
  }.merge env

  body = {
    id: id,
    cmd: cmd,
    env: term_env
  }.to_json

  response = internet.post("#{Pytty::Client.host_url}/v1/yield", headers, [body])
  [response, JSON.parse(response.body.read)]
end