mojodna-switchboard 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +28 -0
- data/bin/switchboard +2 -4
- data/lib/switchboard/commands/default.rb +1 -0
- data/lib/switchboard/commands/pubsub/affiliations.rb +38 -0
- data/lib/switchboard/commands/pubsub/config.rb +46 -0
- data/lib/switchboard/commands/pubsub/create.rb +45 -0
- data/lib/switchboard/commands/pubsub/delete.rb +36 -0
- data/lib/switchboard/commands/pubsub/info.rb +52 -0
- data/lib/switchboard/commands/pubsub/items.rb +44 -0
- data/lib/switchboard/commands/pubsub/listen.rb +20 -0
- data/lib/switchboard/commands/pubsub/nodes.rb +41 -0
- data/lib/switchboard/commands/pubsub/options.rb +44 -0
- data/lib/switchboard/commands/pubsub/publish.rb +47 -0
- data/lib/switchboard/commands/pubsub/pubsub.rb +5 -6
- data/lib/switchboard/commands/pubsub/purge.rb +36 -0
- data/lib/switchboard/commands/pubsub/subscribe.rb +2 -2
- data/lib/switchboard/commands/pubsub/subscriptions.rb +2 -2
- data/lib/switchboard/commands/pubsub.rb +11 -0
- data/lib/switchboard/commands/register.rb +5 -1
- data/lib/switchboard/core.rb +2 -1
- data/lib/switchboard/ext/delegate.rb +21 -0
- data/lib/switchboard/{instance_exec.rb → ext/instance_exec.rb} +0 -0
- data/lib/switchboard/helpers/oauth_pubsub.rb +39 -0
- data/lib/switchboard/helpers/pubsub.rb +25 -0
- data/lib/switchboard/jacks/oauth_pubsub.rb +3 -45
- data/lib/switchboard/jacks/pubsub.rb +3 -34
- data/lib/switchboard/version.rb +1 -1
- data/switchboard.gemspec +2 -2
- metadata +17 -2
data/Rakefile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'switchboard'
|
2
|
+
|
3
|
+
task :gemspec do
|
4
|
+
gemspec =<<-EOF
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "switchboard"
|
7
|
+
s.version = "#{Switchboard::VERSION * "."}"
|
8
|
+
s.summary = "XMPP toolkit."
|
9
|
+
s.description = "A toolkit for assembling XMPP clients and interacting with XMPP servers."
|
10
|
+
s.authors = ["Seth Fitzsimmons"]
|
11
|
+
s.email = ["seth@mojodna.net"]
|
12
|
+
|
13
|
+
s.files = #{Dir.glob("**/*").select { |f| File.file?(f) }.inspect}
|
14
|
+
s.executables = ["switchboard"]
|
15
|
+
s.require_paths = ["lib"]
|
16
|
+
|
17
|
+
s.add_dependency("xmpp4r")
|
18
|
+
end
|
19
|
+
EOF
|
20
|
+
|
21
|
+
open("switchboard.gemspec", "w") do |f|
|
22
|
+
f << gemspec
|
23
|
+
end
|
24
|
+
|
25
|
+
puts "gemspec successfully created."
|
26
|
+
end
|
27
|
+
|
28
|
+
task :default => :gemspec
|
data/bin/switchboard
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
require 'switchboard'
|
3
3
|
require 'optparse'
|
4
4
|
|
5
|
-
|
5
|
+
ARGV.clone.options do |opts|
|
6
6
|
# opts.banner = "Usage: example.rb [options]"
|
7
7
|
|
8
8
|
command = Switchboard::Commands::Default
|
@@ -30,6 +30,4 @@ command = ARGV.clone.options do |opts|
|
|
30
30
|
ARGV.reject! { |v| !argv.include?(v) }
|
31
31
|
|
32
32
|
command
|
33
|
-
end
|
34
|
-
|
35
|
-
command.run!
|
33
|
+
end.run!
|
@@ -19,6 +19,7 @@ module Switchboard
|
|
19
19
|
|
20
20
|
# opts.on("-d", "--daemon", "Make server run as a daemon.") { OPTIONS[:detach] = true }
|
21
21
|
opts.on("-j", "--jid=jid", String, "Specifies the JID to use.") { |v| OPTIONS["jid"] = v }
|
22
|
+
opts.on("-r", "--resource=resource", String, "Specifies the resource to use.") { |v| OPTIONS["resource"] = v }
|
22
23
|
opts.on("-p", "--password=password", String, "Specifies the password to use.") { |v| OPTIONS["password"] = v }
|
23
24
|
# opts.on("-p", "--pidfile=path", String,
|
24
25
|
# "Specifies a pidfile to use.") { |v| OPTIONS[:pidfile] = v }
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Switchboard
|
2
|
+
module Commands
|
3
|
+
class PubSub
|
4
|
+
class Affiliations < Switchboard::Command
|
5
|
+
description "Lists pubsub affiliations"
|
6
|
+
|
7
|
+
def self.run!
|
8
|
+
switchboard = Switchboard::Core.new do
|
9
|
+
defer :affiliations_received do
|
10
|
+
begin
|
11
|
+
pubsub.get_affiliations(OPTIONS["pubsub.node"])
|
12
|
+
rescue Jabber::ServerError => e
|
13
|
+
puts e
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def affiliations_received(affiliations)
|
18
|
+
if affiliations
|
19
|
+
affiliations.each do |node, affiliation|
|
20
|
+
puts [node, affiliation] * " => "
|
21
|
+
end
|
22
|
+
else
|
23
|
+
puts "No affiliations."
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
if OPTIONS["oauth"]
|
29
|
+
switchboard.plug!(OAuthPubSubJack)
|
30
|
+
else
|
31
|
+
switchboard.plug!(PubSubJack)
|
32
|
+
end
|
33
|
+
switchboard.run!
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Switchboard
|
2
|
+
module Commands
|
3
|
+
class PubSub
|
4
|
+
class Config < Switchboard::Command
|
5
|
+
description "Gets the configuration for a pubsub node"
|
6
|
+
|
7
|
+
def self.run!
|
8
|
+
switchboard = Switchboard::Core.new do
|
9
|
+
defer :configuration_retrieved do
|
10
|
+
begin
|
11
|
+
if ARGV.length == 2
|
12
|
+
key, value = ARGV
|
13
|
+
puts "Setting '#{key}' to '#{value}'"
|
14
|
+
config = Jabber::PubSub::NodeConfig.new(OPTIONS["pubsub.node"], key => value)
|
15
|
+
set_config_for(OPTIONS["pubsub.node"], config)
|
16
|
+
end
|
17
|
+
|
18
|
+
get_config_from(OPTIONS["pubsub.node"])
|
19
|
+
rescue Jabber::ServerError => e
|
20
|
+
puts e
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def configuration_retrieved(config)
|
25
|
+
if config
|
26
|
+
puts "Configuration for node '#{config.node}':"
|
27
|
+
config.options.each do |k,v|
|
28
|
+
puts " " + [k, v] * ": "
|
29
|
+
end
|
30
|
+
else
|
31
|
+
puts "Could not load configuration for node '#{OPTIONS["pubsub.node"]}'."
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
if OPTIONS["oauth"]
|
37
|
+
switchboard.plug!(OAuthPubSubJack)
|
38
|
+
else
|
39
|
+
switchboard.plug!(PubSubJack)
|
40
|
+
end
|
41
|
+
switchboard.run!
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Switchboard
|
2
|
+
module Commands
|
3
|
+
class PubSub
|
4
|
+
class Create < Switchboard::Command
|
5
|
+
description "Creates a pubsub node"
|
6
|
+
|
7
|
+
def self.options(opts)
|
8
|
+
super(opts)
|
9
|
+
opts.on("--collection", "Specifies that a 'collection' node should be created.") { |v| OPTIONS["pubsub.create.node_type"] = "collection" }
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.run!
|
13
|
+
switchboard = Switchboard::Core.new do
|
14
|
+
defer :node_created do
|
15
|
+
begin
|
16
|
+
if OPTIONS["pubsub.create.node_type"] == "collection"
|
17
|
+
create_collection_node(OPTIONS["pubsub.node"])
|
18
|
+
else
|
19
|
+
create_node(OPTIONS["pubsub.node"])
|
20
|
+
end
|
21
|
+
rescue Jabber::ServerError => e
|
22
|
+
puts e
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def node_created(name)
|
27
|
+
if name
|
28
|
+
puts "Node '#{name}' was created."
|
29
|
+
else
|
30
|
+
puts "An auto-named node was created."
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
if OPTIONS["oauth"]
|
36
|
+
switchboard.plug!(OAuthPubSubJack)
|
37
|
+
else
|
38
|
+
switchboard.plug!(PubSubJack)
|
39
|
+
end
|
40
|
+
switchboard.run!
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Switchboard
|
2
|
+
module Commands
|
3
|
+
class PubSub
|
4
|
+
class Delete < Switchboard::Command
|
5
|
+
description "Deletes a pubsub node"
|
6
|
+
|
7
|
+
def self.run!
|
8
|
+
switchboard = Switchboard::Core.new do
|
9
|
+
defer :node_deleted do
|
10
|
+
begin
|
11
|
+
delete_node(OPTIONS["pubsub.node"])
|
12
|
+
rescue Jabber::ServerError => e
|
13
|
+
puts e
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def node_deleted(success)
|
18
|
+
if success
|
19
|
+
puts "Node '#{OPTIONS["pubsub.node"]}' was deleted."
|
20
|
+
else
|
21
|
+
puts "Node '#{OPTIONS["pubsub.node"]}' could not be deleted."
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
if OPTIONS["oauth"]
|
27
|
+
switchboard.plug!(OAuthPubSubJack)
|
28
|
+
else
|
29
|
+
switchboard.plug!(PubSubJack)
|
30
|
+
end
|
31
|
+
switchboard.run!
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module Switchboard
|
2
|
+
module Commands
|
3
|
+
class PubSub
|
4
|
+
class Info < Switchboard::Command
|
5
|
+
hide! # Jabber::PubSub::NodeBrowser is broken in xmpp4r-0.4.0
|
6
|
+
description "Gets information about a pubsub resource"
|
7
|
+
|
8
|
+
def self.run!
|
9
|
+
switchboard = Switchboard::Core.new do
|
10
|
+
defer :info_retrieved do
|
11
|
+
begin
|
12
|
+
browser = Jabber::PubSub::NodeBrowser.new(client)
|
13
|
+
browser.get_info(OPTIONS["pubsub.server"], OPTIONS["pubsub.node"])
|
14
|
+
rescue Jabber::ServerError => e
|
15
|
+
puts e
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def info_retrieved(info)
|
20
|
+
if info
|
21
|
+
if OPTIONS["pubsub.node"]
|
22
|
+
puts "Info for '#{OPTIONS["pubsub.node"]}' on '#{OPTIONS["pubsub.server"]}'"
|
23
|
+
else
|
24
|
+
puts "Info for '#{OPTIONS["pubsub.server"]}'"
|
25
|
+
end
|
26
|
+
info.each do |k,v|
|
27
|
+
if v.is_a?(Array)
|
28
|
+
puts " #{k}:"
|
29
|
+
v.each do |v2|
|
30
|
+
puts " #{v2}"
|
31
|
+
end
|
32
|
+
else
|
33
|
+
puts " #{k}: #{v}"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
else
|
37
|
+
puts "Info could not be loaded for '#{OPTIONS["pubsub.server"]}'"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
if OPTIONS["oauth"]
|
43
|
+
switchboard.plug!(OAuthPubSubJack)
|
44
|
+
else
|
45
|
+
switchboard.plug!(PubSubJack)
|
46
|
+
end
|
47
|
+
switchboard.run!
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Switchboard
|
2
|
+
module Commands
|
3
|
+
class PubSub
|
4
|
+
class Items < Switchboard::Command
|
5
|
+
description "Get items from a pubsub node"
|
6
|
+
|
7
|
+
def self.options(opts)
|
8
|
+
super(opts)
|
9
|
+
opts.on("--item-count=count", Integer, "Specifies the number of items to retrieve.") { |v| OPTIONS["pubsub.items.count"] = v }
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.run!
|
13
|
+
switchboard = Switchboard::Core.new do
|
14
|
+
defer :items_retrieved do
|
15
|
+
begin
|
16
|
+
get_items_from(OPTIONS["pubsub.node"], OPTIONS["pubsub.items.count"])
|
17
|
+
rescue Jabber::ServerError => e
|
18
|
+
puts e
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def items_retrieved(items)
|
23
|
+
if items && items.any?
|
24
|
+
puts "Items:"
|
25
|
+
items.each do |id, item|
|
26
|
+
puts [id, item] * ": "
|
27
|
+
end
|
28
|
+
else
|
29
|
+
puts "No items available for node '#{OPTIONS["pubsub.node"]}'."
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
if OPTIONS["oauth"]
|
35
|
+
switchboard.plug!(OAuthPubSubJack)
|
36
|
+
else
|
37
|
+
switchboard.plug!(PubSubJack)
|
38
|
+
end
|
39
|
+
switchboard.run!
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Switchboard
|
2
|
+
module Commands
|
3
|
+
class PubSub
|
4
|
+
class Listen < Switchboard::Command
|
5
|
+
description "Listens for pubsub events"
|
6
|
+
|
7
|
+
def self.run!
|
8
|
+
switchboard = Switchboard::Core.new
|
9
|
+
switchboard.plug!(PubSubJack)
|
10
|
+
|
11
|
+
switchboard.on_pubsub_event do |event|
|
12
|
+
puts event.to_s
|
13
|
+
end
|
14
|
+
|
15
|
+
switchboard.run!
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Switchboard
|
2
|
+
module Commands
|
3
|
+
class PubSub
|
4
|
+
class Nodes < Switchboard::Command
|
5
|
+
hide! # Jabber::PubSub::NodeBrowser is broken in xmpp4r-0.4.0
|
6
|
+
description "Lists available pubsub nodes (maybe use pubsub.<server>)"
|
7
|
+
|
8
|
+
def self.run!
|
9
|
+
switchboard = Switchboard::Core.new do
|
10
|
+
defer :nodes_retrieved do
|
11
|
+
begin
|
12
|
+
browser = Jabber::PubSub::NodeBrowser.new(client)
|
13
|
+
browser.nodes(OPTIONS["pubsub.server"])
|
14
|
+
rescue Jabber::ServerError => e
|
15
|
+
puts e
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def nodes_retrieved(nodes)
|
20
|
+
if nodes && nodes.compact! && nodes.any?
|
21
|
+
puts "Nodes available on '#{OPTIONS["pubsub.server"]}':"
|
22
|
+
nodes.each do |node|
|
23
|
+
puts " #{node.to_s}"
|
24
|
+
end
|
25
|
+
else
|
26
|
+
puts "No nodes are available on '#{OPTIONS["pubsub.server"]}'."
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
if OPTIONS["oauth"]
|
32
|
+
switchboard.plug!(OAuthPubSubJack)
|
33
|
+
else
|
34
|
+
switchboard.plug!(PubSubJack)
|
35
|
+
end
|
36
|
+
switchboard.run!
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Switchboard
|
2
|
+
module Commands
|
3
|
+
class PubSub
|
4
|
+
class Options < Switchboard::Command
|
5
|
+
description "Gets subscription options for a pubsub node"
|
6
|
+
|
7
|
+
def self.options(opts)
|
8
|
+
super(opts)
|
9
|
+
opts.on("--subscriber=jid", String, "Specifies the subscriber to retrieve options for.") { |v| OPTIONS["pubsub.subscriber"] = v }
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.run!
|
13
|
+
switchboard = Switchboard::Core.new do
|
14
|
+
defer :options_retrieved do
|
15
|
+
begin
|
16
|
+
get_options_from(OPTIONS["pubsub.node"], OPTIONS["pubsub.subscriber"] || OPTIONS["jid"])
|
17
|
+
rescue Jabber::ServerError => e
|
18
|
+
puts e
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def options_retrieved(options)
|
23
|
+
if options
|
24
|
+
puts "Options for subscription by '#{OPTIONS["pubsub.subscriber"] || OPTIONS["jid"]}' to node '#{options.node}':"
|
25
|
+
options.options.each do |k,v|
|
26
|
+
puts " " + [k, v] * ": "
|
27
|
+
end
|
28
|
+
else
|
29
|
+
puts "Could not load options for subscription by '#{OPTIONS["pubsub.subscriber"] || OPTIONS["jid"]}' to node '#{OPTIONS["pubsub.node"]}'."
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
if OPTIONS["oauth"]
|
35
|
+
switchboard.plug!(OAuthPubSubJack)
|
36
|
+
else
|
37
|
+
switchboard.plug!(PubSubJack)
|
38
|
+
end
|
39
|
+
switchboard.run!
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Switchboard
|
2
|
+
module Commands
|
3
|
+
class PubSub
|
4
|
+
class Publish < Switchboard::Command
|
5
|
+
description "Publish to a pubsub node"
|
6
|
+
|
7
|
+
def self.options(opts)
|
8
|
+
super(opts)
|
9
|
+
opts.on("--item-id=id", String, "Specifies the item id to use.") { |v| OPTIONS["pubsub.publish.id"] = v }
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.run!
|
13
|
+
switchboard = Switchboard::Core.new do
|
14
|
+
defer :item_published do
|
15
|
+
begin
|
16
|
+
item = Jabber::PubSub::Item.new
|
17
|
+
item.text = STDIN.read
|
18
|
+
if OPTIONS["pubsub.publish.id"]
|
19
|
+
publish_item_with_id_to(OPTIONS["pubsub.node"], item, OPTIONS["pubsub.publish.id"])
|
20
|
+
else
|
21
|
+
publish_item_to(OPTIONS["pubsub.node"], item)
|
22
|
+
end
|
23
|
+
rescue Jabber::ServerError => e
|
24
|
+
puts e
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def item_published(success)
|
29
|
+
if success
|
30
|
+
puts "Item was published."
|
31
|
+
else
|
32
|
+
puts "Item could not be published."
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
if OPTIONS["oauth"]
|
38
|
+
switchboard.plug!(OAuthPubSubJack)
|
39
|
+
else
|
40
|
+
switchboard.plug!(PubSubJack)
|
41
|
+
end
|
42
|
+
switchboard.run!
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -10,13 +10,12 @@ module Switchboard
|
|
10
10
|
def self.options(opts)
|
11
11
|
super(opts)
|
12
12
|
opts.on("--node=node", String, "Specifies the PubSub node to use.") { |v| OPTIONS["pubsub.node"] = v }
|
13
|
-
opts.on("--oauth", "Sign requests using OAuth.") { OPTIONS["oauth"] = true }
|
14
|
-
opts.on("--oauth-consumer-key=consumer-key", String, "Specifies the OAuth consumer key to use.") { |v| OPTIONS["oauth.consumer_key"] = v }
|
15
|
-
opts.on("--oauth-consumer-secret=consumer-secret", String, "Specifies the OAuth consumer secret to use.") { |v| OPTIONS["oauth.consumer_secret"] = v }
|
16
|
-
opts.on("--oauth-token=token", String, "Specifies the OAuth token to use.") { |v| OPTIONS["oauth.token"] = v }
|
17
|
-
opts.on("--oauth-token-secret=token-secret", String, "Specifies the OAuth token secret to use.") { |v| OPTIONS["oauth.token_secret"] = v }
|
18
|
-
opts.on("--node=node", String, "Specifies the PubSub node to use.") { |v| OPTIONS["pubsub.node"] = v }
|
19
13
|
opts.on("--server=server", String, "Specifies the PubSub server to use.") { |v| OPTIONS["pubsub.server"] = v }
|
14
|
+
opts.on("--oauth", "Sign requests using OAuth.") { OPTIONS["oauth"] = true }
|
15
|
+
opts.on("--oauth-consumer-key=key", String, "Specifies the OAuth consumer key to use.") { |v| OPTIONS["oauth.consumer_key"] = v }
|
16
|
+
opts.on("--oauth-consumer-secret=secret", String, "Specifies the OAuth consumer secret to use.") { |v| OPTIONS["oauth.consumer_secret"] = v }
|
17
|
+
opts.on("--oauth-token =oken", String, "Specifies the OAuth token to use.") { |v| OPTIONS["oauth.token"] = v }
|
18
|
+
opts.on("--oauth-token-secret=secret", String, "Specifies the OAuth token secret to use.") { |v| OPTIONS["oauth.token_secret"] = v }
|
20
19
|
end
|
21
20
|
end
|
22
21
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Switchboard
|
2
|
+
module Commands
|
3
|
+
class PubSub
|
4
|
+
class Purge < Switchboard::Command
|
5
|
+
description "Purges a pubsub node"
|
6
|
+
|
7
|
+
def self.run!
|
8
|
+
switchboard = Switchboard::Core.new do
|
9
|
+
defer :node_purged do
|
10
|
+
begin
|
11
|
+
purge_items_from(OPTIONS["pubsub.node"])
|
12
|
+
rescue Jabber::ServerError => e
|
13
|
+
puts e
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def node_purged(success)
|
18
|
+
if success
|
19
|
+
puts "Node '#{OPTIONS["pubsub.node"]}' was successfully purged."
|
20
|
+
else
|
21
|
+
puts "Could not purge node '#{OPTIONS["pubsub.node"]}'."
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
if OPTIONS["oauth"]
|
27
|
+
switchboard.plug!(OAuthPubSubJack)
|
28
|
+
else
|
29
|
+
switchboard.plug!(PubSubJack)
|
30
|
+
end
|
31
|
+
switchboard.run!
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -17,10 +17,10 @@ module Switchboard
|
|
17
17
|
|
18
18
|
# define here or as hydrant.subscriptions_received
|
19
19
|
def subscribed(subscription)
|
20
|
-
if subscription.subscription == :subscribed
|
20
|
+
if subscription && subscription.subscription == :subscribed
|
21
21
|
puts "Subscribe successful."
|
22
22
|
else
|
23
|
-
puts "Subscribe failed!"
|
23
|
+
puts "Subscribe failed!"
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
@@ -9,7 +9,7 @@ module Switchboard
|
|
9
9
|
# this executes in the main loop, so it doesn't really matter that this runs in a different thread
|
10
10
|
defer :subscriptions_received do
|
11
11
|
begin
|
12
|
-
subscriptions
|
12
|
+
subscriptions(settings["pubsub.node"])
|
13
13
|
rescue Jabber::ServerError => e
|
14
14
|
puts e
|
15
15
|
end
|
@@ -19,7 +19,7 @@ module Switchboard
|
|
19
19
|
def subscriptions_received(subscriptions)
|
20
20
|
if subscriptions && subscriptions.any?
|
21
21
|
puts "Subscriptions:"
|
22
|
-
puts subscriptions.collect { |subscription| "#{subscription.jid} => #{subscription.node}" } * "\n"
|
22
|
+
puts subscriptions.collect { |subscription| [subscription.subid, "#{subscription.jid || settings["jid"]} => #{subscription.node} (#{subscription.state})"].compact * ": " } * "\n"
|
23
23
|
else
|
24
24
|
puts "No subscriptions."
|
25
25
|
end
|
@@ -1,4 +1,15 @@
|
|
1
1
|
require 'switchboard/commands/pubsub/pubsub'
|
2
|
+
require 'switchboard/commands/pubsub/affiliations'
|
3
|
+
require 'switchboard/commands/pubsub/config'
|
4
|
+
require 'switchboard/commands/pubsub/create'
|
5
|
+
require 'switchboard/commands/pubsub/delete'
|
6
|
+
require 'switchboard/commands/pubsub/info'
|
7
|
+
require 'switchboard/commands/pubsub/items'
|
8
|
+
require 'switchboard/commands/pubsub/listen'
|
9
|
+
require 'switchboard/commands/pubsub/nodes'
|
10
|
+
require 'switchboard/commands/pubsub/options'
|
11
|
+
require 'switchboard/commands/pubsub/publish'
|
12
|
+
require 'switchboard/commands/pubsub/purge'
|
2
13
|
require 'switchboard/commands/pubsub/subscribe'
|
3
14
|
require 'switchboard/commands/pubsub/subscriptions'
|
4
15
|
require 'switchboard/commands/pubsub/unsubscribe'
|
@@ -4,6 +4,10 @@ module Switchboard
|
|
4
4
|
description "Register a JID"
|
5
5
|
|
6
6
|
class Registration < Switchboard::Core
|
7
|
+
def initialize(settings = Switchboard::Settings.new, spin = false)
|
8
|
+
super(settings, false)
|
9
|
+
end
|
10
|
+
|
7
11
|
protected
|
8
12
|
|
9
13
|
def auth!
|
@@ -16,7 +20,7 @@ module Switchboard
|
|
16
20
|
# TODO consider using client.register_info.inspect
|
17
21
|
begin
|
18
22
|
puts "Registering #{settings["jid"]} with password '#{settings["password"]}'."
|
19
|
-
|
23
|
+
iq = client.register(settings["password"])
|
20
24
|
rescue Jabber::ServerError => e
|
21
25
|
puts "Could not register: #{e}"
|
22
26
|
shutdown(false)
|
data/lib/switchboard/core.rb
CHANGED
@@ -9,7 +9,8 @@ end
|
|
9
9
|
# allow local library modifications/additions to be loaded
|
10
10
|
$: << File.join(File.dirname(__FILE__))
|
11
11
|
|
12
|
-
require 'switchboard/
|
12
|
+
require 'switchboard/ext/delegate'
|
13
|
+
require 'switchboard/ext/instance_exec'
|
13
14
|
require 'xmpp4r/roster'
|
14
15
|
|
15
16
|
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class Module
|
2
|
+
# Modified version from ActiveSupport to support :with (for additional arguments)
|
3
|
+
def delegate(*methods)
|
4
|
+
options = methods.pop
|
5
|
+
unless options.is_a?(Hash) && to = options[:to]
|
6
|
+
raise ArgumentError, "Delegation needs a target. Supply an options hash with a :to key as the last argument (e.g. delegate :hello, :to => :greeter)."
|
7
|
+
end
|
8
|
+
|
9
|
+
prefix = options[:prefix] && "#{options[:prefix] == true ? to : options[:prefix]}_"
|
10
|
+
with = options[:with] || []
|
11
|
+
|
12
|
+
methods.each do |method|
|
13
|
+
module_eval(<<-EOS, "(__DELEGATION__)", 1)
|
14
|
+
def #{prefix}#{method}(*args, &block)
|
15
|
+
args += [#{with * ", "}]
|
16
|
+
#{to}.__send__(#{method.inspect}, *args, &block)
|
17
|
+
end
|
18
|
+
EOS
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
File without changes
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
begin
|
3
|
+
require 'oauth'
|
4
|
+
rescue LoadError => e
|
5
|
+
gem = e.message.split("--").last.strip
|
6
|
+
puts "The #{gem} gem is required."
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'switchboard/helpers/pubsub'
|
10
|
+
require 'oauth/consumer'
|
11
|
+
require 'oauth/request_proxy/mock_request'
|
12
|
+
require 'xmpp4r/pubsub'
|
13
|
+
require 'xmpp4r/pubsub/helper/oauth_service_helper'
|
14
|
+
|
15
|
+
module Switchboard
|
16
|
+
module Helpers
|
17
|
+
module OAuthPubSubHelper
|
18
|
+
include PubSubHelper
|
19
|
+
|
20
|
+
attr_reader :oauth_consumer, :oauth_token
|
21
|
+
|
22
|
+
# TODO most/all of these need to be implemented in OAuthServiceHelper
|
23
|
+
delegate :create_node, :create_collection_node, :delete_node,
|
24
|
+
:get_config_from, :get_options_from, :get_items_from, :publish_item_to,
|
25
|
+
:publish_item_with_id_to, :purge_items_from, :set_config_for,
|
26
|
+
:subscribe_to, :unsubscribe_from, :to => :pubsub,
|
27
|
+
:with => [:oauth_consumer, :oauth_token]
|
28
|
+
|
29
|
+
def subscriptions(node = nil)
|
30
|
+
if node
|
31
|
+
# TODO this needs to be implemented in OAuthServiceHelper
|
32
|
+
pubsub.get_subscriptions_from(node, oauth_consumer, oauth_token)
|
33
|
+
else
|
34
|
+
pubsub.get_subscriptions_from_all_nodes(oauth_consumer, oauth_token)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'xmpp4r/pubsub'
|
2
|
+
# TODO this is broken in XMPP4R 0.4.0
|
3
|
+
# require 'xmpp4r/pubsub/helper/nodebrowser'
|
4
|
+
|
5
|
+
module PubSubHelper
|
6
|
+
attr_reader :pubsub
|
7
|
+
|
8
|
+
delegate :create_node, :create_collection_node, :delete_node,
|
9
|
+
:get_config_from, :get_options_from, :get_items_from, :publish_item_to,
|
10
|
+
:publish_item_with_id_to, :purge_items_from, :set_config_for,
|
11
|
+
:subscribe_to, :unsubscribe_from, :to => :pubsub
|
12
|
+
|
13
|
+
def on_pubsub_event(&block)
|
14
|
+
register_hook(:pubsub_event, &block)
|
15
|
+
end
|
16
|
+
|
17
|
+
def subscriptions(node = nil)
|
18
|
+
# NOTE: node-specific subscriptions do not appear to work in ejabberd 2.0.2
|
19
|
+
if node
|
20
|
+
pubsub.get_subscriptions_from(node)
|
21
|
+
else
|
22
|
+
pubsub.get_subscriptions_from_all_nodes
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -1,15 +1,4 @@
|
|
1
|
-
require '
|
2
|
-
begin
|
3
|
-
require 'oauth'
|
4
|
-
rescue LoadError => e
|
5
|
-
gem = e.message.split("--").last.strip
|
6
|
-
puts "The #{gem} gem is required."
|
7
|
-
end
|
8
|
-
|
9
|
-
require 'oauth/consumer'
|
10
|
-
require 'oauth/request_proxy/mock_request'
|
11
|
-
require 'xmpp4r/pubsub'
|
12
|
-
require 'xmpp4r/pubsub/helper/oauth_service_helper'
|
1
|
+
require 'switchboard/helpers/oauth_pubsub'
|
13
2
|
|
14
3
|
# TODO subclass PubSubJack
|
15
4
|
class OAuthPubSubJack
|
@@ -20,6 +9,8 @@ class OAuthPubSubJack
|
|
20
9
|
return false
|
21
10
|
end
|
22
11
|
|
12
|
+
switchboard.extend(Switchboard::Helpers::OAuthPubSubHelper)
|
13
|
+
|
23
14
|
switchboard.on_startup do
|
24
15
|
@pubsub = Jabber::PubSub::OAuthServiceHelper.new(client, settings["pubsub.server"])
|
25
16
|
|
@@ -30,38 +21,5 @@ class OAuthPubSubJack
|
|
30
21
|
on(:pubsub_event, event)
|
31
22
|
end
|
32
23
|
end
|
33
|
-
|
34
|
-
def switchboard.subscribe_to(node)
|
35
|
-
pubsub.subscribe_to(node, oauth_consumer, oauth_token)
|
36
|
-
end
|
37
|
-
|
38
|
-
def switchboard.subscriptions
|
39
|
-
pubsub.get_subscriptions_from_all_nodes(oauth_consumer, oauth_token)
|
40
|
-
end
|
41
|
-
|
42
|
-
def switchboard.unsubscribe_from(node)
|
43
|
-
pubsub.unsubscribe_from(node, oauth_consumer, oauth_token)
|
44
|
-
end
|
45
|
-
|
46
|
-
# TODO add the ability to define accessors
|
47
|
-
def switchboard.general_token
|
48
|
-
@general_token
|
49
|
-
end
|
50
|
-
|
51
|
-
def switchboard.oauth_consumer
|
52
|
-
@oauth_consumer
|
53
|
-
end
|
54
|
-
|
55
|
-
def switchboard.oauth_token
|
56
|
-
@oauth_token
|
57
|
-
end
|
58
|
-
|
59
|
-
def switchboard.pubsub
|
60
|
-
@pubsub
|
61
|
-
end
|
62
|
-
|
63
|
-
def switchboard.on_pubsub_event(&block)
|
64
|
-
register_hook(:pubsub_event, &block)
|
65
|
-
end
|
66
24
|
end
|
67
25
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'switchboard/helpers/pubsub'
|
2
2
|
|
3
3
|
class PubSubJack
|
4
4
|
def self.connect(switchboard, settings)
|
@@ -8,6 +8,8 @@ class PubSubJack
|
|
8
8
|
return false
|
9
9
|
end
|
10
10
|
|
11
|
+
switchboard.extend(Switchboard::Helpers::PubSubHelper)
|
12
|
+
|
11
13
|
switchboard.on_startup do
|
12
14
|
@pubsub = Jabber::PubSub::ServiceHelper.new(client, settings["pubsub.server"])
|
13
15
|
|
@@ -15,38 +17,5 @@ class PubSubJack
|
|
15
17
|
on(:pubsub_event, event)
|
16
18
|
end
|
17
19
|
end
|
18
|
-
|
19
|
-
def switchboard.subscribe_to(node)
|
20
|
-
pubsub.subscribe_to(node)
|
21
|
-
end
|
22
|
-
|
23
|
-
def switchboard.subscriptions
|
24
|
-
pubsub.get_subscriptions_from_all_nodes
|
25
|
-
end
|
26
|
-
|
27
|
-
def switchboard.unsubscribe_from(node)
|
28
|
-
pubsub.unsubscribe_from(node)
|
29
|
-
end
|
30
|
-
|
31
|
-
# TODO add the ability to define accessors
|
32
|
-
def switchboard.general_token
|
33
|
-
@general_token
|
34
|
-
end
|
35
|
-
|
36
|
-
def switchboard.oauth_consumer
|
37
|
-
@oauth_consumer
|
38
|
-
end
|
39
|
-
|
40
|
-
def switchboard.oauth_token
|
41
|
-
@oauth_token
|
42
|
-
end
|
43
|
-
|
44
|
-
def switchboard.pubsub
|
45
|
-
@pubsub
|
46
|
-
end
|
47
|
-
|
48
|
-
def switchboard.on_pubsub_event(&block)
|
49
|
-
register_hook(:pubsub_event, &block)
|
50
|
-
end
|
51
20
|
end
|
52
21
|
end
|
data/lib/switchboard/version.rb
CHANGED
data/switchboard.gemspec
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "switchboard"
|
3
|
-
s.version = "0.0.
|
3
|
+
s.version = "0.0.4"
|
4
4
|
s.summary = "XMPP toolkit."
|
5
5
|
s.description = "A toolkit for assembling XMPP clients and interacting with XMPP servers."
|
6
6
|
s.authors = ["Seth Fitzsimmons"]
|
7
7
|
s.email = ["seth@mojodna.net"]
|
8
8
|
|
9
|
-
s.files = ["bin/switchboard", "examples/election_results.rb", "lib/switchboard/colors.rb", "lib/switchboard/commands/command.rb", "lib/switchboard/commands/config/config.rb", "lib/switchboard/commands/config.rb", "lib/switchboard/commands/default.rb", "lib/switchboard/commands/help/help.rb", "lib/switchboard/commands/help.rb", "lib/switchboard/commands/pubsub/pubsub.rb", "lib/switchboard/commands/pubsub/subscribe.rb", "lib/switchboard/commands/pubsub/subscriptions.rb", "lib/switchboard/commands/pubsub/unsubscribe.rb", "lib/switchboard/commands/pubsub.rb", "lib/switchboard/commands/register.rb", "lib/switchboard/commands/roster/add.rb", "lib/switchboard/commands/roster/list.rb", "lib/switchboard/commands/roster/remove.rb", "lib/switchboard/commands/roster/roster.rb", "lib/switchboard/commands/roster.rb", "lib/switchboard/commands/unregister.rb", "lib/switchboard/commands.rb", "lib/switchboard/core.rb", "lib/switchboard/instance_exec.rb", "lib/switchboard/jacks/auto_accept.rb", "lib/switchboard/jacks/debug.rb", "lib/switchboard/jacks/notify.rb", "lib/switchboard/jacks/oauth_pubsub.rb", "lib/switchboard/jacks/pubsub.rb", "lib/switchboard/jacks/roster_debug.rb", "lib/switchboard/jacks.rb", "lib/switchboard/oauth/request_proxy/mock_request.rb", "lib/switchboard/settings.rb", "lib/switchboard/switchboard.rb", "lib/switchboard/version.rb", "lib/switchboard/xmpp4r/pubsub/helper/oauth_service_helper.rb", "lib/switchboard.rb", "README.markdown", "switchboard.gemspec"]
|
9
|
+
s.files = ["bin/switchboard", "examples/election_results.rb", "lib/switchboard/colors.rb", "lib/switchboard/commands/command.rb", "lib/switchboard/commands/config/config.rb", "lib/switchboard/commands/config.rb", "lib/switchboard/commands/default.rb", "lib/switchboard/commands/help/help.rb", "lib/switchboard/commands/help.rb", "lib/switchboard/commands/pubsub/affiliations.rb", "lib/switchboard/commands/pubsub/config.rb", "lib/switchboard/commands/pubsub/create.rb", "lib/switchboard/commands/pubsub/delete.rb", "lib/switchboard/commands/pubsub/info.rb", "lib/switchboard/commands/pubsub/items.rb", "lib/switchboard/commands/pubsub/listen.rb", "lib/switchboard/commands/pubsub/nodes.rb", "lib/switchboard/commands/pubsub/options.rb", "lib/switchboard/commands/pubsub/publish.rb", "lib/switchboard/commands/pubsub/pubsub.rb", "lib/switchboard/commands/pubsub/purge.rb", "lib/switchboard/commands/pubsub/subscribe.rb", "lib/switchboard/commands/pubsub/subscriptions.rb", "lib/switchboard/commands/pubsub/unsubscribe.rb", "lib/switchboard/commands/pubsub.rb", "lib/switchboard/commands/register.rb", "lib/switchboard/commands/roster/add.rb", "lib/switchboard/commands/roster/list.rb", "lib/switchboard/commands/roster/remove.rb", "lib/switchboard/commands/roster/roster.rb", "lib/switchboard/commands/roster.rb", "lib/switchboard/commands/unregister.rb", "lib/switchboard/commands.rb", "lib/switchboard/core.rb", "lib/switchboard/ext/delegate.rb", "lib/switchboard/ext/instance_exec.rb", "lib/switchboard/helpers/oauth_pubsub.rb", "lib/switchboard/helpers/pubsub.rb", "lib/switchboard/jacks/auto_accept.rb", "lib/switchboard/jacks/debug.rb", "lib/switchboard/jacks/notify.rb", "lib/switchboard/jacks/oauth_pubsub.rb", "lib/switchboard/jacks/pubsub.rb", "lib/switchboard/jacks/roster_debug.rb", "lib/switchboard/jacks.rb", "lib/switchboard/oauth/request_proxy/mock_request.rb", "lib/switchboard/settings.rb", "lib/switchboard/switchboard.rb", "lib/switchboard/version.rb", "lib/switchboard/xmpp4r/pubsub/helper/oauth_service_helper.rb", "lib/switchboard.rb", "Rakefile", "README.markdown", "switchboard.gemspec"]
|
10
10
|
s.executables = ["switchboard"]
|
11
11
|
s.require_paths = ["lib"]
|
12
12
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mojodna-switchboard
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Seth Fitzsimmons
|
@@ -40,7 +40,18 @@ files:
|
|
40
40
|
- lib/switchboard/commands/default.rb
|
41
41
|
- lib/switchboard/commands/help/help.rb
|
42
42
|
- lib/switchboard/commands/help.rb
|
43
|
+
- lib/switchboard/commands/pubsub/affiliations.rb
|
44
|
+
- lib/switchboard/commands/pubsub/config.rb
|
45
|
+
- lib/switchboard/commands/pubsub/create.rb
|
46
|
+
- lib/switchboard/commands/pubsub/delete.rb
|
47
|
+
- lib/switchboard/commands/pubsub/info.rb
|
48
|
+
- lib/switchboard/commands/pubsub/items.rb
|
49
|
+
- lib/switchboard/commands/pubsub/listen.rb
|
50
|
+
- lib/switchboard/commands/pubsub/nodes.rb
|
51
|
+
- lib/switchboard/commands/pubsub/options.rb
|
52
|
+
- lib/switchboard/commands/pubsub/publish.rb
|
43
53
|
- lib/switchboard/commands/pubsub/pubsub.rb
|
54
|
+
- lib/switchboard/commands/pubsub/purge.rb
|
44
55
|
- lib/switchboard/commands/pubsub/subscribe.rb
|
45
56
|
- lib/switchboard/commands/pubsub/subscriptions.rb
|
46
57
|
- lib/switchboard/commands/pubsub/unsubscribe.rb
|
@@ -54,7 +65,10 @@ files:
|
|
54
65
|
- lib/switchboard/commands/unregister.rb
|
55
66
|
- lib/switchboard/commands.rb
|
56
67
|
- lib/switchboard/core.rb
|
57
|
-
- lib/switchboard/
|
68
|
+
- lib/switchboard/ext/delegate.rb
|
69
|
+
- lib/switchboard/ext/instance_exec.rb
|
70
|
+
- lib/switchboard/helpers/oauth_pubsub.rb
|
71
|
+
- lib/switchboard/helpers/pubsub.rb
|
58
72
|
- lib/switchboard/jacks/auto_accept.rb
|
59
73
|
- lib/switchboard/jacks/debug.rb
|
60
74
|
- lib/switchboard/jacks/notify.rb
|
@@ -68,6 +82,7 @@ files:
|
|
68
82
|
- lib/switchboard/version.rb
|
69
83
|
- lib/switchboard/xmpp4r/pubsub/helper/oauth_service_helper.rb
|
70
84
|
- lib/switchboard.rb
|
85
|
+
- Rakefile
|
71
86
|
- README.markdown
|
72
87
|
- switchboard.gemspec
|
73
88
|
has_rdoc: false
|