Class: Magellan::Cli::Messaging::Mqtt

Inherits:
Base
  • Object
show all
Defined in:
lib/magellan/cli/messaging/mqtt.rb

Constant Summary

Constants included from FileAccess

FileAccess::DEFAULT_SELECTION_FILENAME

Instance Method Summary collapse

Methods included from FileAccess

ensure_config_dir, load_selection, load_selections, remove_selection_file, selection_filename, update_selections

Methods inherited from Base

command_help, help, log_error, log_info, log_success, log_verbose, log_warning, puts_with_color, sorted_commands, sorted_printable_commands, update_common_help_message

Instance Method Details

#get(topic = nil) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/magellan/cli/messaging/mqtt.rb', line 19

def get(topic = nil)
  topic, payload = *core.get_message(topic)
  $stderr.puts topic
  $stdout.puts payload.ascii_only? ? payload : payload.inspect
rescue Magellan::Cli::Error
  raise
rescue => e
  show_error_and_exit1(e)
end

#pub(topic, payload) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/magellan/cli/messaging/mqtt.rb', line 9

def pub(topic, payload)
  core.publish(topic, try_reading_file(payload).dup)
  log_success "\e[32mOK\e[0m"
rescue Magellan::Cli::Error
  raise
rescue => e
  show_error_and_exit1(e)
end