Class: CollinsNotify::IrcAdapter
- Defined in:
- lib/collins_notify/adapter/irc.rb
Instance Method Summary collapse
- #configure! ⇒ Object
-
#notify!(message_obj = OpenStruct.new, to = nil) ⇒ Object
Available in template binding: message_obj - Depends on call nick - nickname channel - channel sending to host - host connecting to port - port on host being connected to.
Methods inherited from Notifier
adapter_name, adapters, get_adapter, #initialize, mimetypes, register_name, require_config, required_config_keys, requires_config?, #supports_html?, supports_mimetype, #supports_text?
Constructor Details
This class inherits a constructor from CollinsNotify::Notifier
Instance Method Details
#configure! ⇒ Object
9 10 11 12 13 |
# File 'lib/collins_notify/adapter/irc.rb', line 9 def configure! # An exception gets thrown if needed get_channel symbolize_hash(deep_copy_hash(config.adapters[:irc])), nil nil end |
#notify!(message_obj = OpenStruct.new, to = nil) ⇒ Object
Available in template binding:
message_obj - Depends on call
nick - nickname
channel - channel sending to
host - host connecting to
port - port on host being connected to
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/collins_notify/adapter/irc.rb', line 21 def notify! = OpenStruct.new, to = nil tmp_config = symbolize_hash(deep_copy_hash(config.adapters[:irc])) host = tmp_config.delete(:host) port = tmp_config.delete(:port).to_i nick = tmp_config.delete(:username) channel = get_channel(tmp_config, to) tmp_config.delete(:channel) cp_config = { :host => host, :port => port, :nick => nick, :channel => channel, :logger => logger } cp_config.merge!(tmp_config) logger.trace "Using IRC config: #{cp_config.inspect}" if config.test? then logger.info "Not sending message in test mode" return true end cp = try_connect cp_config return false unless cp logger.info "Connected to IRC" begin body = (binding).strip.gsub(/[\n\r]/, ' ') cp. body, cp_config[:notice] true rescue CollinsNotify::CollinsNotifyException => e logger.error "error sending irc notification - #{e}" raise e rescue Exception => e logger.error "#{e.class.to_s} - error sending irc notification - #{e}" raise CollinsNotify::CollinsNotifyException.new e ensure cp.die end end |