switchboard 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. data/History.txt +3 -0
  2. data/README.markdown +59 -0
  3. data/Rakefile +30 -0
  4. data/bin/switchboard +35 -0
  5. data/examples/echo_bot.rb +7 -0
  6. data/lib/switchboard.rb +1 -0
  7. data/lib/switchboard/client.rb +92 -0
  8. data/lib/switchboard/colors.rb +10 -0
  9. data/lib/switchboard/commands.rb +12 -0
  10. data/lib/switchboard/commands/command.rb +85 -0
  11. data/lib/switchboard/commands/config.rb +1 -0
  12. data/lib/switchboard/commands/config/config.rb +20 -0
  13. data/lib/switchboard/commands/default.rb +40 -0
  14. data/lib/switchboard/commands/disco.rb +3 -0
  15. data/lib/switchboard/commands/disco/disco.rb +13 -0
  16. data/lib/switchboard/commands/disco/info.rb +39 -0
  17. data/lib/switchboard/commands/disco/items.rb +30 -0
  18. data/lib/switchboard/commands/grep.rb +23 -0
  19. data/lib/switchboard/commands/help.rb +1 -0
  20. data/lib/switchboard/commands/help/help.rb +15 -0
  21. data/lib/switchboard/commands/last.rb +1 -0
  22. data/lib/switchboard/commands/last/last.rb +34 -0
  23. data/lib/switchboard/commands/pep.rb +3 -0
  24. data/lib/switchboard/commands/pep/location.rb +97 -0
  25. data/lib/switchboard/commands/pep/pep.rb +7 -0
  26. data/lib/switchboard/commands/pep/tune.rb +85 -0
  27. data/lib/switchboard/commands/pubsub.rb +16 -0
  28. data/lib/switchboard/commands/pubsub/affiliations.rb +34 -0
  29. data/lib/switchboard/commands/pubsub/config.rb +42 -0
  30. data/lib/switchboard/commands/pubsub/create.rb +41 -0
  31. data/lib/switchboard/commands/pubsub/delete.rb +32 -0
  32. data/lib/switchboard/commands/pubsub/info.rb +48 -0
  33. data/lib/switchboard/commands/pubsub/items.rb +40 -0
  34. data/lib/switchboard/commands/pubsub/listen.rb +20 -0
  35. data/lib/switchboard/commands/pubsub/nodes.rb +37 -0
  36. data/lib/switchboard/commands/pubsub/options.rb +40 -0
  37. data/lib/switchboard/commands/pubsub/publish.rb +44 -0
  38. data/lib/switchboard/commands/pubsub/pubsub.rb +25 -0
  39. data/lib/switchboard/commands/pubsub/purge.rb +32 -0
  40. data/lib/switchboard/commands/pubsub/retract.rb +38 -0
  41. data/lib/switchboard/commands/pubsub/subscribe.rb +34 -0
  42. data/lib/switchboard/commands/pubsub/subscriptions.rb +35 -0
  43. data/lib/switchboard/commands/pubsub/unsubscribe.rb +30 -0
  44. data/lib/switchboard/commands/register.rb +40 -0
  45. data/lib/switchboard/commands/roster.rb +5 -0
  46. data/lib/switchboard/commands/roster/add.rb +27 -0
  47. data/lib/switchboard/commands/roster/list.rb +26 -0
  48. data/lib/switchboard/commands/roster/online.rb +28 -0
  49. data/lib/switchboard/commands/roster/remove.rb +25 -0
  50. data/lib/switchboard/commands/roster/roster.rb +7 -0
  51. data/lib/switchboard/commands/unregister.rb +21 -0
  52. data/lib/switchboard/component.rb +36 -0
  53. data/lib/switchboard/core.rb +311 -0
  54. data/lib/switchboard/ext/delegate.rb +21 -0
  55. data/lib/switchboard/ext/instance_exec.rb +16 -0
  56. data/lib/switchboard/helpers/oauth_pubsub.rb +44 -0
  57. data/lib/switchboard/helpers/pubsub.rb +28 -0
  58. data/lib/switchboard/jacks.rb +7 -0
  59. data/lib/switchboard/jacks/auto_accept.rb +16 -0
  60. data/lib/switchboard/jacks/debug.rb +17 -0
  61. data/lib/switchboard/jacks/echo.rb +7 -0
  62. data/lib/switchboard/jacks/notify.rb +15 -0
  63. data/lib/switchboard/jacks/oauth_pubsub.rb +23 -0
  64. data/lib/switchboard/jacks/pubsub.rb +21 -0
  65. data/lib/switchboard/jacks/roster_debug.rb +23 -0
  66. data/lib/switchboard/settings.rb +49 -0
  67. data/lib/switchboard/switchboard.rb +12 -0
  68. data/lib/switchboard/version.rb +3 -0
  69. data/switchboard.gemspec +15 -0
  70. metadata +136 -0
@@ -0,0 +1,32 @@
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::Client.new do
9
+ defer :node_deleted do
10
+ delete_node(OPTIONS["pubsub.node"])
11
+ end
12
+
13
+ def node_deleted(success)
14
+ if success
15
+ puts "Node '#{OPTIONS["pubsub.node"]}' was deleted."
16
+ else
17
+ puts "Node '#{OPTIONS["pubsub.node"]}' could not be deleted."
18
+ end
19
+ end
20
+ end
21
+
22
+ if defined?(OAuth) && OPTIONS["oauth"]
23
+ switchboard.plug!(OAuthPubSubJack)
24
+ else
25
+ switchboard.plug!(PubSubJack)
26
+ end
27
+ switchboard.run!
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,48 @@
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::Client.new do
10
+ defer :info_retrieved do
11
+ browser = Jabber::PubSub::NodeBrowser.new(client)
12
+ browser.get_info(OPTIONS["pubsub.server"], OPTIONS["pubsub.node"])
13
+ end
14
+
15
+ def info_retrieved(info)
16
+ if info
17
+ if OPTIONS["pubsub.node"]
18
+ puts "Info for '#{OPTIONS["pubsub.node"]}' on '#{OPTIONS["pubsub.server"]}'"
19
+ else
20
+ puts "Info for '#{OPTIONS["pubsub.server"]}'"
21
+ end
22
+ info.each do |k,v|
23
+ if v.is_a?(Array)
24
+ puts " #{k}:"
25
+ v.each do |v2|
26
+ puts " #{v2}"
27
+ end
28
+ else
29
+ puts " #{k}: #{v}"
30
+ end
31
+ end
32
+ else
33
+ puts "Info could not be loaded for '#{OPTIONS["pubsub.server"]}'"
34
+ end
35
+ end
36
+ end
37
+
38
+ if defined?(OAuth) && OPTIONS["oauth"]
39
+ switchboard.plug!(OAuthPubSubJack)
40
+ else
41
+ switchboard.plug!(PubSubJack)
42
+ end
43
+ switchboard.run!
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,40 @@
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::Client.new do
14
+ defer :items_retrieved do
15
+ get_items_from(OPTIONS["pubsub.node"], OPTIONS["pubsub.items.count"])
16
+ end
17
+
18
+ def items_retrieved(items)
19
+ if items && items.any?
20
+ puts "Items:"
21
+ items.each do |id, item|
22
+ puts [id, item].compact * ": "
23
+ end
24
+ else
25
+ puts "No items available for node '#{OPTIONS["pubsub.node"]}'."
26
+ end
27
+ end
28
+ end
29
+
30
+ if defined?(OAuth) && OPTIONS["oauth"]
31
+ switchboard.plug!(OAuthPubSubJack)
32
+ else
33
+ switchboard.plug!(PubSubJack)
34
+ end
35
+ switchboard.run!
36
+ end
37
+ end
38
+ end
39
+ end
40
+ 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::Client.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,37 @@
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::Client.new do
10
+ defer :nodes_retrieved do
11
+ browser = Jabber::PubSub::NodeBrowser.new(client)
12
+ browser.nodes(OPTIONS["pubsub.server"])
13
+ end
14
+
15
+ def nodes_retrieved(nodes)
16
+ if nodes && nodes.compact! && nodes.any?
17
+ puts "Nodes available on '#{OPTIONS["pubsub.server"]}':"
18
+ nodes.each do |node|
19
+ puts " #{node.to_s}"
20
+ end
21
+ else
22
+ puts "No nodes are available on '#{OPTIONS["pubsub.server"]}'."
23
+ end
24
+ end
25
+ end
26
+
27
+ if defined?(OAuth) && OPTIONS["oauth"]
28
+ switchboard.plug!(OAuthPubSubJack)
29
+ else
30
+ switchboard.plug!(PubSubJack)
31
+ end
32
+ switchboard.run!
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,40 @@
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::Client.new do
14
+ defer :options_retrieved do
15
+ get_options_from(OPTIONS["pubsub.node"], OPTIONS["pubsub.subscriber"] || OPTIONS["jid"])
16
+ end
17
+
18
+ def options_retrieved(options)
19
+ if options
20
+ puts "Options for subscription by '#{OPTIONS["pubsub.subscriber"] || OPTIONS["jid"]}' to node '#{options.node}':"
21
+ options.options.each do |k,v|
22
+ puts " " + [k, v] * ": "
23
+ end
24
+ else
25
+ puts "Could not load options for subscription by '#{OPTIONS["pubsub.subscriber"] || OPTIONS["jid"]}' to node '#{OPTIONS["pubsub.node"]}'."
26
+ end
27
+ end
28
+ end
29
+
30
+ if defined?(OAuth) && OPTIONS["oauth"]
31
+ switchboard.plug!(OAuthPubSubJack)
32
+ else
33
+ switchboard.plug!(PubSubJack)
34
+ end
35
+ switchboard.run!
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,44 @@
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::Client.new do
14
+ defer :item_published do
15
+ item = Jabber::PubSub::Item.new
16
+ item.text = STDIN.read
17
+ if OPTIONS["pubsub.publish.id"]
18
+ publish_item_with_id_to(OPTIONS["pubsub.node"], item, OPTIONS["pubsub.publish.id"])
19
+ else
20
+ publish_item_to(OPTIONS["pubsub.node"], item)
21
+ end
22
+ end
23
+
24
+ def item_published(success)
25
+ # puts "Result: #{success.to_s}"
26
+ if success
27
+ puts "Item was published." # TODO include id
28
+ else
29
+ puts "Item could not be published."
30
+ end
31
+ end
32
+ end
33
+
34
+ if defined?(OAuth) && 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,25 @@
1
+ module Switchboard
2
+ module Commands
3
+ class PubSub < Switchboard::Command
4
+ description "Pubsub node manipulation"
5
+
6
+ def self.help
7
+ "These are the more extensive instructions for using the pubsub command."
8
+ end
9
+
10
+ def self.options(opts)
11
+ super(opts)
12
+ opts.on("--node=node", String, "Specifies the PubSub node to use.") { |v| OPTIONS["pubsub.node"] = v }
13
+ opts.on("--server=server", String, "Specifies the PubSub server to use.") { |v| OPTIONS["pubsub.server"] = v }
14
+ if defined?(OAuth)
15
+ opts.on("--oauth", "Sign requests using OAuth.") { OPTIONS["oauth"] = true }
16
+ opts.on("--oauth-consumer-key=key", String, "Specifies the OAuth consumer key to use.") { |v| OPTIONS["oauth.consumer_key"] = v }
17
+ opts.on("--oauth-consumer-secret=secret", String, "Specifies the OAuth consumer secret to use.") { |v| OPTIONS["oauth.consumer_secret"] = v }
18
+ opts.on("--oauth-token=token", String, "Specifies the OAuth token to use.") { |v| OPTIONS["oauth.token"] = v }
19
+ opts.on("--oauth-token-secret=secret", String, "Specifies the OAuth token secret to use.") { |v| OPTIONS["oauth.token_secret"] = v }
20
+ end
21
+ opts
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,32 @@
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::Client.new do
9
+ defer :node_purged do
10
+ purge_items_from(OPTIONS["pubsub.node"])
11
+ end
12
+
13
+ def node_purged(success)
14
+ if success
15
+ puts "Node '#{OPTIONS["pubsub.node"]}' was successfully purged."
16
+ else
17
+ puts "Could not purge node '#{OPTIONS["pubsub.node"]}'."
18
+ end
19
+ end
20
+ end
21
+
22
+ if defined?(OAuth) && OPTIONS["oauth"]
23
+ switchboard.plug!(OAuthPubSubJack)
24
+ else
25
+ switchboard.plug!(PubSubJack)
26
+ end
27
+ switchboard.run!
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,38 @@
1
+ module Switchboard
2
+ module Commands
3
+ class PubSub
4
+ class Retract < Switchboard::Command
5
+ description "Retracts an item from a pubsub node"
6
+
7
+ def self.options(opts)
8
+ super(opts)
9
+ opts.on("--item-id=id", String, "Specifies the item id to retract.") { |v| OPTIONS["pubsub.retract.id"] = v }
10
+ end
11
+
12
+ def self.run!
13
+ switchboard = Switchboard::Client.new do
14
+ defer :item_retracted do
15
+ delete_item_from(OPTIONS["pubsub.node"], OPTIONS["pubsub.retract.id"])
16
+ end
17
+
18
+ def item_retracted(success)
19
+ # puts "Result: #{success.to_s}"
20
+ if success
21
+ puts "Item was retracted." # TODO with id?
22
+ else
23
+ puts "Item could not be retracted."
24
+ end
25
+ end
26
+ end
27
+
28
+ if defined?(OAuth) && 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,34 @@
1
+ module Switchboard
2
+ module Commands
3
+ class PubSub
4
+ class Subscribe < Switchboard::Command
5
+ description "Subscribe to a pubsub node"
6
+
7
+ def self.run!
8
+ switchboard = Switchboard::Client.new do
9
+ # this executes in the main loop, so it doesn't really matter that this runs in a different thread
10
+ defer :subscribed do
11
+ subscribe_to(settings["pubsub.node"])
12
+ end
13
+
14
+ # define here or as hydrant.subscriptions_received
15
+ def subscribed(subscription)
16
+ if subscription && subscription.subscription == :subscribed
17
+ puts "Subscribe successful."
18
+ else
19
+ puts "Subscribe failed!"
20
+ end
21
+ end
22
+ end
23
+
24
+ if defined?(OAuth) && OPTIONS["oauth"]
25
+ switchboard.plug!(OAuthPubSubJack)
26
+ else
27
+ switchboard.plug!(PubSubJack)
28
+ end
29
+ switchboard.run!
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,35 @@
1
+ module Switchboard
2
+ module Commands
3
+ class PubSub
4
+ class Subscriptions < Switchboard::Command
5
+ description "List pubsub subscriptions"
6
+
7
+ def self.run!
8
+ switchboard = Switchboard::Client.new do
9
+ # this executes in the main loop, so it doesn't really matter that this runs in a different thread
10
+ defer :subscriptions_received do
11
+ subscriptions(settings["pubsub.node"])
12
+ end
13
+
14
+ # define here or as hydrant.subscriptions_received
15
+ def subscriptions_received(subscriptions)
16
+ if subscriptions && subscriptions.any?
17
+ puts "Subscriptions:"
18
+ puts subscriptions.collect { |subscription| [subscription.subid, "#{subscription.jid || settings["jid"]} => #{subscription.node} (#{subscription.state})"].compact * ": " } * "\n"
19
+ else
20
+ puts "No subscriptions."
21
+ end
22
+ end
23
+ end
24
+
25
+ if defined?(OAuth) && OPTIONS["oauth"]
26
+ switchboard.plug!(OAuthPubSubJack)
27
+ else
28
+ switchboard.plug!(PubSubJack)
29
+ end
30
+ switchboard.run!
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,30 @@
1
+ module Switchboard
2
+ module Commands
3
+ class PubSub
4
+ class Unsubscribe < Switchboard::Command
5
+ description "Unsubscribe from a pubsub node"
6
+
7
+ def self.run!
8
+ switchboard = Switchboard::Client.new do
9
+ # this executes in the main loop, so it doesn't really matter that this runs in a different thread
10
+ defer :unsubscribed do
11
+ unsubscribe_from(settings["pubsub.node"])
12
+ end
13
+
14
+ # define here or as hydrant.subscriptions_received
15
+ def unsubscribed(successful)
16
+ puts "Unsubscribe was successful." if successful
17
+ end
18
+ end
19
+
20
+ if defined?(OAuth) && OPTIONS["oauth"]
21
+ switchboard.plug!(OAuthPubSubJack)
22
+ else
23
+ switchboard.plug!(PubSubJack)
24
+ end
25
+ switchboard.run!
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end