Module: AppEngine::XMPP

Defined in:
lib/appengine-apis/xmpp.rb

Overview

The XMPP api provides an interface for accessing XMPP status information, sending XMPP messages, and parsing XMPP responses.

Defined Under Namespace

Modules: Proto, Status Classes: Message, Presence, XMPPError

Class Method Summary collapse

Class Method Details

.get_presence(jid, from_jid = nil) ⇒ Object

Get the presence for a JID.

Args:

  • jid: The JID of the contact whose presence is requested.

  • from_jid: Optional custom sender JID.

    The default is <appid>@appspot.com. Custom JIDs can be of the form
    <anything>@<appid>.appspotchat.com.
    

Returns:

  • A Presence object.



191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# File 'lib/appengine-apis/xmpp.rb', line 191

def get_presence(jid, from_jid=nil)
  raise ArgumentError, 'Jabber ID cannot be nil' if jid.nil?
  request = Proto::PresenceRequest.new
  request.set_jid(jid)
  request.set_from_jid(from_jid) if from_jid
  
  response = make_sync_call('GetPresence', request,
                            Proto::PresenceResponse)
  Presence.new(response.isIsAvailable)
rescue ApiProxy::ApplicationException => ex
  case Proto::ErrorCode.value_of(ex.application_error)
  when Proto::ErrorCode::INVALID_JID
    raise ArgumentError, "Invalid jabber ID: #{jid}"
  else
    raise XMPPError, 'Unknown error retrieving presence for jabber ID: ' +
        jid
  end
end

.send_invitation(jid, from_jid = nil) ⇒ Object

Send a chat invitaion.

Args:

  • jid: JID of the contact to invite.

  • from_jid: Optional custom sender JID.

    The default is <appid>@appspot.com. Custom JIDs can be of the form
    <anything>@<appid>.appspotchat.com.
    


217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
# File 'lib/appengine-apis/xmpp.rb', line 217

def send_invitation(jid, from_jid=nil)
  raise ArgumentError, 'Jabber ID cannot be nil' if jid.nil?
  request = Proto::XmppInviteRequest.new
  request.set_jid(jid)
  request.set_from_jid(from_jid) if from_jid

  make_sync_call('SendInvite', request, Proto::XmppInviteResponse)
  nil
rescue ApiProxy::ApplicationException => ex
  case Proto::ErrorCode.value_of(ex.application_error)
  when Proto::ErrorCode::INVALID_JID
    raise ArgumentError, "Invalid jabber ID: #{jid}"
  else
    raise XMPPError, 'Unknown error sending invitation to jabber ID: ' +
        jid
  end
end

.send_message(*args) ⇒ Object

call-seq:

XMPP.send_message(message)
or
XMPP.send_message(*message_args)

Send a chat message.

Args:

  • message: A Message object to send.

  • message_args: Used to create a new Message. See #Message.new

Returns an Array Statuses, one for each JID, corresponding to the result of sending the message to that JID.



249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
# File 'lib/appengine-apis/xmpp.rb', line 249

def send_message(*args)
  if args[0].kind_of? Message
    message = args[0]
  else
    message = Message.new(*args)
  end
  request = message.send :to_proto
  response = make_sync_call('SendMessage', request,
                            Proto::XmppMessageResponse)
  response.status_iterator.to_a
rescue ApiProxy::ApplicationException => ex
  case Proto::ErrorCode.value_of(ex.application_error)
  when Proto::ErrorCode::INVALID_JID
    raise ArgumentError, "Invalid jabber ID"
  when Proto::ErrorCode::NO_BODY
    raise ArgumentError, "Missing message body"
  when Proto::ErrorCode::INVALID_XML
    raise ArgumentError, "Invalid XML body"
  when Proto::ErrorCode::INVALID_TYPE
    raise ArgumentError, "Invalid type #{message.type.inspect}"
  else
    raise XMPPError, 'Unknown error sending message'
  end
end