blather 0.3.4 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +1 -1
- data/README.rdoc +41 -12
- data/examples/echo.rb +1 -1
- data/examples/execute.rb +0 -5
- data/examples/pubsub/cli.rb +64 -0
- data/examples/pubsub/ping_pong.rb +18 -0
- data/examples/rosterprint.rb +14 -0
- data/examples/xmpp4r/echo.rb +35 -0
- data/lib/blather.rb +35 -12
- data/lib/blather/client.rb +1 -1
- data/lib/blather/client/client.rb +19 -13
- data/lib/blather/client/dsl.rb +16 -0
- data/lib/blather/client/dsl/pubsub.rb +133 -0
- data/lib/blather/core_ext/active_support.rb +1 -117
- data/lib/blather/core_ext/active_support/inheritable_attributes.rb +117 -0
- data/lib/blather/core_ext/nokogiri.rb +35 -0
- data/lib/blather/errors.rb +3 -20
- data/lib/blather/errors/sasl_error.rb +3 -1
- data/lib/blather/errors/stanza_error.rb +10 -17
- data/lib/blather/errors/stream_error.rb +11 -14
- data/lib/blather/jid.rb +1 -0
- data/lib/blather/roster.rb +9 -0
- data/lib/blather/roster_item.rb +6 -1
- data/lib/blather/stanza.rb +35 -18
- data/lib/blather/stanza/disco.rb +7 -1
- data/lib/blather/stanza/disco/disco_info.rb +45 -33
- data/lib/blather/stanza/disco/disco_items.rb +32 -21
- data/lib/blather/stanza/iq.rb +13 -8
- data/lib/blather/stanza/iq/query.rb +16 -8
- data/lib/blather/stanza/iq/roster.rb +33 -22
- data/lib/blather/stanza/message.rb +20 -31
- data/lib/blather/stanza/presence.rb +3 -5
- data/lib/blather/stanza/presence/status.rb +13 -21
- data/lib/blather/stanza/presence/subscription.rb +11 -16
- data/lib/blather/stanza/pubsub.rb +63 -0
- data/lib/blather/stanza/pubsub/affiliations.rb +50 -0
- data/lib/blather/stanza/pubsub/create.rb +43 -0
- data/lib/blather/stanza/pubsub/errors.rb +9 -0
- data/lib/blather/stanza/pubsub/event.rb +77 -0
- data/lib/blather/stanza/pubsub/items.rb +63 -0
- data/lib/blather/stanza/pubsub/publish.rb +58 -0
- data/lib/blather/stanza/pubsub/retract.rb +53 -0
- data/lib/blather/stanza/pubsub/subscribe.rb +42 -0
- data/lib/blather/stanza/pubsub/subscription.rb +66 -0
- data/lib/blather/stanza/pubsub/subscriptions.rb +55 -0
- data/lib/blather/stanza/pubsub/unsubscribe.rb +42 -0
- data/lib/blather/stanza/pubsub_owner.rb +41 -0
- data/lib/blather/stanza/pubsub_owner/delete.rb +34 -0
- data/lib/blather/stanza/pubsub_owner/purge.rb +34 -0
- data/lib/blather/stream.rb +76 -168
- data/lib/blather/stream/client.rb +1 -2
- data/lib/blather/stream/component.rb +9 -5
- data/lib/blather/stream/features.rb +53 -0
- data/lib/blather/stream/features/resource.rb +63 -0
- data/lib/blather/stream/{sasl.rb → features/sasl.rb} +53 -52
- data/lib/blather/stream/features/session.rb +44 -0
- data/lib/blather/stream/features/tls.rb +28 -0
- data/lib/blather/stream/parser.rb +70 -46
- data/lib/blather/xmpp_node.rb +113 -52
- data/spec/blather/client/client_spec.rb +44 -58
- data/spec/blather/client/dsl/pubsub_spec.rb +465 -0
- data/spec/blather/client/dsl_spec.rb +19 -6
- data/spec/blather/core_ext/nokogiri_spec.rb +83 -0
- data/spec/blather/errors/sasl_error_spec.rb +8 -8
- data/spec/blather/errors/stanza_error_spec.rb +25 -33
- data/spec/blather/errors/stream_error_spec.rb +21 -16
- data/spec/blather/errors_spec.rb +4 -11
- data/spec/blather/jid_spec.rb +31 -30
- data/spec/blather/roster_item_spec.rb +34 -23
- data/spec/blather/roster_spec.rb +27 -12
- data/spec/blather/stanza/discos/disco_info_spec.rb +61 -42
- data/spec/blather/stanza/discos/disco_items_spec.rb +47 -35
- data/spec/blather/stanza/iq/query_spec.rb +34 -11
- data/spec/blather/stanza/iq/roster_spec.rb +47 -30
- data/spec/blather/stanza/iq_spec.rb +19 -14
- data/spec/blather/stanza/message_spec.rb +30 -17
- data/spec/blather/stanza/presence/status_spec.rb +43 -20
- data/spec/blather/stanza/presence/subscription_spec.rb +41 -21
- data/spec/blather/stanza/presence_spec.rb +34 -21
- data/spec/blather/stanza/pubsub/affiliations_spec.rb +57 -0
- data/spec/blather/stanza/pubsub/create_spec.rb +56 -0
- data/spec/blather/stanza/pubsub/event_spec.rb +84 -0
- data/spec/blather/stanza/pubsub/items_spec.rb +79 -0
- data/spec/blather/stanza/pubsub/publish_spec.rb +83 -0
- data/spec/blather/stanza/pubsub/retract_spec.rb +75 -0
- data/spec/blather/stanza/pubsub/subscribe_spec.rb +61 -0
- data/spec/blather/stanza/pubsub/subscription_spec.rb +97 -0
- data/spec/blather/stanza/pubsub/subscriptions_spec.rb +59 -0
- data/spec/blather/stanza/pubsub/unsubscribe_spec.rb +61 -0
- data/spec/blather/stanza/pubsub_owner/delete_spec.rb +50 -0
- data/spec/blather/stanza/pubsub_owner/purge_spec.rb +50 -0
- data/spec/blather/stanza/pubsub_owner_spec.rb +27 -0
- data/spec/blather/stanza/pubsub_spec.rb +62 -0
- data/spec/blather/stanza_spec.rb +53 -38
- data/spec/blather/stream/client_spec.rb +231 -88
- data/spec/blather/stream/component_spec.rb +14 -5
- data/spec/blather/stream/parser_spec.rb +145 -0
- data/spec/blather/xmpp_node_spec.rb +192 -96
- data/spec/fixtures/pubsub.rb +311 -0
- data/spec/spec_helper.rb +5 -4
- metadata +54 -18
- data/Rakefile +0 -139
- data/ext/extconf.rb +0 -65
- data/ext/push_parser.c +0 -209
- data/lib/blather/core_ext/libxml.rb +0 -28
- data/lib/blather/stream/resource.rb +0 -48
- data/lib/blather/stream/session.rb +0 -36
- data/lib/blather/stream/stream_handler.rb +0 -39
- data/lib/blather/stream/tls.rb +0 -33
- data/spec/blather/core_ext/libxml_spec.rb +0 -58
@@ -1,36 +0,0 @@
|
|
1
|
-
module Blather # :nodoc:
|
2
|
-
class Stream # :nodoc:
|
3
|
-
|
4
|
-
class Session < StreamHandler # :nodoc:
|
5
|
-
def initialize(stream, to)
|
6
|
-
super stream
|
7
|
-
@to = to
|
8
|
-
end
|
9
|
-
|
10
|
-
private
|
11
|
-
##
|
12
|
-
# Send a start session command
|
13
|
-
def session
|
14
|
-
response = Stanza::Iq.new :set
|
15
|
-
response.to = @to
|
16
|
-
sess = XMPPNode.new 'session'
|
17
|
-
sess['xmlns'] = 'urn:ietf:params:xml:ns:xmpp-session'
|
18
|
-
response << sess
|
19
|
-
@stream.send response
|
20
|
-
end
|
21
|
-
|
22
|
-
##
|
23
|
-
# The server should respond with a <result> node if all is well
|
24
|
-
def result
|
25
|
-
success
|
26
|
-
end
|
27
|
-
|
28
|
-
##
|
29
|
-
# Server returned an error.
|
30
|
-
def error
|
31
|
-
failure StanzaError.import(@node)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
end
|
36
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
module Blather # :nodoc:
|
2
|
-
class Stream # :nodoc:
|
3
|
-
|
4
|
-
class StreamHandler # :nodoc:
|
5
|
-
def on_success(&block); @success = block; end
|
6
|
-
def on_failure(&block); @failure = block; end
|
7
|
-
|
8
|
-
def initialize(stream)
|
9
|
-
@stream = stream
|
10
|
-
end
|
11
|
-
|
12
|
-
def handle(node)
|
13
|
-
@node = node
|
14
|
-
method = @node.element_name == 'iq' ? @node['type'] : @node.element_name
|
15
|
-
if self.respond_to?(method, true)
|
16
|
-
self.__send__ method
|
17
|
-
else
|
18
|
-
@failure.call UnknownResponse.new(@node)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
protected
|
23
|
-
##
|
24
|
-
# Handle error response from the server
|
25
|
-
def error
|
26
|
-
failure
|
27
|
-
end
|
28
|
-
|
29
|
-
def success(message_back = nil)
|
30
|
-
@success.call message_back
|
31
|
-
end
|
32
|
-
|
33
|
-
def failure(err = nil)
|
34
|
-
@failure.call err
|
35
|
-
end
|
36
|
-
end #StreamHandler
|
37
|
-
|
38
|
-
end #Stream
|
39
|
-
end #Blather
|
data/lib/blather/stream/tls.rb
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
module Blather # :nodoc:
|
2
|
-
class Stream # :nodoc:
|
3
|
-
|
4
|
-
# TLS negotiation invovles 3 node types:
|
5
|
-
# * starttls -- Server asking for TLS to be started
|
6
|
-
# * proceed -- Server saying it's ready for a TLS connection to be started
|
7
|
-
# * failure -- Failed TLS negotiation. Failure results in a closed connection.
|
8
|
-
# so there's no message to pass back to the tream
|
9
|
-
class TLS < StreamHandler # :nodoc:
|
10
|
-
private
|
11
|
-
##
|
12
|
-
# After receiving <starttls> from the server send one
|
13
|
-
# back to let it know we're ready to start TLS
|
14
|
-
def starttls
|
15
|
-
@stream.send "<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>"
|
16
|
-
end
|
17
|
-
|
18
|
-
##
|
19
|
-
# Server's ready for TLS, so start it up
|
20
|
-
def proceed
|
21
|
-
@stream.start_tls
|
22
|
-
success
|
23
|
-
end
|
24
|
-
|
25
|
-
##
|
26
|
-
# Negotiations failed
|
27
|
-
def failure
|
28
|
-
super StreamError::TLSFailure.new
|
29
|
-
end
|
30
|
-
end #TLS
|
31
|
-
|
32
|
-
end #Stream
|
33
|
-
end #Blather
|
@@ -1,58 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), *%w[.. .. spec_helper])
|
2
|
-
|
3
|
-
describe 'LibXML::XML::Node' do
|
4
|
-
it 'aliases #name to #element_name' do
|
5
|
-
node = LibXML::XML::Node.new 'foo'
|
6
|
-
node.must_respond_to :element_name
|
7
|
-
node.element_name.must_equal node.name
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'aliases #name= to #element_name=' do
|
11
|
-
node = LibXML::XML::Node.new 'foo'
|
12
|
-
node.must_respond_to :element_name=
|
13
|
-
node.element_name.must_equal node.name
|
14
|
-
node.element_name = 'bar'
|
15
|
-
node.element_name.must_equal 'bar'
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
describe 'LibXML::XML::Attributes' do
|
20
|
-
it 'provides a helper to remove a specified attribute' do
|
21
|
-
attrs = LibXML::XML::Node.new('foo').attributes
|
22
|
-
attrs['foo'] = 'bar'
|
23
|
-
attrs['foo'].must_equal 'bar'
|
24
|
-
attrs.remove 'foo'
|
25
|
-
attrs['foo'].must_be_nil
|
26
|
-
|
27
|
-
attrs['foo'] = 'bar'
|
28
|
-
attrs['foo'].must_equal 'bar'
|
29
|
-
attrs.remove :foo
|
30
|
-
attrs['foo'].must_be_nil
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'allows symbols as hash keys' do
|
34
|
-
attrs = LibXML::XML::Node.new('foo').attributes
|
35
|
-
attrs['foo'] = 'bar'
|
36
|
-
|
37
|
-
attrs['foo'].must_equal 'bar'
|
38
|
-
attrs[:foo].must_equal 'bar'
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'removes an attribute when set to nil' do
|
42
|
-
attrs = LibXML::XML::Node.new('foo').attributes
|
43
|
-
attrs['foo'] = 'bar'
|
44
|
-
|
45
|
-
attrs['foo'].must_equal 'bar'
|
46
|
-
attrs['foo'] = nil
|
47
|
-
attrs['foo'].must_be_nil
|
48
|
-
end
|
49
|
-
|
50
|
-
it 'allows attribute values to change' do
|
51
|
-
attrs = LibXML::XML::Node.new('foo').attributes
|
52
|
-
attrs['foo'] = 'bar'
|
53
|
-
|
54
|
-
attrs['foo'].must_equal 'bar'
|
55
|
-
attrs['foo'] = 'baz'
|
56
|
-
attrs['foo'].must_equal 'baz'
|
57
|
-
end
|
58
|
-
end
|