Class: Blather::DSL::PubSub

Inherits:
Object show all
Defined in:
lib/blather/client/dsl/pubsub.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, host) ⇒ PubSub

Returns a new instance of PubSub.



7
8
9
10
# File 'lib/blather/client/dsl/pubsub.rb', line 7

def initialize(client, host)
  @client = client
  @host = host
end

Instance Attribute Details

#hostObject

Returns the value of attribute host.



5
6
7
# File 'lib/blather/client/dsl/pubsub.rb', line 5

def host
  @host
end

Instance Method Details

#affiliations(host = nil, &callback) ⇒ Object

Retrieve Affiliations Yields a hash of affiliations in the form:

{:aff_type => ['node1', 'node2']}


16
17
18
# File 'lib/blather/client/dsl/pubsub.rb', line 16

def affiliations(host = nil, &callback)
  request Stanza::PubSub::Affiliations.new(:get, send_to(host)), :list, callback
end

#create(node, host = nil) ⇒ Object

Create a node Yields the resulting node This does not (yet) handle configuration

  • node is the node to create



101
102
103
# File 'lib/blather/client/dsl/pubsub.rb', line 101

def create(node, host = nil)
  request(Stanza::PubSub::Create.new(:set, send_to(host), node)) { |n| yield n if block_given? }
end

#delete(node, host = nil) ⇒ Object

Delete a node Yields the resulting node

  • node is the node to delete



117
118
119
# File 'lib/blather/client/dsl/pubsub.rb', line 117

def delete(node, host = nil)
  request(Stanza::PubSubOwner::Delete.new(:set, send_to(host), node)) { |n| yield n if block_given? }
end

#items(path, list = [], max = nil, host = nil, &callback) ⇒ Object

Retrieve items for a node

  • path is the node’s path

  • list can be an array of items to retrieve

  • max can be the maximum number of items to return



54
55
56
# File 'lib/blather/client/dsl/pubsub.rb', line 54

def items(path, list = [], max = nil, host = nil, &callback)
  request Stanza::PubSub::Items.request(send_to(host), path, list, max), :items, callback
end

#node(path, host = nil, &callback) ⇒ Object

Discover node information Yields a DiscoInfo node

  • path is the node’s path



43
44
45
46
47
# File 'lib/blather/client/dsl/pubsub.rb', line 43

def node(path, host = nil, &callback)
  stanza = Stanza::DiscoInfo.new(:get, path)
  stanza.to = send_to(host)
  request stanza, nil, callback
end

#nodes(path = nil, host = nil, &callback) ⇒ Object

Discover Nodes Yields a list of DiscoItem::Item objects

  • path is the node’s path. Default is ‘/’



32
33
34
35
36
37
# File 'lib/blather/client/dsl/pubsub.rb', line 32

def nodes(path = nil, host = nil, &callback)
  path ||= '/'
  stanza = Stanza::DiscoItems.new(:get, path)
  stanza.to = send_to(host)
  request stanza, :items, callback
end

#publish(node, payload, host = nil) ⇒ Object

Publish an item to a node Yields the resulting Publish node

  • node is the node to publish to

  • payload is the payload to send (see Blather::Stanza::PubSub::Publish for details)



83
84
85
# File 'lib/blather/client/dsl/pubsub.rb', line 83

def publish(node, payload, host = nil)
  request(Stanza::PubSub::Publish.new(send_to(host), node, :set, payload)) { |n| yield n if block_given? }
end

#purge(node, host = nil) ⇒ Object

Purge all node items Yields the resulting node

  • node is the node to purge



109
110
111
# File 'lib/blather/client/dsl/pubsub.rb', line 109

def purge(node, host = nil)
  request(Stanza::PubSubOwner::Purge.new(:set, send_to(host), node)) { |n| yield n if block_given? }
end

#retract(node, ids = [], host = nil) ⇒ Object

Delete items from a node Yields the resulting node

  • node is the node to retract items from

  • ids is a list of ids to retract. This can also be a single id



92
93
94
# File 'lib/blather/client/dsl/pubsub.rb', line 92

def retract(node, ids = [], host = nil)
  request(Stanza::PubSub::Retract.new(send_to(host), node, :set, ids)) { |n| yield n if block_given? }
end

#subscribe(node, jid = nil, host = nil) ⇒ Object

Subscribe to a node Yields the resulting Subscription object

  • node is the node to subscribe to

  • jid is the jid that should be used. Defaults to the stripped current JID



63
64
65
66
# File 'lib/blather/client/dsl/pubsub.rb', line 63

def subscribe(node, jid = nil, host = nil)
  jid ||= DSL.client.jid.stripped
  request(Stanza::PubSub::Subscribe.new(:set, send_to(host), node, jid)) { |n| yield n if block_given? }
end

#subscriptions(host = nil, &callback) ⇒ Object

Retrieve Subscriptions Yields a hash of subscriptions in the form:

{:sub_type => [{:node => 'node1', :jid => 'j@d'}]}


24
25
26
# File 'lib/blather/client/dsl/pubsub.rb', line 24

def subscriptions(host = nil, &callback)
  request Stanza::PubSub::Subscriptions.new(:get, send_to(host)), :list, callback
end

#unsubscribe(node, jid = nil, host = nil) ⇒ Object

Unsubscribe from a node Yields the resulting Unsubscribe object

  • node is the node to subscribe to

  • jid is the jid that should be used. Defaults to the stripped current JID



73
74
75
76
# File 'lib/blather/client/dsl/pubsub.rb', line 73

def unsubscribe(node, jid = nil, host = nil)
  jid ||= DSL.client.jid.stripped
  request(Stanza::PubSub::Unsubscribe.new(:set, send_to(host), node, jid)) { |n| yield n if block_given? }
end