Class: Sendxmpp::CLI
Overview
Class CLI
Input via STDIN or -m option:
Examples
sendxmpprb -m "server down notification" user [email protected]
echo "server down"|sendxmpprb user [email protected]
...
Instance Method Summary collapse
-
#chat(*jids) ⇒ Object
Public: Send a message to a single/multiple multi user chatrooms.
-
#initialize(*args) ⇒ CLI
constructor
Public: Initialize a new Object from CLI.
-
#user(*jids) ⇒ Object
Public: Send a message to multiple users.
Methods included from Config
Constructor Details
#initialize(*args) ⇒ CLI
Public: Initialize a new Object from CLI
args - Arguments, passed to Thor
Raises IniFile::Error on invalid configuration Raises ArgumentError if the main hash key was not found
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/sendxmpp/cli.rb', line 37 def initialize(*args) super local_conf = .dup local_conf.delete_if{|k,v|v.nil?||(v.kind_of?(String) && v.empty?)} update_config(local_conf) if File.exists?([:config]) conf = IniFile.load([:config])["sendxmpp"] if conf.nil? || conf.empty? raise ArgumentError, "No [sendxmpp] section in ini file found!" end conf.merge!(local_conf) update_config(conf) end Log.logger.debug("finished loading configuration.") $stdout.sync = true end |
Instance Method Details
#chat(*jids) ⇒ Object
Public: Send a message to a single/multiple multi user chatrooms.
Messages will be sent to each chat seperately
jids - Array of MUC(Multi user chat) jids.
Examples
chat(["[email protected]"])
chat(["[email protected]", "[email protected]"])
Returns 0 or 1 exit codes
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/sendxmpp/cli.rb', line 99 def chat(*jids) Log.logger.debug("Received call for chat method") fetch_stdin unless jids.kind_of?(Array) Log.logger.error("Throwing ArgumentError because Jids is not an array.") raise ArgumentError, "Jids needs to be an Array got #{jids.class}" end if config..empty? Log.logger.error("No message to send. Exiting.") Log.logger.error("See https://github.com/nirnanaaa/sendxmpprb/wiki/Sending-messages for available message formats.") exit 1 end Message.batch do jids.each do |jid| Message.(jid) end end end |
#user(*jids) ⇒ Object
Public: Send a message to multiple users.
Message will be sent to each user seperately
jids - Receipient(s) can be one or more
Examples
user(["[email protected]"])
user(["[email protected]", "[email protected]"])
...
Returns 0 or 1 exit codes
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/sendxmpp/cli.rb', line 67 def user(*jids) Log.logger.debug("Received call for user method") fetch_stdin unless jids.kind_of?(Array) Log.logger.error("Throwing ArgumentError because Jids is not an array.") raise ArgumentError, "Jids needs to be an Array got #{jids.class}" end if config..empty? Log.logger.error("No message to send. Exiting.") Log.logger.error("See https://github.com/nirnanaaa/sendxmpprb/wiki/Sending-messages for available message formats.") exit 1 end Message.batch do jids.each do |jid| Message.(jid) end end end |