Class: DaemonKit::XMPP
- Inherits:
-
Object
- Object
- DaemonKit::XMPP
- Includes:
- Blather::DSL
- Defined in:
- lib/daemon_kit/xmpp.rb
Overview
Thin wrapper around the blather DSL
Class Method Summary collapse
Instance Method Summary collapse
- #become_available ⇒ Object
- #busy(message = nil, &block) ⇒ Object
- #configure_roster! ⇒ Object
- #contacts ⇒ Object
-
#initialize ⇒ XMPP
constructor
A new instance of XMPP.
- #run ⇒ Object
- #trusted?(message) ⇒ Boolean
Constructor Details
#initialize ⇒ XMPP
Returns a new instance of XMPP.
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 |
# File 'lib/daemon_kit/xmpp.rb', line 24 def initialize @config = DaemonKit::Config.load('xmpp') if @config.enable_logging Blather.logger = DaemonKit.logger end jid = if @config.resource "#{@config.jabber_id}/#{@config.resource}" else @config.jabber_id end # host & port allow nil, defaults to the jabber id host and default port # so if those keys are not present in the config, its ok. setup jid, @config.password, @config.host, @config.port when_ready do configure_roster! become_available end return if @config['require_master'] == false do |m| trusted?( m ) ? pass : halt end end |
Class Method Details
Instance Method Details
#become_available ⇒ Object
77 78 79 |
# File 'lib/daemon_kit/xmpp.rb', line 77 def become_available set_status( :chat, "#{DaemonKit.configuration.daemon_name} is available" ) end |
#busy(message = nil, &block) ⇒ Object
93 94 95 96 97 98 99 |
# File 'lib/daemon_kit/xmpp.rb', line 93 def busy( = nil, &block ) set_status( :dnd, ) block.call become_available end |
#configure_roster! ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/daemon_kit/xmpp.rb', line 53 def configure_roster! DaemonKit.logger.debug 'Configuring roster' my_roster.each do |(jid, item)| unless contacts.include?( jid ) DaemonKit.logger.debug "Removing #{jid} from roster" my_roster.delete( item.jid ) next end end contacts.each do |jid| DaemonKit.logger.debug "Adding #{jid} to roster" my_roster.add( Blather::JID.new( jid ) ) end my_roster.each do |(jid,item)| item.subscription = :both item.ask = :subscribe end end |
#contacts ⇒ Object
85 86 87 |
# File 'lib/daemon_kit/xmpp.rb', line 85 def contacts @config.masters + @config.supporters end |
#run ⇒ Object
89 90 91 |
# File 'lib/daemon_kit/xmpp.rb', line 89 def run client.run end |
#trusted?(message) ⇒ Boolean
81 82 83 |
# File 'lib/daemon_kit/xmpp.rb', line 81 def trusted?( ) @config.masters.include?( .from.stripped.to_s ) end |