Class: WeixinRailsMiddleware::Message
- Inherits:
-
Object
- Object
- WeixinRailsMiddleware::Message
show all
- Defined in:
- lib/weixin_rails_middleware/message.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(hash) ⇒ Message
Returns a new instance of Message.
14
15
16
|
# File 'lib/weixin_rails_middleware/message.rb', line 14
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
18
19
20
|
# File 'lib/weixin_rails_middleware/message.rb', line 18
def method_missing(method, *args, &block)
@source.send(method, *args, &block)
end
|
Class Method Details
.factory(xml) ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/weixin_rails_middleware/message.rb', line 30
def self.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
22
23
24
|
# File 'lib/weixin_rails_middleware/message.rb', line 22
def CreateTime
@source.CreateTime.to_i
end
|
#MsgId ⇒ Object
26
27
28
|
# File 'lib/weixin_rails_middleware/message.rb', line 26
def MsgId
@source.MsgId.to_i
end
|