Class: Line::Bot::Receive::Message
- Inherits:
-
Object
- Object
- Line::Bot::Receive::Message
- Defined in:
- lib/line/bot/receive/message.rb
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#created_time ⇒ Object
readonly
Returns the value of attribute created_time.
-
#event_type ⇒ Object
readonly
Returns the value of attribute event_type.
-
#from_channel_id ⇒ Object
readonly
Returns the value of attribute from_channel_id.
-
#from_mid ⇒ Object
readonly
Returns the value of attribute from_mid.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#to_channel_id ⇒ Object
readonly
Returns the value of attribute to_channel_id.
-
#to_mid ⇒ Object
readonly
Returns the value of attribute to_mid.
Instance Method Summary collapse
- #create_content(attrs) ⇒ Object
-
#initialize(attrs) ⇒ Message
constructor
A new instance of Message.
Constructor Details
#initialize(attrs) ⇒ Message
Returns a new instance of Message.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/line/bot/receive/message.rb', line 7 def initialize(attrs) @id = attrs['content']['id'] @from_mid = attrs['content']['from'] @to_mid = attrs['content']['to'] @from_channel_id = attrs['fromChannel'] @to_channel_id = attrs['toChannel'] @event_type = attrs['eventType'] (time, usec) = attrs['content']['createdTime'].to_i.divmod(1000) @created_time = Time.at(time, usec) @content = create_content(attrs['content']) end |
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content.
5 6 7 |
# File 'lib/line/bot/receive/message.rb', line 5 def content @content end |
#created_time ⇒ Object (readonly)
Returns the value of attribute created_time.
5 6 7 |
# File 'lib/line/bot/receive/message.rb', line 5 def created_time @created_time end |
#event_type ⇒ Object (readonly)
Returns the value of attribute event_type.
5 6 7 |
# File 'lib/line/bot/receive/message.rb', line 5 def event_type @event_type end |
#from_channel_id ⇒ Object (readonly)
Returns the value of attribute from_channel_id.
5 6 7 |
# File 'lib/line/bot/receive/message.rb', line 5 def from_channel_id @from_channel_id end |
#from_mid ⇒ Object (readonly)
Returns the value of attribute from_mid.
5 6 7 |
# File 'lib/line/bot/receive/message.rb', line 5 def from_mid @from_mid end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
5 6 7 |
# File 'lib/line/bot/receive/message.rb', line 5 def id @id end |
#to_channel_id ⇒ Object (readonly)
Returns the value of attribute to_channel_id.
5 6 7 |
# File 'lib/line/bot/receive/message.rb', line 5 def to_channel_id @to_channel_id end |
#to_mid ⇒ Object (readonly)
Returns the value of attribute to_mid.
5 6 7 |
# File 'lib/line/bot/receive/message.rb', line 5 def to_mid @to_mid end |
Instance Method Details
#create_content(attrs) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/line/bot/receive/message.rb', line 23 def create_content(attrs) case attrs['contentType'] when Line::Bot::Message::ContentType::TEXT return Line::Bot::Message::Text.new( text: attrs['text'], ) when Line::Bot::Message::ContentType::IMAGE return Line::Bot::Message::Image.new( image_url: attrs['originalContentUrl'], preview_url: attrs['previewImageUrl'], ) when Line::Bot::Message::ContentType::VIDEO return Line::Bot::Message::Video.new( video_url: attrs['originalContentUrl'], preview_url: attrs['previewImageUrl'], ) when Line::Bot::Message::ContentType::AUDIO return Line::Bot::Message::Audio.new( audio_url: attrs['originalContentUrl'], duration: attrs['contentMetadata']['duration'].to_i, ) when Line::Bot::Message::ContentType::LOCATION return Line::Bot::Message::Location.new( title: attrs['location']['title'], address: attrs['location']['address'], latitude: attrs['location']['latitude'], longitude: attrs['location']['longitude'], ) when Line::Bot::Message::ContentType::STICKER return Line::Bot::Message::Sticker.new( stkpkgid: attrs['contentMetadata']['STKPKGID'], stkid: attrs['contentMetadata']['STKID'], stkver: attrs['contentMetadata']['STKVER'], ) when Line::Bot::Message::ContentType::CONTACT return Line::Bot::Message::Contact.new( mid: attrs['contentMetadata']['mid'], display_name: attrs['contentMetadata']['displayName'], ) else end end |