Class: Blather::DSL::PubSub

Inherits:
Object
  • 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

Create a new pubsub DSL

Parameters:

  • client (Blather::Client)

    the client who’s connection will be used

  • host (#to_s)

    the PubSub host



11
12
13
14
# File 'lib/blather/client/dsl/pubsub.rb', line 11

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) {|Hash| ... } ⇒ Object

Retrieve Affiliations

Parameters:

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

    the PubSub host (defaults to the initialized host)

Yields:



20
21
22
# File 'lib/blather/client/dsl/pubsub.rb', line 20

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

#create(node, host = 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)

Yields:



123
124
125
126
# File 'lib/blather/client/dsl/pubsub.rb', line 123

def create(node, host = nil)
  stanza = Stanza::PubSub::Create.new(:set, send_to(host), node)
  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:



143
144
145
146
# File 'lib/blather/client/dsl/pubsub.rb', line 143

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:



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

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:



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

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:



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

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:



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

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:



133
134
135
136
# File 'lib/blather/client/dsl/pubsub.rb', line 133

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:



113
114
115
116
# File 'lib/blather/client/dsl/pubsub.rb', line 113

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:



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

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:



28
29
30
# File 'lib/blather/client/dsl/pubsub.rb', line 28

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

#unsubscribe(node, jid = 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:



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

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