Class: Vines::Stream::Client::Bind
- Inherits:
-
State
- Object
- State
- Vines::Stream::Client::Bind
show all
- Defined in:
- lib/vines/stream/client/bind.rb
Constant Summary
collapse
- NS =
NAMESPACES[:bind]
- MAX_ATTEMPTS =
5
Constants inherited
from State
State::BODY, State::STREAM
Instance Attribute Summary
Attributes inherited from State
#stream
Instance Method Summary
collapse
Methods inherited from State
#==, #eql?, #hash
Methods included from Log
#log
Constructor Details
#initialize(stream, success = Ready) ⇒ Bind
10
11
12
13
|
# File 'lib/vines/stream/client/bind.rb', line 10
def initialize(stream, success=Ready)
super
@attempts = 0
end
|
Instance Method Details
#node(node) ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/vines/stream/client/bind.rb', line 15
def node(node)
@attempts += 1
raise StreamErrors::NotAuthorized unless bind?(node)
raise StreamErrors::PolicyViolation.new('max bind attempts reached') if @attempts > MAX_ATTEMPTS
raise StanzaErrors::ResourceConstraint.new(node, 'wait') if resource_limit_reached?
stream.bind!(resource(node))
doc = Document.new
result = doc.create_element('iq', 'id' => node['id'], 'type' => 'result') do |el|
el << doc.create_element('bind') do |bind|
bind.default_namespace = NS
bind << doc.create_element('jid', stream.user.jid.to_s)
end
end
stream.write(result)
send_empty_features
advance
end
|