-
Notifications
You must be signed in to change notification settings - Fork 0
Ruby
PiotrFerenc edited this page May 14, 2024
·
1 revision
require 'net/http'
require 'json'
class Parameters
attr_accessor :console_text
def initialize(console_text)
@console_text = console_text
end
end
class TaskItem
attr_accessor :sequence, :name, :action
def initialize(sequence, name, action)
@sequence = sequence
@name = name
@action = action
end
end
class RequestPayload
attr_accessor :parameters, :tasks
def initialize(parameters, tasks)
@parameters = parameters
@tasks = tasks
end
end
def main
url = URI('http://localhost:5000/execute')
http = Net::HTTP.new(url.host, url.port)
request = Net::HTTP::Post.new(url.path, {'Content-Type' => 'application/json'})
parameters = Parameters.new('hallo word')
tasks = [TaskItem.new(1, 'log', 'console')]
payload = RequestPayload.new(parameters, tasks)
json_content = JSON.generate({
parameters: {
console_text: payload.parameters.console_text
},
tasks: payload.tasks.map { |task| { sequence: task.sequence, name: task.name, action: task.action } }
})
request.body = json_content
response = http.request(request)
if response.is_a?(Net::HTTPSuccess)
puts "Response: #{response.body}"
else
puts "Error: #{response.code}"
end
end
main