Class: WeChat::Messaging::Message
- Inherits:
-
Object
- Object
- WeChat::Messaging::Message
show all
- Includes:
- Symbolizable
- Defined in:
- lib/we_chat/messaging/message.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(hash) ⇒ Message
Returns a new instance of Message.
10
11
12
|
# File 'lib/we_chat/messaging/message.rb', line 10
def initialize(hash)
@source = symbolize_keys! hash
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
27
28
29
30
31
32
33
34
|
# File 'lib/we_chat/messaging/message.rb', line 27
def method_missing(method_name, *args, &block)
key = method_name.to_s.gsub(/\=/, '').camelize.to_sym
if method_name.to_s =~ /.*=$/
@source[key] = args.first
else
return source[key]
end
end
|
Instance Attribute Details
#source ⇒ Object
Returns the value of attribute source.
8
9
10
|
# File 'lib/we_chat/messaging/message.rb', line 8
def source
@source
end
|
Instance Method Details
#create_response(message_type = :text) ⇒ Object
36
37
38
39
40
41
42
43
|
# File 'lib/we_chat/messaging/message.rb', line 36
def create_response(message_type = :text)
response = WeChat::Messaging::Message.new({})
response.to_user_name = self.from_user_name
response.from_user_name = self.to_user_name
response.msg_type = message_type.to_s
response.create_time = Time.now.to_i
response
end
|
#create_time ⇒ Object
14
15
16
17
|
# File 'lib/we_chat/messaging/message.rb', line 14
def create_time
return nil if source[:CreateTime].nil?
Time.at(source[:CreateTime].to_i)
end
|
#msg_id ⇒ Object
19
20
21
|
# File 'lib/we_chat/messaging/message.rb', line 19
def msg_id
source[:MsgId].to_i
end
|
#msg_type ⇒ Object
23
24
25
|
# File 'lib/we_chat/messaging/message.rb', line 23
def msg_type
source[:MsgType].to_sym
end
|