Class: UppityRobot::CLI::Commands::Monitors::Create
- Inherits:
-
Dry::CLI::Command
- Object
- Dry::CLI::Command
- UppityRobot::CLI::Commands::Monitors::Create
- Defined in:
- lib/uppityrobot/cli/commands/monitors/create.rb
Overview
UppityRobot::CLI::Commands::Monitors::Create creates an HTTP monitor
Instance Method Summary collapse
Instance Method Details
#call(name:, url:, contacts:) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/uppityrobot/cli/commands/monitors/create.rb', line 19 def call(name:, url:, contacts:, **) sub_type = check_subtype(URI.parse(url)) data = { friendly_name: name, url: url, type: UptimeRobot::Monitor::Type::HTTP, sub_type: sub_type, alert_contacts: contacts } response = UppityRobot::Client.new(:newMonitor, data).execute puts response.to_json rescue URI::InvalidURIError => e puts JSON.generate({stat: "fail", error: "URI parser #{e.}"}) end |
#check_subtype(uri) ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/uppityrobot/cli/commands/monitors/create.rb', line 36 def check_subtype(uri) if uri.instance_of?(URI::HTTP) UptimeRobot::Monitor::SubType::HTTP elsif uri.instance_of?(URI::HTTPS) UptimeRobot::Monitor::SubType::HTTPS else abort({stat: "fail", error: "Monitor URL must be HTTP/S"}.to_json) end end |