Class: AppEngine::XMPP::Message
- Inherits:
-
Object
- Object
- AppEngine::XMPP::Message
- Defined in:
- lib/appengine-apis/xmpp.rb
Overview
Constant Summary collapse
- ARG_INDEX =
{:to => 0, :body => 1, :from => 2, :type => 3, :xml => 4}
- COMMAND_REGEX =
/^[\\\/](\S+)(\s+(.+))?/
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#recipients ⇒ Object
readonly
Returns the value of attribute recipients.
-
#sender ⇒ Object
readonly
Returns the value of attribute sender.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#arg ⇒ Object
If this message contains a chat command, returns the command argument.
-
#command ⇒ Object
Returns the command if this message contains a chat command.
-
#initialize(*args) ⇒ Message
constructor
call-seq: Message.new(to, body, from=nil, type=:chat, xml=false) or Message.new(options).
-
#reply(body, type = :chat, xml = false) ⇒ Object
Convenience method to reply to a message.
- #xml? ⇒ Boolean
Constructor Details
#initialize(*args) ⇒ Message
call-seq:
Message.new(to, body, from=nil, type=:chat, xml=false)
or
Message.new()
Constructor for sending an outgoing XMPP message or parsing an incoming XMPP message.
Args / Options:
[:to] Destination JID or array of JIDs for the message.
[:body] Body of the message.
[:from]
Optional custom sender JID. The default is
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/appengine-apis/xmpp.rb', line 95 def initialize(*args) if args.size == 1 = args[0] elsif args[-1].kind_of? Hash = args.pop else = {} end @recipients = fetch_arg(:to, , args) @body = fetch_arg(:body, , args) unless @recipients && @body raise ArgumentError, "Recipient and body are required." end @recipients = [@recipients] unless @recipients.kind_of? Array @sender = fetch_arg(:from, , args) @type = fetch_arg(:type, , args) || :chat @xml = !!fetch_arg(:xml, , args) end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
70 71 72 |
# File 'lib/appengine-apis/xmpp.rb', line 70 def body @body end |
#recipients ⇒ Object (readonly)
Returns the value of attribute recipients.
70 71 72 |
# File 'lib/appengine-apis/xmpp.rb', line 70 def recipients @recipients end |
#sender ⇒ Object (readonly)
Returns the value of attribute sender.
70 71 72 |
# File 'lib/appengine-apis/xmpp.rb', line 70 def sender @sender end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
70 71 72 |
# File 'lib/appengine-apis/xmpp.rb', line 70 def type @type end |
Instance Method Details
#arg ⇒ Object
If this message contains a chat command, returns the command argument. Otherwise, returns the message body.
127 128 129 130 |
# File 'lib/appengine-apis/xmpp.rb', line 127 def arg parse_command @arg end |
#command ⇒ Object
Returns the command if this message contains a chat command.
120 121 122 123 |
# File 'lib/appengine-apis/xmpp.rb', line 120 def command parse_command @command end |
#reply(body, type = :chat, xml = false) ⇒ Object
Convenience method to reply to a message.
133 134 135 136 |
# File 'lib/appengine-apis/xmpp.rb', line 133 def reply(body, type=:chat, xml=false) = Message.new([sender], body, recipients[0], type, xml) XMPP.() end |
#xml? ⇒ Boolean
115 116 117 |
# File 'lib/appengine-apis/xmpp.rb', line 115 def xml? @xml end |