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

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

Constant Summary

Constants inherited from Switchboard::Command

Switchboard::Command::DEFAULT_OPTIONS, Switchboard::Command::OPTIONS

Class Method Summary collapse

Methods inherited from Switchboard::Command

description, help, hide!, inherited, options, to_command, to_command_name, unregister!

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
45
46
47
48
# File 'lib/switchboard/commands/pubsub/info.rb', line 8

def self.run!
  switchboard = Switchboard::Core.new do
    defer :info_retrieved do
      begin
        browser = Jabber::PubSub::NodeBrowser.new(client)
        browser.get_info(OPTIONS["pubsub.server"], OPTIONS["pubsub.node"])
      rescue Jabber::ServerError => e
        puts e
      end
    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 OPTIONS["oauth"]
    switchboard.plug!(OAuthPubSubJack)
  else
    switchboard.plug!(PubSubJack)
  end
  switchboard.run!
end