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

#initialize(client, host) ⇒ PubSub

Create a new pubsub DSL

Parameters:

  • client (Blather::Client)

    the client who’s connection will be used

  • host (#to_s)

    the PubSub host



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

#hostObject

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

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

Retrieve Affiliations

Parameters:

  • host (#to_s) (defaults to: nil)

    the PubSub host (defaults to the initialized host)

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

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

Create a node

Parameters:

  • node (#to_s)

    the node to create

  • host (#to_s) (defaults to: nil)

    the PubSub host (defaults to the initialized host)

  • configuration (optional, Blather::Stanza::X) (defaults to: nil)

    the additional configuration to be set to created 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

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

Delete a node

Parameters:

  • node (#to_s)

    the node to delete

  • host (#to_s) (defaults to: nil)

    the PubSub host (defaults to the initialized host)

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

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

Retrieve items for a node

Parameters:

  • path (#to_s)

    the node path

  • list (Array<#to_s>) (defaults to: [])

    a list of IDs to retrieve

  • max (Fixnum, #to_s) (defaults to: nil)

    the maximum number of items to return

  • host (#to_s) (defaults to: nil)

    the PubSub host (defaults to the initialized host)

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

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

Discover node information

Parameters:

  • path (#to_s)

    the node path

  • host (#to_s) (defaults to: nil)

    the PubSub host (defaults to the initialized host)

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

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

Discover Nodes

Parameters:

  • path (#to_s) (defaults to: nil)

    the node path

  • host (#to_s) (defaults to: nil)

    the PubSub host (defaults to the initialized host)

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

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

Publish an item to a node

Parameters:

  • node (#to_s)

    the node to publish to

  • payload (#to_s)

    the payload to send see Stanza::PubSub::Publish

  • host (#to_s) (defaults to: nil)

    the PubSub host (defaults to the initialized host)

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

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

Purge all node items

Parameters:

  • node (#to_s)

    the node to purge

  • host (#to_s) (defaults to: nil)

    the PubSub host (defaults to the initialized host)

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

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

Delete items from a node

Parameters:

  • node (#to_s)

    the node to delete from

  • ids (Array<#to_s>) (defaults to: [])

    a list of ids to delete

  • host (#to_s) (defaults to: nil)

    the PubSub host (defaults to the initialized host)

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

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

Subscribe to a node

Defaults to the stripped current JID

Parameters:

  • node (#to_s)

    the node to subscribe to

  • jid (Blather::JID, #to_s) (defaults to: nil)

    is the jid that should be used.

  • host (#to_s) (defaults to: nil)

    the PubSub host (defaults to the initialized host)

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

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

Retrieve Subscriptions

Parameters:

  • host (#to_s) (defaults to: nil)

    the PubSub host (defaults to the initialized host)

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

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

Unsubscribe from a node

Defaults to the stripped current JID

Parameters:

  • node (#to_s)

    the node to unsubscribe from

  • jid (Blather::JID, #to_s) (defaults to: nil)

    is the jid that should be used.

  • host (#to_s) (defaults to: nil)

    the PubSub host (defaults to the initialized host)

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