Class: Blather::DSL::PubSub

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

Overview

A helper class for providing a simplified PubSub interface to the DSL

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (PubSub) initialize(client, host)

Create a new pubsub DSL



13
14
15
16
# File 'lib/blather/client/dsl/pubsub.rb', line 13

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

Instance Attribute Details

- (Object) host

Returns the value of attribute host



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

def host
  @host
end

Instance Method Details

- (Object) affiliations(host = nil) {|Hash| ... }

Retrieve Affiliations

Yields:



22
23
24
# File 'lib/blather/client/dsl/pubsub.rb', line 22

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

- (Object) create(node, host = nil, configuration = nil) {|Blather::Stanza| ... }

Create a node

Yields:



126
127
128
129
130
# File 'lib/blather/client/dsl/pubsub.rb', line 126

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

- (Object) delete(node, host = nil) {|Blather::Stanza| ... }

Delete a node

Yields:



147
148
149
150
# File 'lib/blather/client/dsl/pubsub.rb', line 147

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

- (Object) items(path, list = [], max = nil, host = nil) {|Array<Blather::Stanza::PubSub::PubSubItem>| ... }

Retrieve items for a node

Yields:



64
65
66
67
68
69
70
# File 'lib/blather/client/dsl/pubsub.rb', line 64

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

- (Object) node(path, host = nil) {|Blather::Stanza::DiscoInfo| ... }

Discover node information

Yields:



51
52
53
54
55
# File 'lib/blather/client/dsl/pubsub.rb', line 51

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

- (Object) nodes(path = nil, host = nil) {|Array<Blather::Stanza::DiscoItems::Item>| ... }

Discover Nodes

Yields:



39
40
41
42
43
44
# File 'lib/blather/client/dsl/pubsub.rb', line 39

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

- (Object) publish(node, payload, host = nil) {|Blather::Stanza| ... }

Publish an item to a node

Yields:



104
105
106
107
# File 'lib/blather/client/dsl/pubsub.rb', line 104

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

- (Object) purge(node, host = nil) {|Blather::Stanza| ... }

Purge all node items

Yields:



137
138
139
140
# File 'lib/blather/client/dsl/pubsub.rb', line 137

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

- (Object) retract(node, ids = [], host = nil) {|Blather::Stanza| ... }

Delete items from a node

Yields:



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

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

- (Object) subscribe(node, jid = nil, host = nil) {|Blather::Stanza| ... }

Subscribe to a node

Defaults to the stripped current JID

Yields:



79
80
81
82
83
# File 'lib/blather/client/dsl/pubsub.rb', line 79

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

- (Object) subscriptions(host = nil) {|Hash| ... }

Retrieve Subscriptions

Yields:



30
31
32
# File 'lib/blather/client/dsl/pubsub.rb', line 30

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

- (Object) unsubscribe(node, jid = nil, subid = nil, host = nil) {|Blather::Stanza| ... }

Unsubscribe from a node

Defaults to the stripped current JID

Yields:



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

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