Class: UppityRobot::CLI::Commands::Monitors::Delete

Inherits:
Dry::CLI::Command
  • Object
show all
Defined in:
lib/uppityrobot/cli/commands/monitors/delete.rb

Overview

UppityRobot::CLI::Commands::Monitors::Delete delete a monitor

Instance Method Summary collapse

Instance Method Details

#call(field:, value:) ⇒ Object



19
20
21
22
23
24
# File 'lib/uppityrobot/cli/commands/monitors/delete.rb', line 19

def call(field:, value:, **)
  check_field(field)
  monitor = find_monitor(field, value)
  response = UppityRobot::Client.new(:deleteMonitor, {id: monitor["id"]}).execute
  puts response.to_json
end

#check_field(field) ⇒ Object



26
27
28
29
30
31
# File 'lib/uppityrobot/cli/commands/monitors/delete.rb', line 26

def check_field(field)
  return if %w[id name].include? field

  abort({stat: "fail",
         error: "Field not recognized, must be one of: [id, name]"}.to_json)
end

#find_monitor(field, value) ⇒ Object



33
34
35
36
37
38
39
40
41
42
# File 'lib/uppityrobot/cli/commands/monitors/delete.rb', line 33

def find_monitor(field, value)
  params = {}
  case field
  when "id"
    params[:monitors] = value
  when "name"
    params[:search] = value
  end
  UppityRobot::Client.new(:getMonitors, params).fetch
end