Class: Xrc::Client
- Inherits:
-
Object
- Object
- Xrc::Client
- Defined in:
- lib/xrc/client.rb
Constant Summary collapse
- DEFAULT_PORT =
5222- PING_INTERVAL =
30
Instance Attribute Summary collapse
-
#users ⇒ Xrc::Roster
readonly
Users information existing in the server.
Instance Method Summary collapse
-
#connect ⇒ nil
Connects to the JID’s server and waits for message.
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
-
#mention_name ⇒ String
Mention name of this account.
-
#on_event {|element| ... } ⇒ Proc
Registers a callback called when client received a new XML element from server.
-
#on_private_message {|element| ... } ⇒ Proc
Registers a callback called when client received a new private message (a.k.a. 1vs1 message).
-
#on_room_message {|element| ... } ⇒ Proc
Registers a callback called when client received a new room message.
-
#on_subject {|element| ... } ⇒ Proc
Registers a callback called when client received a new message with subject.
-
#reply(options) ⇒ REXML::Element
Replies to given message.
-
#say(options) ⇒ REXML::Element
Send a message.
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
17 18 19 |
# File 'lib/xrc/client.rb', line 17 def initialize( = {}) @options = end |
Instance Attribute Details
#users ⇒ Xrc::Roster (readonly)
Returns Users information existing in the server.
8 9 10 |
# File 'lib/xrc/client.rb', line 8 def users @users end |
Instance Method Details
#connect ⇒ nil
Connects to the JID’s server and waits for message
23 24 25 26 |
# File 'lib/xrc/client.rb', line 23 def connect connection.connect nil end |
#mention_name ⇒ String
Returns Mention name of this account.
115 116 117 |
# File 'lib/xrc/client.rb', line 115 def mention_name users[jid].try(:mention_name) end |
#on_event {|element| ... } ⇒ Proc
Registers a callback called when client received a new XML element from server
76 77 78 |
# File 'lib/xrc/client.rb', line 76 def on_event(&block) @on_event_block = block end |
#on_private_message {|element| ... } ⇒ Proc
Registers a callback called when client received a new private message (a.k.a. 1vs1 message)
37 38 39 |
# File 'lib/xrc/client.rb', line 37 def (&block) @on_private_message_block = block end |
#on_room_message {|element| ... } ⇒ Proc
Registers a callback called when client received a new room message
50 51 52 |
# File 'lib/xrc/client.rb', line 50 def (&block) @on_room_message_block = block end |
#on_subject {|element| ... } ⇒ Proc
Registers a callback called when client received a new message with subject
63 64 65 |
# File 'lib/xrc/client.rb', line 63 def on_subject(&block) @on_subject_block = block end |
#reply(options) ⇒ REXML::Element
Replies to given message
86 87 88 89 90 91 92 93 |
# File 'lib/xrc/client.rb', line 86 def reply() say( body: [:body], from: [:to].to, to: [:to].from, type: [:to].type, ) end |