Class: XmppServer::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/xmpp_server.rb

Overview

xmpp client to push connect and push message to xmpp server

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(jid, password) ⇒ Client

Returns a new instance of Client.



20
21
22
23
24
# File 'lib/xmpp_server.rb', line 20

def initialize(jid, password)
	@jid      = jid
	@password = password
	@client   = Jabber::Client.new @jid 
end

Instance Attribute Details

#jidObject

Returns the value of attribute jid.



18
19
20
# File 'lib/xmpp_server.rb', line 18

def jid
  @jid
end

#passwordObject

Returns the value of attribute password.



18
19
20
# File 'lib/xmpp_server.rb', line 18

def password
  @password
end

Class Method Details

.get_default_clientObject



41
42
43
44
45
46
47
48
# File 'lib/xmpp_server.rb', line 41

def get_default_client
	jid      = "#{XmppServer::Config.username}@#{XmppServer::Config::server}/pusher"
	password = XmppServer::Config.password
	client   = XmppServer::Client.new(jid, password)
	client.connect
	client.auth
	client
end

Instance Method Details

#authObject



30
31
32
# File 'lib/xmpp_server.rb', line 30

def auth
	@client.auth @password
end

#connectObject



26
27
28
# File 'lib/xmpp_server.rb', line 26

def connect
	@client.connect
end

#push(m) ⇒ Object



34
35
36
37
38
# File 'lib/xmpp_server.rb', line 34

def push(m)
	to = "#{m.username}@#{XmppServer::Config.server}/nickname"
	msg = Jabber::Message::new(to, m.content).set_type(:normal).set_id(1)
	@client.send msg
end