Class: Jabber::UserLocation::Helper

Inherits:
PubSub::ServiceHelper show all
Defined in:
lib/xmpp4r/location/helper/helper.rb

Overview

A Helper for XEP-0080 User Location

Use this helper to send a user’s location, or receive them from a specified jid. Described at www.xmpp.org/extensions/xep-0080.html

For example: <pre> h = UserLocation::Helper( @client, ‘[email protected]’ ) h.add_userlocation_callback do |location|

puts "Now in: #{location.locality}"

end </pre>

Instance Method Summary collapse

Methods inherited from PubSub::ServiceHelper

#add_event_callback, #create_collection_node, #create_node, #delete_item_from, #delete_node, #get_affiliations, #get_config_from, #get_items_from, #get_options_from, #get_subids_for, #get_subscribers_from, #get_subscriptions_from, #get_subscriptions_from_all_nodes, #initialize, #publish_item_to, #publish_item_with_id_to, #purge_items_from, #set_affiliations, #set_config_for, #set_options_for, #subscribe_to, #to_s, #unsubscribe_from

Constructor Details

This class inherits a constructor from Jabber::PubSub::ServiceHelper

Instance Method Details

#add_userlocation_callback(prio = 200, ref = nil, &block) ⇒ Object

Add a callback that will be invoked when a location is received from the jid specified when you constructed the Helper.



46
47
48
49
50
51
52
53
# File 'lib/xmpp4r/location/helper/helper.rb', line 46

def add_userlocation_callback(prio = 200, ref = nil, &block)
  add_event_callback(prio, ref) do |event|
    location = event.first_element('items/item/location')
    if location
      block.call(location)
    end
  end
end

#current_location(location) ⇒ Object

Send out the current location.

location
Jabber::UserLocation::Location

current_location



29
30
31
32
33
34
# File 'lib/xmpp4r/location/helper/helper.rb', line 29

def current_location(location)
  item = Jabber::PubSub::Item.new()
  item.add(location)

  publish_item_to(NS_USERLOCATION, item)
end

#stop_publishingObject

Use this method to indicate that you wish to stop publishing a location.



39
40
41
# File 'lib/xmpp4r/location/helper/helper.rb', line 39

def stop_publishing
  current_location(Jabber::UserLocation::Location.new())
end