Class: Twitter::DirectMessageEvent

Inherits:
Identity show all
Includes:
Creatable, Entities
Defined in:
lib/twitter/direct_message_event.rb

Overview

Represents a Twitter direct message event

Instance Attribute Summary collapse

Attributes inherited from Identity

#id

Attributes inherited from Base

#attrs

Instance Method Summary collapse

Methods included from Entities

#entities?, #hashtags, #hashtags?, #media, #media?, #symbols, #symbols?, #uris, #uris?, #user_mentions, #user_mentions?

Methods included from Creatable

#created?, #created_at

Methods inherited from Base

#[], attr_reader, define_attribute_method, define_predicate_method, define_uri_method, display_uri_attr_reader, object_attr_reader, predicate_attr_reader, uri_attr_reader

Methods included from Utils

flat_pmap, pmap

Constructor Details

#initialize(attrs) ⇒ Twitter::DirectMessageEvent

Initializes a new DirectMessageEvent

Examples:

Twitter::DirectMessageEvent.new(attrs)

Parameters:

  • attrs (Hash)

    The attributes hash from the API response



28
29
30
31
32
33
34
35
36
37
# File 'lib/twitter/direct_message_event.rb', line 28

def initialize(attrs)
  attrs = read_from_response(attrs)
  text = attrs.dig(:message_create, :message_data, :text)
  urls = attrs.dig(:message_create, :message_data, :entities, :urls)

  text = text.gsub(urls[0][:url], urls[0][:expanded_url]) if urls.any?

  attrs[:direct_message] = build_direct_message(attrs, text)
  super
end

Instance Attribute Details

#created_timestampString (readonly)

The timestamp when the event was created

Examples:

event.created_timestamp

Returns:

  • (String)


17
18
19
# File 'lib/twitter/direct_message_event.rb', line 17

def created_timestamp
  @created_timestamp
end