Class: Blather::DSL::PubSub
- Inherits:
-
Object
- Object
- Blather::DSL::PubSub
- 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
-
#host ⇒ Object
Returns the value of attribute host.
Instance Method Summary collapse
-
#affiliations(host = nil) {|Hash| ... } ⇒ Object
Retrieve Affiliations.
-
#create(node, host = nil, configuration = nil) {|Blather::Stanza| ... } ⇒ Object
Create a node.
-
#delete(node, host = nil) {|Blather::Stanza| ... } ⇒ Object
Delete a node.
-
#initialize(client, host) ⇒ PubSub
constructor
Create a new pubsub DSL.
-
#items(path, list = [], max = nil, host = nil) {|Array<Blather::Stanza::PubSub::PubSubItem>| ... } ⇒ Object
Retrieve items for a node.
-
#node(path, host = nil) {|Blather::Stanza::DiscoInfo| ... } ⇒ Object
Discover node information.
-
#nodes(path = nil, host = nil) {|Array<Blather::Stanza::DiscoItems::Item>| ... } ⇒ Object
Discover Nodes.
-
#publish(node, payload, host = nil) {|Blather::Stanza| ... } ⇒ Object
Publish an item to a node.
-
#purge(node, host = nil) {|Blather::Stanza| ... } ⇒ Object
Purge all node items.
-
#retract(node, ids = [], host = nil) {|Blather::Stanza| ... } ⇒ Object
Delete items from a node.
-
#subscribe(node, jid = nil, host = nil) {|Blather::Stanza| ... } ⇒ Object
Subscribe to a node.
-
#subscriptions(host = nil) {|Hash| ... } ⇒ Object
Retrieve Subscriptions.
-
#unsubscribe(node, jid = nil, subid = nil, host = nil) {|Blather::Stanza| ... } ⇒ Object
Unsubscribe from a node.
Constructor Details
Instance Attribute Details
#host ⇒ Object
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
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
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
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
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
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
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
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
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
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
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
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
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 |