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.
- #join(jids) ⇒ Object
-
#mention_name ⇒ String
Mention name of this account.
-
#on_connection_established { ... } ⇒ Proc
Registers a callback called when a client connected to server.
-
#on_event {|element| ... } ⇒ Proc
Registers a callback called when client received a new XML element from server.
-
#on_invite(&block) ⇒ Proc
Registers a callback for invitation message.
-
#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.
19 20 21 |
# File 'lib/xrc/client.rb', line 19 def initialize( = {}) = end |
Instance Attribute Details
#users ⇒ Xrc::Roster (readonly)
Returns Users information existing in the server.
10 11 12 |
# File 'lib/xrc/client.rb', line 10 def users @users end |
Instance Method Details
#connect ⇒ nil
Connects to the JID’s server and waits for message
25 26 27 28 |
# File 'lib/xrc/client.rb', line 25 def connect connection.connect nil end |
#join(jids) ⇒ Object
139 140 141 142 143 |
# File 'lib/xrc/client.rb', line 139 def join(jids) Array(jids).each do |room_jid| post(Elements::Join.new(from: jid.strip, to: "#{room_jid}/#{nickname}")) end end |
#mention_name ⇒ String
Returns Mention name of this account.
135 136 137 |
# File 'lib/xrc/client.rb', line 135 def mention_name users[jid].try(:mention_name) end |
#on_connection_established { ... } ⇒ Proc
Registers a callback called when a client connected to server
38 39 40 |
# File 'lib/xrc/client.rb', line 38 def on_connection_established(&block) @on_connection_established_block = block end |
#on_event {|element| ... } ⇒ Proc
Registers a callback called when client received a new XML element from server
90 91 92 |
# File 'lib/xrc/client.rb', line 90 def on_event(&block) @on_event_block = block end |
#on_invite(&block) ⇒ Proc
Registers a callback for invitation message
96 97 98 |
# File 'lib/xrc/client.rb', line 96 def on_invite(&block) @on_invite_block = block end |
#on_private_message {|element| ... } ⇒ Proc
Registers a callback called when client received a new private message (a.k.a. 1vs1 message)
51 52 53 |
# File 'lib/xrc/client.rb', line 51 def (&block) = block end |
#on_room_message {|element| ... } ⇒ Proc
Registers a callback called when client received a new room message
64 65 66 |
# File 'lib/xrc/client.rb', line 64 def (&block) = block end |
#on_subject {|element| ... } ⇒ Proc
Registers a callback called when client received a new message with subject
77 78 79 |
# File 'lib/xrc/client.rb', line 77 def on_subject(&block) @on_subject_block = block end |
#reply(options) ⇒ REXML::Element
Replies to given message
106 107 108 109 110 111 112 113 |
# File 'lib/xrc/client.rb', line 106 def reply() say( body: [:body], from: [:to].to, to: [:to].from, type: [:to].type, ) end |
#say(options) ⇒ REXML::Element
Send a message
123 124 125 126 127 128 129 130 |
# File 'lib/xrc/client.rb', line 123 def say() post Elements::Message.new( body: [:body], from: [:from], to: [:to], type: [:type], ) end |