Sha256: d32d3c3c2df6c34eeb2c5484c79b4d0ed9fccf50f83432913d2691ff620781df

Contents?: true

Size: 1.54 KB

Versions: 7

Compression:

Stored size: 1.54 KB

Contents

module UniformNotifier
  class Xmpp < Base
    @receiver = nil
    @xmpp = nil
    @password = nil

    def self.active?
      @xmpp
    end

    def self.out_of_channel_notify( message )
      return unless active?
      notify( message )
    end

    def self.setup_connection( xmpp_information )
      return unless xmpp_information

      require 'xmpp4r'

      @xmpp = xmpp_information
      @receiver = xmpp_information[:receiver]
      @password = xmpp_information[:password]
      @account  = xmpp_information[:account]
      @show_online_status = xmpp_information[:show_online_status]
      @stay_connected = xmpp_information[:stay_connected].nil? ? true : xmpp_information[:stay_connected]

      connect if @stay_connected
    rescue LoadError
      @xmpp = nil
      raise NotificationError.new( 'You must install the xmpp4r gem to use XMPP notification: `gem install xmpp4r`' )
    end

    private
      def self.connect
        jid = Jabber::JID.new( @account )
        @xmpp = Jabber::Client.new( jid )
        @xmpp.connect
        @xmpp.auth( @password )
        @xmpp.send( presence_status ) if @show_online_status
      end

      def self.notify( message )
        connect unless @stay_connected
        message = Jabber::Message.new( @receiver, message ).
                                  set_type( :normal ).
                                  set_subject( 'Uniform Notifier' )
        @xmpp.send( message )
      end

      def self.presence_status
        Jabber::Presence.new.set_status( "Uniform Notifier started on #{Time.now}" )
      end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
uniform_notifier-1.5.0 lib/uniform_notifier/xmpp.rb
uniform_notifier-1.4.0 lib/uniform_notifier/xmpp.rb
uniform_notifier-1.3.0 lib/uniform_notifier/xmpp.rb
uniform_notifier-1.2.0 lib/uniform_notifier/xmpp.rb
uniform_notifier-1.1.1 lib/uniform_notifier/xmpp.rb
uniform_notifier-1.1.0 lib/uniform_notifier/xmpp.rb
uniform_notifier-1.0.2 lib/uniform_notifier/xmpp.rb