Class: Jabber::PubSub::OAuthServiceHelper
- Inherits:
-
ServiceHelper
- Object
- ServiceHelper
- Jabber::PubSub::OAuthServiceHelper
- Defined in:
- lib/switchboard/xmpp4r/pubsub/helper/oauth_service_helper.rb
Overview
PubSub service helper for use with OAuth-authenticated nodes
Instance Method Summary collapse
-
#get_subscriptions_from_all_nodes(oauth_consumer, oauth_token) ⇒ Object
override #get_subscriptions_from_all_nodes to add an oauth element.
-
#initialize(stream, pubsubjid) ⇒ OAuthServiceHelper
constructor
A new instance of OAuthServiceHelper.
-
#subscribe_to(node, oauth_consumer, oauth_token) ⇒ Object
override #subscribe_to to add an oauth element.
-
#unsubscribe_from(node, oauth_consumer, oauth_token, subid = nil) ⇒ Object
override #unsubscribe_from to add an oauth element.
Constructor Details
#initialize(stream, pubsubjid) ⇒ OAuthServiceHelper
Returns a new instance of OAuthServiceHelper.
5 6 7 |
# File 'lib/switchboard/xmpp4r/pubsub/helper/oauth_service_helper.rb', line 5 def initialize(stream, pubsubjid) super(stream, pubsubjid) end |
Instance Method Details
#get_subscriptions_from_all_nodes(oauth_consumer, oauth_token) ⇒ Object
override #get_subscriptions_from_all_nodes to add an oauth element
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/switchboard/xmpp4r/pubsub/helper/oauth_service_helper.rb', line 10 def get_subscriptions_from_all_nodes(oauth_consumer, oauth_token) iq = basic_pubsub_query(:get) iq.pubsub.add(create_oauth_node(oauth_consumer, oauth_token)) entities = iq.pubsub.add(REXML::Element.new('subscriptions')) res = nil @stream.send_with_id(iq) { |reply| if reply.pubsub.first_element('subscriptions') res = [] reply.pubsub.first_element('subscriptions').each_element('subscription') { |subscription| res << Jabber::PubSub::Subscription.import(subscription) } end } res end |
#subscribe_to(node, oauth_consumer, oauth_token) ⇒ Object
override #subscribe_to to add an oauth element
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/switchboard/xmpp4r/pubsub/helper/oauth_service_helper.rb', line 30 def subscribe_to(node, oauth_consumer, oauth_token) iq = basic_pubsub_query(:set) sub = REXML::Element.new('subscribe') sub.attributes['node'] = node sub.attributes['jid'] = @stream.jid.strip.to_s sub.add(create_oauth_node(oauth_consumer, oauth_token)) iq.pubsub.add(sub) res = nil @stream.send_with_id(iq) do |reply| pubsubanswer = reply.pubsub if pubsubanswer.first_element('subscription') res = PubSub::Subscription.import(pubsubanswer.first_element('subscription')) end end # @stream.send_with_id(iq) res end |
#unsubscribe_from(node, oauth_consumer, oauth_token, subid = nil) ⇒ Object
override #unsubscribe_from to add an oauth element
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/switchboard/xmpp4r/pubsub/helper/oauth_service_helper.rb', line 50 def unsubscribe_from(node, oauth_consumer, oauth_token, subid=nil) iq = basic_pubsub_query(:set) unsub = PubSub::Unsubscribe.new unsub.node = node unsub.jid = @stream.jid.strip unsub.add(create_oauth_node(oauth_consumer, oauth_token)) iq.pubsub.add(unsub) ret = false @stream.send_with_id(iq) { |reply| ret = reply.kind_of?(Jabber::Iq) and reply.type == :result } # @stream.send_with_id(iq) ret end |