Class: Switchboard::Commands::PubSub::Retract

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

Class Method Summary collapse

Methods inherited from Switchboard::Command

description, help, to_command, to_command_name

Class Method Details

.options(opts) ⇒ Object



7
8
9
10
# File 'lib/switchboard/commands/pubsub/retract.rb', line 7

def self.options(opts)
  super(opts)
  opts.on("--item-id=id", String, "Specifies the item id to retract.") { |v| OPTIONS["pubsub.retract.id"] = v }
end

.run!Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/switchboard/commands/pubsub/retract.rb', line 12

def self.run!
  switchboard = Switchboard::Client.new do
    defer :item_retracted do
      delete_item_from(OPTIONS["pubsub.node"], OPTIONS["pubsub.retract.id"])
    end

    def item_retracted(success)
      # puts "Result: #{success.to_s}"
      if success
        puts "Item was retracted." # TODO with id?
      else
        puts "Item could not be retracted."
      end
    end
  end

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