mojodna-switchboard 0.0.8 → 0.0.9

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 CHANGED
@@ -16,7 +16,7 @@ Gem::Specification.new do |s|
16
16
  s.executables = ["switchboard"]
17
17
  s.require_paths = ["lib"]
18
18
 
19
- s.add_dependency("xmpp4r")
19
+ s.add_dependency("mojodna-xmpp4r", ">=", "0.4.0.1")
20
20
  end
21
21
  EOF
22
22
 
data/bin/switchboard CHANGED
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'switchboard'
3
+ require 'switchboard/commands'
3
4
  require 'optparse'
4
5
 
5
6
  ARGV.clone.options do |opts|
@@ -0,0 +1,13 @@
1
+ module Switchboard
2
+ module Commands
3
+ class Disco < Switchboard::Command
4
+ description "Service discovery"
5
+
6
+ def self.options(opts)
7
+ super(opts)
8
+ opts.on("--node=node", String, "Specifies the node to query.") { |v| OPTIONS["disco.node"] = v }
9
+ opts.on("--target=target", String, "Specifies the target to query.") { |v| OPTIONS["disco.target"] = v }
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,39 @@
1
+ require 'xmpp4r/discovery'
2
+
3
+ module Switchboard
4
+ module Commands
5
+ class Disco
6
+ class Info < Switchboard::Command
7
+ description "Basic service discovery"
8
+
9
+ def self.run!
10
+ switchboard = Switchboard::Client.new do
11
+ helper = Jabber::Discovery::Helper.new(client)
12
+ resp = helper.get_info_for(settings["disco.target"], settings["disco.node"])
13
+
14
+ if resp.identities.any? || resp.features.any?
15
+ puts "Discovery Info for #{settings["disco.target"]}#{settings["disco.node"] ? " (#{settings["disco.node"]})" : ""}"
16
+
17
+ if resp.identities.any?
18
+ puts "Identities:"
19
+ resp.identities.each do |identity|
20
+ puts " #{identity.category}/#{identity.type}: #{identity.iname ? identity.iname : "n/a"}"
21
+ end
22
+ puts
23
+ end
24
+
25
+ puts "Features:" if resp.features.any?
26
+ resp.features.each do |feature|
27
+ puts " #{feature}"
28
+ end
29
+ else
30
+ puts "No information was discoverable for #{settings["disco.target"]}"
31
+ end
32
+ end
33
+
34
+ switchboard.run!
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,30 @@
1
+ require 'xmpp4r/discovery'
2
+
3
+ module Switchboard
4
+ module Commands
5
+ class Disco
6
+ class Items < Switchboard::Command
7
+ description "Item discovery"
8
+
9
+ def self.run!
10
+ switchboard = Switchboard::Client.new do
11
+ helper = Jabber::Discovery::Helper.new(client)
12
+ resp = helper.get_items_for(settings["disco.target"], settings["disco.node"])
13
+
14
+ if resp.items.any?
15
+ puts "Item Discovery for #{settings["disco.target"]}#{settings["disco.node"] ? " (#{settings["disco.node"]})" : ""}"
16
+ resp.items.each do |item|
17
+ name = "#{item.iname}#{item.node ? " (#{item.node})" : ""}"
18
+ puts " " + [item.jid, name].reject { |x| x == "" } * ": "
19
+ end
20
+ else
21
+ puts "No items were discoverable for #{settings["disco.target"]}."
22
+ end
23
+ end
24
+
25
+ switchboard.run!
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,3 @@
1
+ require 'switchboard/commands/disco/disco'
2
+ require 'switchboard/commands/disco/items'
3
+ require 'switchboard/commands/disco/info'
@@ -0,0 +1,34 @@
1
+ require 'xmpp4r/last'
2
+
3
+ module Switchboard
4
+ module Commands
5
+ class Last < Switchboard::Command
6
+ description "Last Activity (XEP-0012)"
7
+
8
+ def self.options(opts)
9
+ super(opts)
10
+ opts.on("--target=target", String, "Specifies the target to query.") { |v| OPTIONS["last.target"] = v }
11
+ end
12
+
13
+ def self.run!
14
+ switchboard = Switchboard::Client.new do
15
+ helper = Jabber::LastActivity::Helper.new(client)
16
+ resp = helper.get_last_activity_from(jid = Jabber::JID.new(settings["last.target"]))
17
+
18
+ status = " (#{resp.status})" if resp.status
19
+ status ||= ""
20
+
21
+ if jid.resource
22
+ puts "#{jid} idle: #{resp.seconds} seconds" << status
23
+ elsif jid.node
24
+ puts "#{jid} last disconnected: " << (Time.new - resp.seconds).to_s << status
25
+ else
26
+ puts "#{jid} uptime: #{resp.seconds} seconds" << status
27
+ end
28
+ end
29
+
30
+ switchboard.run!
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1 @@
1
+ require 'switchboard/commands/last/last'
@@ -22,8 +22,9 @@ module Switchboard
22
22
  end
23
23
 
24
24
  def item_published(success)
25
+ # puts "Result: #{success.to_s}"
25
26
  if success
26
- puts "Item was published."
27
+ puts "Item was published." # TODO include id
27
28
  else
28
29
  puts "Item could not be published."
29
30
  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
@@ -10,6 +10,7 @@ require 'switchboard/commands/pubsub/nodes'
10
10
  require 'switchboard/commands/pubsub/options'
11
11
  require 'switchboard/commands/pubsub/publish'
12
12
  require 'switchboard/commands/pubsub/purge'
13
+ require 'switchboard/commands/pubsub/retract'
13
14
  require 'switchboard/commands/pubsub/subscribe'
14
15
  require 'switchboard/commands/pubsub/subscriptions'
15
16
  require 'switchboard/commands/pubsub/unsubscribe'
@@ -0,0 +1,28 @@
1
+ module Switchboard
2
+ module Commands
3
+ class Roster
4
+ class Online < Switchboard::Command
5
+ description "List online members of your roster"
6
+
7
+ def self.run!
8
+ switchboard = Switchboard::Client.new do
9
+ puts "Collecting presences..."
10
+ sleep 5
11
+ roster.items.each do |jid, item|
12
+ next unless item.online?
13
+ puts "#{item.jid}:"
14
+ item.each_presence do |presence|
15
+ status = [presence.show, presence.status].compact * " - "
16
+ status = "available" if status == ""
17
+ puts " /#{presence.from.resource} (#{status}) [#{presence.priority}]"
18
+ end
19
+ end
20
+ end
21
+
22
+ switchboard.plug!(AutoAcceptJack)
23
+ switchboard.run!
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -1,4 +1,5 @@
1
1
  require 'switchboard/commands/roster/roster'
2
2
  require 'switchboard/commands/roster/add'
3
3
  require 'switchboard/commands/roster/list'
4
- require 'switchboard/commands/roster/remove'
4
+ require 'switchboard/commands/roster/online'
5
+ require 'switchboard/commands/roster/remove'
@@ -1,7 +1,9 @@
1
1
  require 'switchboard/commands/command'
2
2
  require 'switchboard/commands/config'
3
3
  require 'switchboard/commands/default'
4
+ require 'switchboard/commands/disco'
4
5
  require 'switchboard/commands/help'
6
+ require 'switchboard/commands/last'
5
7
  require 'switchboard/commands/pep'
6
8
  require 'switchboard/commands/pubsub'
7
9
  require 'switchboard/commands/register'
@@ -23,7 +23,7 @@ module Switchboard
23
23
  auth!
24
24
  puts "Component connected." if debug?
25
25
  rescue Errno::ECONNREFUSED, Errno::ETIMEDOUT
26
- puts "Couldn't connect to Jabber server at #{settings["component.host"]}:#{settings["component.host"]}.
26
+ puts "Couldn't connect to Jabber server at #{settings["component.host"]}:#{settings["component.port"]}.
27
27
  That may mean the Jabber server isn't running or listening on that port,
28
28
  or there might be firewall issues. Exiting."
29
29
  exit 1
@@ -65,7 +65,7 @@ module Switchboard
65
65
  if @main
66
66
  instance_eval(&@main)
67
67
  elsif loop?
68
- sleep 5 while !shutdown?
68
+ sleep 1 while !shutdown?
69
69
  end
70
70
 
71
71
  shutdown
@@ -96,8 +96,7 @@ module Switchboard
96
96
  rescue
97
97
  puts "An error occurred while running a deferred: #{$!}"
98
98
  puts $!.backtrace * "\n"
99
- puts "Initiating shutdown..."
100
- @shutdown = true
99
+ shutdown!
101
100
  end
102
101
  end
103
102
  end
@@ -174,7 +173,7 @@ module Switchboard
174
173
  puts "An error occurred while running the hook; shutting down..."
175
174
  puts $!
176
175
  puts $!.backtrace * "\n"
177
- shutdown
176
+ shutdown!
178
177
  raise
179
178
  end
180
179
 
@@ -245,6 +244,12 @@ module Switchboard
245
244
  end
246
245
 
247
246
  def shutdown(run_hooks = true)
247
+ if Thread.current != Thread.main
248
+ $stderr.puts "Wrong thread! You should be using #shutdown! instead."
249
+ shutdown!
250
+ return
251
+ end
252
+
248
253
  while (pending = @deferreds.select { |k,d| d.alive? }.length) > 0
249
254
  puts "Waiting for #{pending} thread(s) to finish" if debug?
250
255
  sleep 1
@@ -22,9 +22,10 @@ module Switchboard
22
22
 
23
23
  # TODO most/all of these need to be implemented in OAuthServiceHelper
24
24
  delegate :create_node, :create_collection_node, :delete_node,
25
- :get_config_from, :get_options_from, :get_items_from, :publish_item_to,
26
- :publish_item_with_id_to, :purge_items_from, :set_config_for,
27
- :subscribe_to, :unsubscribe_from, :to => :pubsub,
25
+ :delete_item_from, :get_config_from, :get_options_from, :get_items_from,
26
+ :publish_item_to, :publish_item_with_id_to, :purge_items_from,
27
+ :set_config_for, :subscribe_to, :unsubscribe_from,
28
+ :to => :pubsub,
28
29
  :with => [:oauth_consumer, :oauth_token]
29
30
 
30
31
  def subscriptions(node = nil)
@@ -8,9 +8,10 @@ module Switchboard
8
8
  attr_reader :pubsub
9
9
 
10
10
  delegate :create_node, :create_collection_node, :delete_node,
11
- :get_config_from, :get_options_from, :get_items_from, :publish_item_to,
12
- :publish_item_with_id_to, :purge_items_from, :set_config_for,
13
- :subscribe_to, :unsubscribe_from, :to => :pubsub
11
+ :delete_item_from, :get_config_from, :get_options_from, :get_items_from,
12
+ :publish_item_to, :publish_item_with_id_to, :purge_items_from,
13
+ :set_config_for, :subscribe_to, :unsubscribe_from,
14
+ :to => :pubsub
14
15
 
15
16
  Switchboard::Core.hook(:pubsub_event)
16
17
 
@@ -7,7 +7,6 @@ end
7
7
  require 'switchboard/core'
8
8
  require 'switchboard/client'
9
9
  require 'switchboard/component'
10
- require 'switchboard/commands'
11
10
  require 'switchboard/jacks'
12
11
  require 'switchboard/settings'
13
12
  require 'switchboard/version'
@@ -1,3 +1,3 @@
1
1
  module Switchboard
2
- VERSION = [0, 0, 8]
2
+ VERSION = [0, 0, 9]
3
3
  end
data/switchboard.gemspec CHANGED
@@ -1,15 +1,15 @@
1
1
  # this file is automatically generated
2
2
  Gem::Specification.new do |s|
3
3
  s.name = "switchboard"
4
- s.version = "0.0.8"
4
+ s.version = "0.0.9"
5
5
  s.summary = "XMPP toolkit."
6
6
  s.description = "A toolkit for assembling XMPP clients and interacting with XMPP servers."
7
7
  s.authors = ["Seth Fitzsimmons"]
8
8
  s.email = ["seth@mojodna.net"]
9
9
 
10
- s.files = ["bin/switchboard", "examples/election_results.rb", "lib/switchboard/client.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/pep/location.rb", "lib/switchboard/commands/pep/pep.rb", "lib/switchboard/commands/pep/tune.rb", "lib/switchboard/commands/pep.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/component.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/location/helper/helper.rb", "lib/switchboard/xmpp4r/location/location.rb", "lib/switchboard/xmpp4r/location.rb", "lib/switchboard/xmpp4r/pubsub/helper/oauth_service_helper.rb", "lib/switchboard.rb", "Rakefile", "README.markdown", "switchboard.gemspec"]
10
+ s.files = ["bin/switchboard", "examples/election_results.rb", "lib/switchboard/client.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/disco/disco.rb", "lib/switchboard/commands/disco/info.rb", "lib/switchboard/commands/disco/items.rb", "lib/switchboard/commands/disco.rb", "lib/switchboard/commands/help/help.rb", "lib/switchboard/commands/help.rb", "lib/switchboard/commands/last/last.rb", "lib/switchboard/commands/last.rb", "lib/switchboard/commands/pep/location.rb", "lib/switchboard/commands/pep/pep.rb", "lib/switchboard/commands/pep/tune.rb", "lib/switchboard/commands/pep.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/retract.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/online.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/component.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/location/helper/helper.rb", "lib/switchboard/xmpp4r/location/location.rb", "lib/switchboard/xmpp4r/location.rb", "lib/switchboard/xmpp4r/pubsub/helper/oauth_service_helper.rb", "lib/switchboard.rb", "Rakefile", "README.markdown", "switchboard-0.0.8.gem", "switchboard.gemspec"]
11
11
  s.executables = ["switchboard"]
12
12
  s.require_paths = ["lib"]
13
13
 
14
- s.add_dependency("xmpp4r")
14
+ s.add_dependency("mojodna-xmpp4r", ">=", "0.4.0.1")
15
15
  end
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.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seth Fitzsimmons
@@ -13,13 +13,16 @@ date: 2008-10-27 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
- name: xmpp4r
16
+ name: mojodna-xmpp4r
17
17
  version_requirement:
18
18
  version_requirements: !ruby/object:Gem::Requirement
19
19
  requirements:
20
20
  - - ">="
21
21
  - !ruby/object:Gem::Version
22
22
  version: "0"
23
+ - - "="
24
+ - !ruby/object:Gem::Version
25
+ version: 0.4.0.1
23
26
  version:
24
27
  description: A toolkit for assembling XMPP clients and interacting with XMPP servers.
25
28
  email:
@@ -39,8 +42,14 @@ files:
39
42
  - lib/switchboard/commands/config/config.rb
40
43
  - lib/switchboard/commands/config.rb
41
44
  - lib/switchboard/commands/default.rb
45
+ - lib/switchboard/commands/disco/disco.rb
46
+ - lib/switchboard/commands/disco/info.rb
47
+ - lib/switchboard/commands/disco/items.rb
48
+ - lib/switchboard/commands/disco.rb
42
49
  - lib/switchboard/commands/help/help.rb
43
50
  - lib/switchboard/commands/help.rb
51
+ - lib/switchboard/commands/last/last.rb
52
+ - lib/switchboard/commands/last.rb
44
53
  - lib/switchboard/commands/pep/location.rb
45
54
  - lib/switchboard/commands/pep/pep.rb
46
55
  - lib/switchboard/commands/pep/tune.rb
@@ -57,6 +66,7 @@ files:
57
66
  - lib/switchboard/commands/pubsub/publish.rb
58
67
  - lib/switchboard/commands/pubsub/pubsub.rb
59
68
  - lib/switchboard/commands/pubsub/purge.rb
69
+ - lib/switchboard/commands/pubsub/retract.rb
60
70
  - lib/switchboard/commands/pubsub/subscribe.rb
61
71
  - lib/switchboard/commands/pubsub/subscriptions.rb
62
72
  - lib/switchboard/commands/pubsub/unsubscribe.rb
@@ -64,6 +74,7 @@ files:
64
74
  - lib/switchboard/commands/register.rb
65
75
  - lib/switchboard/commands/roster/add.rb
66
76
  - lib/switchboard/commands/roster/list.rb
77
+ - lib/switchboard/commands/roster/online.rb
67
78
  - lib/switchboard/commands/roster/remove.rb
68
79
  - lib/switchboard/commands/roster/roster.rb
69
80
  - lib/switchboard/commands/roster.rb
@@ -93,6 +104,7 @@ files:
93
104
  - lib/switchboard.rb
94
105
  - Rakefile
95
106
  - README.markdown
107
+ - switchboard-0.0.8.gem
96
108
  - switchboard.gemspec
97
109
  has_rdoc: false
98
110
  homepage: