Module: Twitter::REST::DirectMessages
- Includes:
- UploadUtils, Utils, Utils
- Included in:
- API
- Defined in:
- lib/twitter/rest/direct_messages.rb,
lib/twitter/rest/direct_messages/welcome_messages.rb
Defined Under Namespace
Modules: WelcomeMessages
Constant Summary
Constants included from Utils
Instance Method Summary collapse
-
#create_direct_message(user_id, text, options = {}) ⇒ Twitter::DirectMessage
(also: #d, #m, #dm)
Sends a new direct message to the specified user from the authenticating user.
-
#create_direct_message_event(*args) ⇒ Twitter::DirectMessageEvent
Create a new direct message event to the specified user from the authenticating user.
-
#create_direct_message_event_with_media(user, text, media, options = {}) ⇒ Twitter::DirectMessageEvent
Create a new direct message event to the specified user from the authenticating user with media.
-
#destroy_direct_message(*ids) ⇒ nil
Destroys direct messages.
-
#direct_message(id, options = {}) ⇒ Twitter::DirectMessage
Returns a direct message.
-
#direct_message_event(id, options = {}) ⇒ Twitter::DirectMessageEvent
Returns a direct message event.
-
#direct_messages(*args) ⇒ Object
@see https://developer.twitter.com/en/docs/direct-messages/sending-and-receiving/api-reference/list-events @param options [Hash] A customizable set of options.
-
#direct_messages_events(options = {}) ⇒ Array<Twitter::DirectMessageEvent>
Returns all Direct Message events for the authenticated user (both sent and received) within the last 30 days.
-
#direct_messages_list(options = {}) ⇒ Array<Twitter::DirectMessage>
Returns all Direct Messages for the authenticated user (both sent and received) within the last 30 days.
-
#direct_messages_received(options = {}) ⇒ Array<Twitter::DirectMessage>
Returns Direct Messages received by the authenticated user within the last 30 days.
-
#direct_messages_sent(options = {}) ⇒ Array<Twitter::DirectMessage>
Returns Direct Messages sent by the authenticated user within the last 30 days.
Methods included from Utils
Instance Method Details
#create_direct_message(user_id, text, options = {}) ⇒ Twitter::DirectMessage Also known as: d, m, dm
Sends a new direct message to the specified user from the authenticating user
171 172 173 174 |
# File 'lib/twitter/rest/direct_messages.rb', line 171 def (user_id, text, = {}) event = perform_request_with_object(:json_post, '/1.1/direct_messages/events/new.json', (user_id, text, ), Twitter::DirectMessageEvent) event. end |
#create_direct_message_event(*args) ⇒ Twitter::DirectMessageEvent
This method requires an access token with RWD (read, write & direct message) permissions. Consult The Application Permission Model for more information.
Create a new direct message event to the specified user from the authenticating user
190 191 192 193 194 195 196 |
# File 'lib/twitter/rest/direct_messages.rb', line 190 def (*args) arguments = Twitter::Arguments.new(args) = arguments..dup [:event] = {type: 'message_create', message_create: {target: {recipient_id: extract_id(arguments[0])}, message_data: {text: arguments[1]}}} if arguments.length >= 2 response = Twitter::REST::Request.new(self, :json_post, '/1.1/direct_messages/events/new.json', ).perform Twitter::DirectMessageEvent.new(response[:event]) end |
#create_direct_message_event_with_media(user, text, media, options = {}) ⇒ Twitter::DirectMessageEvent
This method requires an access token with RWD (read, write & direct message) permissions. Consult The Application Permission Model for more information.
Create a new direct message event to the specified user from the authenticating user with media
211 212 213 214 215 216 217 |
# File 'lib/twitter/rest/direct_messages.rb', line 211 def (user, text, media, = {}) media_id = upload(media, media_category_prefix: 'dm')[:media_id] = .dup [:event] = {type: 'message_create', message_create: {target: {recipient_id: extract_id(user)}, message_data: {text: text, attachment: {type: 'media', media: {id: media_id}}}}} response = Twitter::REST::Request.new(self, :json_post, '/1.1/direct_messages/events/new.json', ).perform Twitter::DirectMessageEvent.new(response[:event]) end |
#destroy_direct_message(*ids) ⇒ nil
This method requires an access token with RWD (read, write & direct message) permissions. Consult The Application Permission Model for more information.
Destroys direct messages
154 155 156 157 158 159 |
# File 'lib/twitter/rest/direct_messages.rb', line 154 def (*ids) pmap(ids) do |id| perform_requests(:delete, '/1.1/direct_messages/events/destroy.json', id: id) end nil end |
#direct_message(id, options = {}) ⇒ Twitter::DirectMessage
This method requires an access token with RWD (read, write & direct message) permissions. Consult The Application Permission Model for more information.
Returns a direct message
88 89 90 |
# File 'lib/twitter/rest/direct_messages.rb', line 88 def (id, = {}) (id, ). end |
#direct_message_event(id, options = {}) ⇒ Twitter::DirectMessageEvent
This method requires an access token with RWD (read, write & direct message) permissions. Consult The Application Permission Model for more information.
Returns a direct message event
102 103 104 105 106 |
# File 'lib/twitter/rest/direct_messages.rb', line 102 def (id, = {}) = .dup [:id] = id perform_get_with_object('/1.1/direct_messages/events/show.json', , Twitter::DirectMessageEvent) end |
#direct_messages(*ids) ⇒ Object #direct_messages(*ids, options) ⇒ Object
@see https://developer.twitter.com/en/docs/direct-messages/sending-and-receiving/api-reference/list-events @param options [Hash] A customizable set of options. @option options [Integer] :count Specifies the number of records (sent and received dms) to retrieve. Must be less than or equal to 50. Default is 50 this count does not directly correspond to the output, as we pull sent and received messages from twitter and only present received to the user @option options [String] :cursor Specifies the cursor position of results to retrieve.
133 134 135 136 137 138 139 140 141 142 |
# File 'lib/twitter/rest/direct_messages.rb', line 133 def (*args) arguments = Twitter::Arguments.new(args) if arguments.empty? (arguments.) else pmap(arguments) do |id| (id, arguments.) end end end |
#direct_messages_events(options = {}) ⇒ Array<Twitter::DirectMessageEvent>
This method requires an access token with RWD (read, write & direct message) permissions. Consult The Application Permission Model for more information.
Returns all Direct Message events for the authenticated user (both sent and received) within the last 30 days. Sorted in reverse-chronological order.
26 27 28 29 |
# File 'lib/twitter/rest/direct_messages.rb', line 26 def ( = {}) limit = .fetch(:count, 20) perform_get_with_cursor('/1.1/direct_messages/events/list.json', .merge!(no_default_cursor: true, count: 50, limit: limit), :events, Twitter::DirectMessageEvent) end |
#direct_messages_list(options = {}) ⇒ Array<Twitter::DirectMessage>
This method requires an access token with RWD (read, write & direct message) permissions. Consult The Application Permission Model for more information.
Returns all Direct Messages for the authenticated user (both sent and received) within the last 30 days. Sorted in reverse-chronological order.
41 42 43 |
# File 'lib/twitter/rest/direct_messages.rb', line 41 def ( = {}) ().collect(&:direct_message) end |
#direct_messages_received(options = {}) ⇒ Array<Twitter::DirectMessage>
This method requires an access token with RWD (read, write & direct message) permissions. Consult The Application Permission Model for more information.
Returns Direct Messages received by the authenticated user within the last 30 days. Sorted in reverse-chronological order. this count does not directly correspond to the output, as we pull sent and received messages from twitter and only present received to the user
56 57 58 59 |
# File 'lib/twitter/rest/direct_messages.rb', line 56 def ( = {}) limit = .fetch(:count, 20) ().select { |dm| dm.recipient_id == user_id }.first(limit) end |
#direct_messages_sent(options = {}) ⇒ Array<Twitter::DirectMessage>
This method requires an access token with RWD (read, write & direct message) permissions. Consult The Application Permission Model for more information.
Returns Direct Messages sent by the authenticated user within the last 30 days. Sorted in reverse-chronological order. this count does not directly correspond to the output, as we pull sent and received messages from twitter and only present received to the user
72 73 74 75 |
# File 'lib/twitter/rest/direct_messages.rb', line 72 def ( = {}) limit = .fetch(:count, 20) ().select { |dm| dm.sender_id == user_id }.first(limit) end |