omf_common 6.0.0.pre.4 → 6.0.0.pre.6
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/omf_common.rb +1 -0
- data/lib/omf_common/comm.rb +2 -2
- data/lib/omf_common/core_ext/string.rb +0 -8
- data/lib/omf_common/dsl/{xmpp_blather.rb → xmpp.rb} +33 -28
- data/lib/omf_common/message.rb +1 -1
- data/lib/omf_common/version.rb +1 -1
- data/omf_common.gemspec +1 -1
- data/test/omf_common/comm_spec.rb +2 -2
- data/test/omf_common/core_ext/string_spec.rb +2 -6
- metadata +6 -10
- data/lib/omf_common/core_ext/blather/dsl/pubsub.rb +0 -11
- data/lib/omf_common/core_ext/blather/stream/features.rb +0 -34
- data/lib/omf_common/core_ext/blather/stream/features/register.rb +0 -40
data/lib/omf_common.rb
CHANGED
data/lib/omf_common/comm.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
require 'omf_common/dsl/
|
1
|
+
require 'omf_common/dsl/xmpp'
|
2
2
|
|
3
3
|
module OmfCommon
|
4
4
|
# PubSub communication class, can be extended with different implementations
|
5
5
|
class Comm
|
6
6
|
def initialize(pubsub_implementation)
|
7
|
-
self.extend("OmfCommon::DSL::#{pubsub_implementation.to_s.
|
7
|
+
self.extend("OmfCommon::DSL::#{pubsub_implementation.to_s.camelize}".constantize)
|
8
8
|
end
|
9
9
|
end
|
10
10
|
end
|
@@ -2,12 +2,4 @@ class String
|
|
2
2
|
def ducktype
|
3
3
|
Integer(self) rescue Float(self) rescue self
|
4
4
|
end
|
5
|
-
|
6
|
-
def camelcase
|
7
|
-
self.split('_').map(&:capitalize).join('')
|
8
|
-
end
|
9
|
-
|
10
|
-
def constant
|
11
|
-
self.split('::').inject(Object) { |obj, name| obj = obj.const_get(name); obj }
|
12
|
-
end
|
13
5
|
end
|
@@ -1,13 +1,12 @@
|
|
1
1
|
require 'blather/client/dsl'
|
2
|
-
require 'omf_common/core_ext/blather/dsl/pubsub'
|
3
|
-
require 'omf_common/core_ext/blather/stream/features'
|
4
|
-
require 'omf_common/core_ext/blather/stream/features/register'
|
5
2
|
|
6
3
|
module OmfCommon
|
7
4
|
module DSL
|
8
|
-
module
|
5
|
+
module Xmpp
|
9
6
|
include Blather::DSL
|
10
7
|
|
8
|
+
HOST_PREFIX = 'pubsub'
|
9
|
+
|
11
10
|
PUBSUB_CONFIGURE = Blather::Stanza::X.new({
|
12
11
|
:type => :submit,
|
13
12
|
:fields => [
|
@@ -27,59 +26,61 @@ module OmfCommon
|
|
27
26
|
end
|
28
27
|
|
29
28
|
# Shut down XMPP connection
|
30
|
-
|
31
|
-
# @param [String] host Host represents the pubsub address, e.g. pubsub.norbit.npc.nicta.com.au
|
32
|
-
def disconnect(host)
|
29
|
+
def disconnect
|
33
30
|
shutdown
|
34
31
|
end
|
35
32
|
|
36
|
-
# Create a new pubsub
|
33
|
+
# Create a new pubsub topic with additional configuration
|
37
34
|
#
|
38
|
-
# @param [String]
|
35
|
+
# @param [String] topic Pubsub topic name
|
39
36
|
# @param [String] host Pubsub host address
|
40
|
-
def
|
41
|
-
pubsub.
|
37
|
+
def create_topic(topic, host, &block)
|
38
|
+
pubsub.create(topic, prefix_host(host), PUBSUB_CONFIGURE, &callback_logging(__method__, topic, &block))
|
42
39
|
end
|
43
40
|
|
44
|
-
# Delete a pubsub
|
41
|
+
# Delete a pubsub topic
|
45
42
|
#
|
46
|
-
# @param [String]
|
43
|
+
# @param [String] topic Pubsub topic name
|
47
44
|
# @param [String] host Pubsub host address
|
48
|
-
def
|
49
|
-
pubsub.delete(
|
45
|
+
def delete_topic(topic, host, &block)
|
46
|
+
pubsub.delete(topic, prefix_host(host), &callback_logging(__method__, topic, &block))
|
50
47
|
end
|
51
48
|
|
52
|
-
# Subscribe to a pubsub
|
49
|
+
# Subscribe to a pubsub topic
|
53
50
|
#
|
54
|
-
# @param [String]
|
51
|
+
# @param [String] topic Pubsub topic name
|
55
52
|
# @param [String] host Pubsub host address
|
56
|
-
def subscribe(
|
57
|
-
pubsub.subscribe(
|
53
|
+
def subscribe(topic, host, &block)
|
54
|
+
pubsub.subscribe(topic, nil, prefix_host(host), &callback_logging(__method__, topic, &block))
|
58
55
|
end
|
59
56
|
|
60
|
-
# Un-subscribe all existing subscriptions from all pubsub
|
57
|
+
# Un-subscribe all existing subscriptions from all pubsub topics.
|
61
58
|
#
|
62
59
|
# @param [String] host Pubsub host address
|
63
60
|
def unsubscribe(host)
|
64
|
-
pubsub.subscriptions(host) do |m|
|
61
|
+
pubsub.subscriptions(prefix_host(host)) do |m|
|
65
62
|
m[:subscribed] && m[:subscribed].each do |s|
|
66
|
-
pubsub.unsubscribe(s[:node], nil, s[:subid], host, &callback_logging(__method__, s[:node], s[:subid]))
|
63
|
+
pubsub.unsubscribe(s[:node], nil, s[:subid], prefix_host(host), &callback_logging(__method__, s[:node], s[:subid]))
|
67
64
|
end
|
68
65
|
end
|
69
66
|
end
|
70
67
|
|
71
|
-
|
68
|
+
def affiliations(host, &block)
|
69
|
+
pubsub.affiliations(prefix_host(host), &callback_logging(__method__, &block))
|
70
|
+
end
|
71
|
+
|
72
|
+
# Publish to a pubsub topic
|
72
73
|
#
|
73
|
-
# @param [String]
|
74
|
+
# @param [String] topic Pubsub topic name
|
74
75
|
# @param [String] message Any XML fragment to be sent as payload
|
75
76
|
# @param [String] host Pubsub host address
|
76
|
-
def publish(
|
77
|
-
pubsub.publish(
|
77
|
+
def publish(topic, message, host, &block)
|
78
|
+
pubsub.publish(topic, message, prefix_host(host), &callback_logging(__method__, topic, message.operation, &block))
|
78
79
|
end
|
79
80
|
|
80
|
-
# Event callback for pubsub
|
81
|
+
# Event callback for pubsub topic event(item published)
|
81
82
|
#
|
82
|
-
def
|
83
|
+
def topic_event(*args, &block)
|
83
84
|
pubsub_event(:items?, *args, &callback_logging(__method__, &block))
|
84
85
|
end
|
85
86
|
|
@@ -94,6 +95,10 @@ module OmfCommon
|
|
94
95
|
block.call(callback) if block
|
95
96
|
end
|
96
97
|
end
|
98
|
+
|
99
|
+
def prefix_host(host)
|
100
|
+
"#{HOST_PREFIX}.#{host}"
|
101
|
+
end
|
97
102
|
end
|
98
103
|
end
|
99
104
|
end
|
data/lib/omf_common/message.rb
CHANGED
data/lib/omf_common/version.rb
CHANGED
data/omf_common.gemspec
CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |s|
|
|
20
20
|
|
21
21
|
# specify any dependencies here; for example:
|
22
22
|
s.add_development_dependency "minitest", "~> 2.11.3"
|
23
|
-
s.add_runtime_dependency "blather", "~> 0.
|
23
|
+
s.add_runtime_dependency "blather", "~> 0.8.0"
|
24
24
|
s.add_runtime_dependency "logging", "~> 1.7.1"
|
25
25
|
s.add_runtime_dependency "hashie", "~> 1.2.0"
|
26
26
|
end
|
@@ -3,8 +3,8 @@ require 'test_helper'
|
|
3
3
|
describe OmfCommon::Comm do
|
4
4
|
describe 'when initialised with a pubsub implementation' do
|
5
5
|
it 'must return a instance with all methods defined in corresponding module loaded' do
|
6
|
-
@comm = OmfCommon::Comm.new(:
|
7
|
-
%w(connect disconnect
|
6
|
+
@comm = OmfCommon::Comm.new(:xmpp)
|
7
|
+
%w(connect disconnect create_topic delete_topic subscribe unsubscribe publish affiliations).each do |m|
|
8
8
|
@comm.must_respond_to m
|
9
9
|
end
|
10
10
|
|
@@ -2,14 +2,10 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
describe String do
|
4
4
|
describe "when given a string" do
|
5
|
-
it "must response to
|
5
|
+
it "must response to ducktype" do
|
6
|
+
"100".ducktype.must_equal 100
|
6
7
|
"100.0".ducktype.must_equal 100.0
|
7
8
|
"i_am_a_string".ducktype.must_equal "i_am_a_string"
|
8
|
-
"i_am_a_string".camelcase.must_equal "IAmAString"
|
9
|
-
module IAmAString; end
|
10
|
-
"i_am_a_string".camelcase.constant.must_equal IAmAString
|
11
|
-
module IAmAString::Test; end
|
12
|
-
"IAmAString::Test".constant.must_equal IAmAString::Test
|
13
9
|
end
|
14
10
|
end
|
15
11
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omf_common
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 6.0.0.pre.
|
4
|
+
version: 6.0.0.pre.6
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-07-
|
12
|
+
date: 2012-07-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: minitest
|
@@ -34,7 +34,7 @@ dependencies:
|
|
34
34
|
requirements:
|
35
35
|
- - ~>
|
36
36
|
- !ruby/object:Gem::Version
|
37
|
-
version:
|
37
|
+
version: 0.8.0
|
38
38
|
type: :runtime
|
39
39
|
prerelease: false
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -42,7 +42,7 @@ dependencies:
|
|
42
42
|
requirements:
|
43
43
|
- - ~>
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
version:
|
45
|
+
version: 0.8.0
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
47
|
name: logging
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
@@ -89,11 +89,8 @@ files:
|
|
89
89
|
- lib/omf_common.rb
|
90
90
|
- lib/omf_common/comm.rb
|
91
91
|
- lib/omf_common/command.rb
|
92
|
-
- lib/omf_common/core_ext/blather/dsl/pubsub.rb
|
93
|
-
- lib/omf_common/core_ext/blather/stream/features.rb
|
94
|
-
- lib/omf_common/core_ext/blather/stream/features/register.rb
|
95
92
|
- lib/omf_common/core_ext/string.rb
|
96
|
-
- lib/omf_common/dsl/
|
93
|
+
- lib/omf_common/dsl/xmpp.rb
|
97
94
|
- lib/omf_common/message.rb
|
98
95
|
- lib/omf_common/protocol.rnc
|
99
96
|
- lib/omf_common/protocol.rng
|
@@ -124,9 +121,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
124
121
|
version: 1.3.1
|
125
122
|
requirements: []
|
126
123
|
rubyforge_project: omf_common
|
127
|
-
rubygems_version: 1.8.
|
124
|
+
rubygems_version: 1.8.24
|
128
125
|
signing_key:
|
129
126
|
specification_version: 3
|
130
127
|
summary: Common library of OMF
|
131
128
|
test_files: []
|
132
|
-
has_rdoc:
|
@@ -1,11 +0,0 @@
|
|
1
|
-
module Blather
|
2
|
-
module DSL
|
3
|
-
class PubSub
|
4
|
-
def create_with_configuration(node, configuration, host = nil)
|
5
|
-
stanza = Stanza::PubSub::Create.new(:set, send_to(host), node)
|
6
|
-
stanza.configure_node << configuration
|
7
|
-
request(stanza) { |n| yield n if block_given? }
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
module Blather
|
2
|
-
class Stream
|
3
|
-
# @private
|
4
|
-
class Features
|
5
|
-
def next!
|
6
|
-
@idx = @idx ? @idx+1 : 0
|
7
|
-
if stanza = @features.children[@idx]
|
8
|
-
if stanza.namespaces['xmlns'] && (klass = self.class.from_namespace(stanza.namespaces['xmlns']))
|
9
|
-
@feature = klass.new(
|
10
|
-
@stream,
|
11
|
-
proc {
|
12
|
-
if (klass == Blather::Stream::Register && @features && !@features.children.find { |v| v.element_name == "mechanisms" }.nil?)
|
13
|
-
stanza = @features.children.find { |v| v.element_name == "mechanisms" }
|
14
|
-
@idx = @features.children.index(stanza)
|
15
|
-
klass = self.class.from_namespace(stanza.namespaces['xmlns'])
|
16
|
-
@feature = klass.new @stream, proc { next! }, @fail
|
17
|
-
@feature.receive_data stanza
|
18
|
-
else
|
19
|
-
next!
|
20
|
-
end
|
21
|
-
},
|
22
|
-
(klass == Blather::Stream::SASL && @features && !@features.children.find { |v| v.element_name == "register" }.nil?) ? proc { next! } : @fail
|
23
|
-
)
|
24
|
-
@feature.receive_data stanza
|
25
|
-
else
|
26
|
-
next!
|
27
|
-
end
|
28
|
-
else
|
29
|
-
succeed!
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end #Stream
|
34
|
-
end #Blather
|
@@ -1,40 +0,0 @@
|
|
1
|
-
module Blather
|
2
|
-
class Stream
|
3
|
-
class Register < Features
|
4
|
-
REGISTER_NS = "http://jabber.org/features/iq-register".freeze
|
5
|
-
|
6
|
-
register REGISTER_NS
|
7
|
-
|
8
|
-
def initialize(stream, succeed, fail)
|
9
|
-
super
|
10
|
-
@jid = @stream.jid
|
11
|
-
@pass = @stream.password
|
12
|
-
end
|
13
|
-
|
14
|
-
def receive_data(stanza)
|
15
|
-
error_node = stanza.xpath('//error').first
|
16
|
-
|
17
|
-
if error_node
|
18
|
-
fail!(error_node)
|
19
|
-
elsif stanza['type'] == 'result' && (stanza.content.empty? || !stanza.children.find { |v| v.element_name == "query" }.nil?)
|
20
|
-
succeed!
|
21
|
-
else
|
22
|
-
@stream.send register_node
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def register_node
|
27
|
-
node = Blather::Stanza::Iq::Query.new(:set)
|
28
|
-
query_node = node.xpath('//query').first
|
29
|
-
query_node['xmlns'] = 'jabber:iq:register'
|
30
|
-
username_node = Nokogiri::XML::Node.new('username', node)
|
31
|
-
username_node.content = @jid.node
|
32
|
-
password_node = Nokogiri::XML::Node.new('password', node)
|
33
|
-
password_node.content = @pass
|
34
|
-
query_node.add_child(username_node)
|
35
|
-
query_node.add_child(password_node)
|
36
|
-
node
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|