Class: UppityRobot::CLI::Commands::Exec
- Inherits:
-
Dry::CLI::Command
- Object
- Dry::CLI::Command
- UppityRobot::CLI::Commands::Exec
- Defined in:
- lib/uppityrobot/cli/commands/exec.rb
Overview
UppityRobot::CLI::Commands::Exec executes an API task
Instance Method Summary collapse
Instance Method Details
#call(task:, data: nil, params: "{}") ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/uppityrobot/cli/commands/exec.rb', line 20 def call(task:, data: nil, params: "{}", **) task = task.to_sym params = data.nil? ? JSON.parse(params) : parse_file(data) puts UppityRobot::Client.new(task, params).execute.to_json rescue JSON::ParserError => e puts JSON.generate({stat: "fail", error: "JSON parser #{e.}"}) end |
#parse_file(file) ⇒ Object
28 29 30 |
# File 'lib/uppityrobot/cli/commands/exec.rb', line 28 def parse_file(file) JSON.parse(File.read(File.(file))) end |