Class: Switchboard::Commands::PubSub::Info

Inherits:
Switchboard::Command show all
Defined in:
lib/switchboard/commands/pubsub/info.rb

Class Method Summary collapse

Methods inherited from Switchboard::Command

description, help, options, to_command, to_command_name

Class Method Details

.run!Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/switchboard/commands/pubsub/info.rb', line 8

def self.run!
  switchboard = Switchboard::Client.new do
    defer :info_retrieved do
      browser = Jabber::PubSub::NodeBrowser.new(client)
      browser.get_info(OPTIONS["pubsub.server"], OPTIONS["pubsub.node"])
    end

    def info_retrieved(info)
      if info
        if OPTIONS["pubsub.node"]
          puts "Info for '#{OPTIONS["pubsub.node"]}' on '#{OPTIONS["pubsub.server"]}'"
        else
          puts "Info for '#{OPTIONS["pubsub.server"]}'"
        end
        info.each do |k,v|
          if v.is_a?(Array)
            puts "  #{k}:"
            v.each do |v2|
              puts "    #{v2}"
            end
          else
            puts "  #{k}: #{v}"
          end
        end
      else
        puts "Info could not be loaded for '#{OPTIONS["pubsub.server"]}'"
      end
    end
  end

  if defined?(OAuth) && OPTIONS["oauth"]
    switchboard.plug!(OAuthPubSubJack)
  else
    switchboard.plug!(PubSubJack)
  end
  switchboard.run!
end