Class: Weixin::Message
- Inherits:
-
Object
- Object
- Weixin::Message
- Defined in:
- lib/weixin/model.rb
Direct Known Subclasses
Class Method Summary collapse
Instance Method Summary collapse
- #CreateTime ⇒ Object
-
#initialize(hash) ⇒ Message
constructor
A new instance of Message.
- #method_missing(method, *args, &block) ⇒ Object
- #MsgId ⇒ Object
Constructor Details
#initialize(hash) ⇒ Message
Returns a new instance of Message.
10 11 12 |
# File 'lib/weixin/model.rb', line 10 def initialize(hash) @source = OpenStruct.new(hash) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
14 15 16 |
# File 'lib/weixin/model.rb', line 14 def method_missing(method, *args, &block) @source.send(method, *args, &block) end |
Class Method Details
.factory(xml) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/weixin/model.rb', line 26 def Message.factory(xml) hash = MultiXml.parse(xml)['xml'] case hash['MsgType'] when 'text' TextMessage.new(hash) when 'image' ImageMessage.new(hash) when 'location' LocationMessage.new(hash) when 'link' LinkMessage.new(hash) when 'event' EventMessage.new(hash) when 'voice' VoiceMessage.new(hash) when 'video' VideoMessage.new(hash) else raise ArgumentError, 'Unknown Message' end end |
Instance Method Details
#CreateTime ⇒ Object
18 19 20 |
# File 'lib/weixin/model.rb', line 18 def CreateTime @source.CreateTime.to_i end |
#MsgId ⇒ Object
22 23 24 |
# File 'lib/weixin/model.rb', line 22 def MsgId @source.MsgId.to_i end |