xrc 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7bdf50fc7db1a293a2ea1a4e4ff89843060339bf
4
- data.tar.gz: 19b039f6249db2c307ab1be441f00267e9c63145
3
+ metadata.gz: 09c52dabd4cb36ef0aa8f4fe0a47e58513bde212
4
+ data.tar.gz: e7de2dc52efff5426ac88f1e1250cf3d54f1e7b4
5
5
  SHA512:
6
- metadata.gz: e27ee54faf8f8bbc91547f58cb6b50208660fbc82256e69ef8a40822174c482847d2d55da79f180d334996a6b968d41b75094a76f0e004c0ddd5620464c55c8a
7
- data.tar.gz: a6135d4d3862f9dfd1a6cef147fba0c2de3de13dc5d8c9aabdba832c231d12e1d8bcf9be8d2275eee059ecd253da402ad6adbd6c37317d3d381791602de804ef
6
+ metadata.gz: 1e6a674ed0dc77b987a883d9e8b7f6064b0dc6d786d96813a163c676d058f03b1952823ab136dc90cb40aec841d7610578e5589177c067f872afe6bb27af615f
7
+ data.tar.gz: 5dd6a07664227ca0e391a6f0ee2cb424aba0e4d36f9facee7f9fdbfcaf2853c21629cae5cd4032860f961e98195e939f726d6acb597ceb50fa13c0de8e045577
@@ -1,3 +1,6 @@
1
+ ## 0.1.1
2
+ * Support invite message
3
+
1
4
  ## 0.1.0
2
5
  * Support comma-separated multi room JIDs
3
6
 
data/lib/xrc.rb CHANGED
@@ -30,6 +30,7 @@ require "xrc/elements/stream"
30
30
  require "xrc/hosts_resolver"
31
31
  require "xrc/message_builder"
32
32
  require "xrc/messages/base"
33
+ require "xrc/messages/invite"
33
34
  require "xrc/messages/null"
34
35
  require "xrc/messages/message"
35
36
  require "xrc/messages/private_message"
@@ -77,6 +77,12 @@ module Xrc
77
77
  @on_event_block = block
78
78
  end
79
79
 
80
+ # Registers a callback for invitation message
81
+ # @return [Proc] Returns given block
82
+ def on_invite(&block)
83
+ @on_invite_block = block
84
+ end
85
+
80
86
  # Replies to given message
81
87
  # @option options [Xrc::Messages::Base] :to A message object given from server
82
88
  # @option options [String] :body A text to be sent to server
@@ -116,6 +122,12 @@ module Xrc
116
122
  users[jid].try(:mention_name)
117
123
  end
118
124
 
125
+ def join(jids)
126
+ Array(jids).each do |room_jid|
127
+ post(Elements::Join.new(from: jid.strip, to: "#{room_jid}/#{nickname}"))
128
+ end
129
+ end
130
+
119
131
  private
120
132
 
121
133
  def on_event_block
@@ -134,6 +146,10 @@ module Xrc
134
146
  @on_subject_block ||= ->(element) {}
135
147
  end
136
148
 
149
+ def on_invite_block
150
+ @on_invite_block ||= ->(element) {}
151
+ end
152
+
137
153
  def on_received(element)
138
154
  on_event_block.call(element)
139
155
  case
@@ -191,6 +207,8 @@ module Xrc
191
207
  on_private_message_block.call(message)
192
208
  when Messages::Subject
193
209
  on_subject_block.call(message)
210
+ when Messages::Invite
211
+ on_invite_block.call(message)
194
212
  end
195
213
  end
196
214
 
@@ -248,7 +266,7 @@ module Xrc
248
266
  end
249
267
 
250
268
  def on_connection_established
251
- join
269
+ join(room_jids)
252
270
  start_ping_thread
253
271
  end
254
272
 
@@ -299,12 +317,6 @@ module Xrc
299
317
  post(Elements::Presence.new)
300
318
  end
301
319
 
302
- def join
303
- room_jids.each do |room_jid|
304
- post(Elements::Join.new(from: jid.strip, to: "#{room_jid}/#{nickname}"))
305
- end
306
- end
307
-
308
320
  def ping
309
321
  post(Elements::Ping.new(from: jid.to_s, to: jid.domain))
310
322
  end
@@ -26,6 +26,8 @@ module Xrc
26
26
  Messages::PrivateMessage
27
27
  when has_subject?
28
28
  Messages::Subject
29
+ when has_invite?
30
+ Messages::Invite
29
31
  else
30
32
  Messages::Null
31
33
  end
@@ -55,6 +57,10 @@ module Xrc
55
57
  !!@element.elements["subject"]
56
58
  end
57
59
 
60
+ def has_invite?
61
+ !!@element.elements["x/invite"]
62
+ end
63
+
58
64
  def type
59
65
  @element.attributes["type"].to_s
60
66
  end
@@ -0,0 +1,9 @@
1
+ module Xrc
2
+ module Messages
3
+ class Invite < Base
4
+ def room_name
5
+ @element["name/text()"].to_s
6
+ end
7
+ end
8
+ end
9
+ end
@@ -1,3 +1,3 @@
1
1
  module Xrc
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xrc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryo Nakamura
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-20 00:00:00.000000000 Z
11
+ date: 2014-06-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -112,6 +112,7 @@ files:
112
112
  - lib/xrc/jid.rb
113
113
  - lib/xrc/message_builder.rb
114
114
  - lib/xrc/messages/base.rb
115
+ - lib/xrc/messages/invite.rb
115
116
  - lib/xrc/messages/message.rb
116
117
  - lib/xrc/messages/null.rb
117
118
  - lib/xrc/messages/private_message.rb