mojodna-switchboard 0.0.2 → 0.0.3
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/lib/switchboard/commands/default.rb +2 -1
- data/lib/switchboard/commands/pubsub/pubsub.rb +8 -1
- data/lib/switchboard/commands/pubsub/subscribe.rb +6 -3
- data/lib/switchboard/commands/pubsub/subscriptions.rb +12 -5
- data/lib/switchboard/commands/pubsub/unsubscribe.rb +6 -3
- data/lib/switchboard/commands/register.rb +36 -0
- data/lib/switchboard/commands/unregister.rb +21 -0
- data/lib/switchboard/commands.rb +3 -1
- data/lib/switchboard/core.rb +10 -2
- data/lib/switchboard/jacks/oauth_pubsub.rb +13 -2
- data/lib/switchboard/jacks/pubsub.rb +12 -0
- data/lib/switchboard/settings.rb +9 -1
- data/lib/switchboard/version.rb +1 -1
- data/switchboard.gemspec +3 -3
- metadata +4 -18
@@ -18,7 +18,8 @@ module Switchboard
|
|
18
18
|
opts.banner = "Usage: #{opts.program_name} [options] COMMAND [options] [args]"
|
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("-p", "--password=password", String, "Specifies the password to use.") { |v| OPTIONS["password"] = v }
|
22
23
|
# opts.on("-p", "--pidfile=path", String,
|
23
24
|
# "Specifies a pidfile to use.") { |v| OPTIONS[:pidfile] = v }
|
24
25
|
# opts.on("-v", "--[no-]verbose", "Run verbosely") { |v| OPTIONS[:verbose] = v }
|
@@ -9,7 +9,14 @@ module Switchboard
|
|
9
9
|
|
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
|
+
opts.on("--server=server", String, "Specifies the PubSub server to use.") { |v| OPTIONS["pubsub.server"] = v }
|
13
20
|
end
|
14
21
|
end
|
15
22
|
end
|
@@ -5,12 +5,11 @@ module Switchboard
|
|
5
5
|
description "Subscribe to a pubsub node"
|
6
6
|
|
7
7
|
def self.run!
|
8
|
-
# TODO override settings with values from the command line
|
9
8
|
switchboard = Switchboard::Core.new do
|
10
9
|
# this executes in the main loop, so it doesn't really matter that this runs in a different thread
|
11
10
|
defer :subscribed do
|
12
11
|
begin
|
13
|
-
|
12
|
+
subscribe_to(settings["pubsub.node"])
|
14
13
|
rescue Jabber::ServerError => e
|
15
14
|
puts e
|
16
15
|
end
|
@@ -26,7 +25,11 @@ module Switchboard
|
|
26
25
|
end
|
27
26
|
end
|
28
27
|
|
29
|
-
|
28
|
+
if OPTIONS["oauth"]
|
29
|
+
switchboard.plug!(OAuthPubSubJack)
|
30
|
+
else
|
31
|
+
switchboard.plug!(PubSubJack)
|
32
|
+
end
|
30
33
|
switchboard.run!
|
31
34
|
end
|
32
35
|
end
|
@@ -5,12 +5,11 @@ module Switchboard
|
|
5
5
|
description "List pubsub subscriptions"
|
6
6
|
|
7
7
|
def self.run!
|
8
|
-
# TODO override settings with values from the command line
|
9
8
|
switchboard = Switchboard::Core.new do
|
10
9
|
# this executes in the main loop, so it doesn't really matter that this runs in a different thread
|
11
10
|
defer :subscriptions_received do
|
12
11
|
begin
|
13
|
-
|
12
|
+
subscriptions
|
14
13
|
rescue Jabber::ServerError => e
|
15
14
|
puts e
|
16
15
|
end
|
@@ -18,12 +17,20 @@ module Switchboard
|
|
18
17
|
|
19
18
|
# define here or as hydrant.subscriptions_received
|
20
19
|
def subscriptions_received(subscriptions)
|
21
|
-
|
22
|
-
|
20
|
+
if subscriptions && subscriptions.any?
|
21
|
+
puts "Subscriptions:"
|
22
|
+
puts subscriptions.collect { |subscription| "#{subscription.jid} => #{subscription.node}" } * "\n"
|
23
|
+
else
|
24
|
+
puts "No subscriptions."
|
25
|
+
end
|
23
26
|
end
|
24
27
|
end
|
25
28
|
|
26
|
-
|
29
|
+
if OPTIONS["oauth"]
|
30
|
+
switchboard.plug!(OAuthPubSubJack)
|
31
|
+
else
|
32
|
+
switchboard.plug!(PubSubJack)
|
33
|
+
end
|
27
34
|
switchboard.run!
|
28
35
|
end
|
29
36
|
end
|
@@ -5,12 +5,11 @@ module Switchboard
|
|
5
5
|
description "Unsubscribe from a pubsub node"
|
6
6
|
|
7
7
|
def self.run!
|
8
|
-
# TODO override settings with values from the command line
|
9
8
|
switchboard = Switchboard::Core.new do
|
10
9
|
# this executes in the main loop, so it doesn't really matter that this runs in a different thread
|
11
10
|
defer :unsubscribed do
|
12
11
|
begin
|
13
|
-
|
12
|
+
unsubscribe_from(settings["pubsub.node"])
|
14
13
|
rescue Jabber::ServerError => e
|
15
14
|
puts e
|
16
15
|
end
|
@@ -22,7 +21,11 @@ module Switchboard
|
|
22
21
|
end
|
23
22
|
end
|
24
23
|
|
25
|
-
|
24
|
+
if OPTIONS["oauth"]
|
25
|
+
switchboard.plug!(OAuthPubSubJack)
|
26
|
+
else
|
27
|
+
switchboard.plug!(PubSubJack)
|
28
|
+
end
|
26
29
|
switchboard.run!
|
27
30
|
end
|
28
31
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Switchboard
|
2
|
+
module Commands
|
3
|
+
class Register < Switchboard::Command
|
4
|
+
description "Register a JID"
|
5
|
+
|
6
|
+
class Registration < Switchboard::Core
|
7
|
+
protected
|
8
|
+
|
9
|
+
def auth!
|
10
|
+
unless settings["jid"] && settings["password"]
|
11
|
+
puts "A JID and password are required to register a new account."
|
12
|
+
shutdown(false)
|
13
|
+
exit
|
14
|
+
end
|
15
|
+
|
16
|
+
# TODO consider using client.register_info.inspect
|
17
|
+
begin
|
18
|
+
puts "Registering #{settings["jid"]} with password '#{settings["password"]}'."
|
19
|
+
puts client.register(settings["password"])
|
20
|
+
rescue Jabber::ServerError => e
|
21
|
+
puts "Could not register: #{e}"
|
22
|
+
shutdown(false)
|
23
|
+
exit 1
|
24
|
+
end
|
25
|
+
|
26
|
+
# now log in
|
27
|
+
super
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.run!
|
32
|
+
Registration.new.run!
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Switchboard
|
2
|
+
module Commands
|
3
|
+
class Unregister < Switchboard::Command
|
4
|
+
description "Unregister a JID"
|
5
|
+
|
6
|
+
def self.run!
|
7
|
+
switchboard = Switchboard::Core.new do
|
8
|
+
begin
|
9
|
+
client.remove_registration
|
10
|
+
rescue Jabber::ServerError => e
|
11
|
+
puts "Could not unregister #{settings["jid"]}: #{e}"
|
12
|
+
shutdown(false)
|
13
|
+
exit 1
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
switchboard.run!
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/switchboard/commands.rb
CHANGED
@@ -3,4 +3,6 @@ require 'switchboard/commands/config'
|
|
3
3
|
require 'switchboard/commands/default'
|
4
4
|
require 'switchboard/commands/help'
|
5
5
|
require 'switchboard/commands/pubsub'
|
6
|
-
require 'switchboard/commands/
|
6
|
+
require 'switchboard/commands/register'
|
7
|
+
require 'switchboard/commands/roster'
|
8
|
+
require 'switchboard/commands/unregister'
|
data/lib/switchboard/core.rb
CHANGED
@@ -157,10 +157,18 @@ module Switchboard
|
|
157
157
|
|
158
158
|
protected
|
159
159
|
|
160
|
-
def
|
161
|
-
client.connect
|
160
|
+
def auth!
|
162
161
|
client.auth(settings["password"])
|
163
162
|
@roster = Jabber::Roster::Helper.new(client)
|
163
|
+
rescue Jabber::ClientAuthenticationFailure => e
|
164
|
+
puts "Could not authenticate as #{settings["jid"]}"
|
165
|
+
shutdown(false)
|
166
|
+
exit 1
|
167
|
+
end
|
168
|
+
|
169
|
+
def connect!
|
170
|
+
client.connect
|
171
|
+
auth!
|
164
172
|
end
|
165
173
|
|
166
174
|
def connected?
|
@@ -11,6 +11,7 @@ require 'oauth/request_proxy/mock_request'
|
|
11
11
|
require 'xmpp4r/pubsub'
|
12
12
|
require 'xmpp4r/pubsub/helper/oauth_service_helper'
|
13
13
|
|
14
|
+
# TODO subclass PubSubJack
|
14
15
|
class OAuthPubSubJack
|
15
16
|
def self.connect(switchboard, settings)
|
16
17
|
# TODO generalize this pattern for required settings
|
@@ -24,14 +25,24 @@ class OAuthPubSubJack
|
|
24
25
|
|
25
26
|
@oauth_consumer = OAuth::Consumer.new(settings["oauth.consumer_key"], settings["oauth.consumer_secret"])
|
26
27
|
@oauth_token = OAuth::Token.new(settings["oauth.token"], settings["oauth.token_secret"])
|
27
|
-
# this is Fire Eagle-specific
|
28
|
-
@general_token = OAuth::Token.new(settings["oauth.general_token"], settings["oauth.general_token_secret"])
|
29
28
|
|
30
29
|
@pubsub.add_event_callback do |event|
|
31
30
|
on(:pubsub_event, event)
|
32
31
|
end
|
33
32
|
end
|
34
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
|
+
|
35
46
|
# TODO add the ability to define accessors
|
36
47
|
def switchboard.general_token
|
37
48
|
@general_token
|
@@ -16,6 +16,18 @@ class PubSubJack
|
|
16
16
|
end
|
17
17
|
end
|
18
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
|
+
|
19
31
|
# TODO add the ability to define accessors
|
20
32
|
def switchboard.general_token
|
21
33
|
@general_token
|
data/lib/switchboard/settings.rb
CHANGED
@@ -19,10 +19,18 @@ module Switchboard
|
|
19
19
|
alias_method :[], :get
|
20
20
|
|
21
21
|
def set!(key, value)
|
22
|
-
|
22
|
+
set(key, value)
|
23
23
|
write
|
24
24
|
end
|
25
25
|
|
26
|
+
def set(key, value)
|
27
|
+
@config[key] = value
|
28
|
+
end
|
29
|
+
|
30
|
+
def []=(key, value)
|
31
|
+
set(key, value)
|
32
|
+
end
|
33
|
+
|
26
34
|
def write
|
27
35
|
open(@path, "w") do |f|
|
28
36
|
f << @config.to_yaml
|
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.
|
4
|
-
s.summary = "XMPP toolkit"
|
3
|
+
s.version = "0.0.3"
|
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
|
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"]
|
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.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Seth Fitzsimmons
|
@@ -31,38 +31,30 @@ extensions: []
|
|
31
31
|
extra_rdoc_files: []
|
32
32
|
|
33
33
|
files:
|
34
|
-
- bin
|
35
34
|
- bin/switchboard
|
36
35
|
- examples/election_results.rb
|
37
|
-
- github-test.rb
|
38
|
-
- lib
|
39
|
-
- lib/switchboard
|
40
36
|
- lib/switchboard/colors.rb
|
41
|
-
- lib/switchboard/commands
|
42
37
|
- lib/switchboard/commands/command.rb
|
43
|
-
- lib/switchboard/commands/config
|
44
38
|
- lib/switchboard/commands/config/config.rb
|
45
39
|
- lib/switchboard/commands/config.rb
|
46
40
|
- lib/switchboard/commands/default.rb
|
47
|
-
- lib/switchboard/commands/help
|
48
41
|
- lib/switchboard/commands/help/help.rb
|
49
42
|
- lib/switchboard/commands/help.rb
|
50
|
-
- lib/switchboard/commands/pubsub
|
51
43
|
- lib/switchboard/commands/pubsub/pubsub.rb
|
52
44
|
- lib/switchboard/commands/pubsub/subscribe.rb
|
53
45
|
- lib/switchboard/commands/pubsub/subscriptions.rb
|
54
46
|
- lib/switchboard/commands/pubsub/unsubscribe.rb
|
55
47
|
- lib/switchboard/commands/pubsub.rb
|
56
|
-
- lib/switchboard/commands/
|
48
|
+
- lib/switchboard/commands/register.rb
|
57
49
|
- lib/switchboard/commands/roster/add.rb
|
58
50
|
- lib/switchboard/commands/roster/list.rb
|
59
51
|
- lib/switchboard/commands/roster/remove.rb
|
60
52
|
- lib/switchboard/commands/roster/roster.rb
|
61
53
|
- lib/switchboard/commands/roster.rb
|
54
|
+
- lib/switchboard/commands/unregister.rb
|
62
55
|
- lib/switchboard/commands.rb
|
63
56
|
- lib/switchboard/core.rb
|
64
57
|
- lib/switchboard/instance_exec.rb
|
65
|
-
- lib/switchboard/jacks
|
66
58
|
- lib/switchboard/jacks/auto_accept.rb
|
67
59
|
- lib/switchboard/jacks/debug.rb
|
68
60
|
- lib/switchboard/jacks/notify.rb
|
@@ -70,19 +62,13 @@ files:
|
|
70
62
|
- lib/switchboard/jacks/pubsub.rb
|
71
63
|
- lib/switchboard/jacks/roster_debug.rb
|
72
64
|
- lib/switchboard/jacks.rb
|
73
|
-
- lib/switchboard/oauth
|
74
|
-
- lib/switchboard/oauth/request_proxy
|
75
65
|
- lib/switchboard/oauth/request_proxy/mock_request.rb
|
76
66
|
- lib/switchboard/settings.rb
|
77
67
|
- lib/switchboard/switchboard.rb
|
78
68
|
- lib/switchboard/version.rb
|
79
|
-
- lib/switchboard/xmpp4r
|
80
|
-
- lib/switchboard/xmpp4r/pubsub
|
81
|
-
- lib/switchboard/xmpp4r/pubsub/helper
|
82
69
|
- lib/switchboard/xmpp4r/pubsub/helper/oauth_service_helper.rb
|
83
70
|
- lib/switchboard.rb
|
84
71
|
- README.markdown
|
85
|
-
- switchboard-0.0.1.gem
|
86
72
|
- switchboard.gemspec
|
87
73
|
has_rdoc: false
|
88
74
|
homepage:
|
@@ -109,6 +95,6 @@ rubyforge_project:
|
|
109
95
|
rubygems_version: 1.2.0
|
110
96
|
signing_key:
|
111
97
|
specification_version: 2
|
112
|
-
summary: XMPP toolkit
|
98
|
+
summary: XMPP toolkit.
|
113
99
|
test_files: []
|
114
100
|
|