Module: Twitter::REST::DirectMessages

Includes:
Utils, Utils
Included in:
API
Defined in:
lib/twitter/rest/direct_messages.rb

Constant Summary

Constant Summary

Constants included from Utils

Utils::DEFAULT_CURSOR, Utils::URI_SUBSTRING

Instance Method Summary (collapse)

Methods included from Utils

flat_pmap, pmap, pmap_with_index

Instance Method Details

- (Twitter::DirectMessage) create_direct_message(user, text, options = {}) Also known as: d, m, dm

Sends a new direct message to the specified user from the authenticating user

Parameters:

  • user (Integer, String, Twitter::User)

    A Twitter user ID, screen name, URI, or object.

  • text (String)

    The text of your direct message, up to 140 characters.

  • options (Hash) (defaults to: {})

    A customizable set of options.

Returns:

Raises:

See Also:

Rate Limited?:

  • No

Authentication:

  • Requires user context



127
128
129
130
131
# File 'lib/twitter/rest/direct_messages.rb', line 127

def create_direct_message(user, text, options = {})
  merge_user!(options, user)
  options[:text] = text
  perform_with_object(:post, '/1.1/direct_messages/new.json', options, Twitter::DirectMessage)
end

- (Array<Twitter::DirectMessage>) destroy_direct_message(*ids) - (Array<Twitter::DirectMessage>) destroy_direct_message(*ids, options)

Note:

This method requires an access token with RWD (read, write & direct message) permissions. Consult The Application Permission Model for more information.

Destroys direct messages

Overloads:

  • - (Array<Twitter::DirectMessage>) destroy_direct_message(*ids)

    Parameters:

    • ids (Enumerable<Integer>)

      A collection of direct message IDs.

  • - (Array<Twitter::DirectMessage>) destroy_direct_message(*ids, options)

    Parameters:

    • ids (Enumerable<Integer>)

      A collection of direct message IDs.

    • options (Hash)

      A customizable set of options.

Returns:

Raises:

See Also:

Rate Limited?:

  • No

Authentication:

  • Requires user context



112
113
114
# File 'lib/twitter/rest/direct_messages.rb', line 112

def destroy_direct_message(*args)
  parallel_objects_from_response(Twitter::DirectMessage, :post, '/1.1/direct_messages/destroy.json', args)
end

- (Twitter::DirectMessage) direct_message(id, options = {})

Note:

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

Parameters:

  • id (Integer)

    A direct message ID.

  • options (Hash) (defaults to: {})

    A customizable set of options.

Returns:

Raises:

See Also:

Rate Limited?:

  • Yes

Authentication:

  • Requires user context



58
59
60
61
# File 'lib/twitter/rest/direct_messages.rb', line 58

def direct_message(id, options = {})
  options[:id] = id
  perform_with_object(:get, '/1.1/direct_messages/show.json', options, Twitter::DirectMessage)
end

- (Array<Twitter::DirectMessage>) direct_messages(options = {}) - (Array<Twitter::DirectMessage>) direct_messages(*ids) - (Array<Twitter::DirectMessage>) direct_messages(*ids, options)

Note:

This method requires an access token with RWD (read, write & direct message) permissions. Consult The Application Permission Model for more information.

Returns The requested messages.

Overloads:

Returns:

Raises:

Rate Limited?:

  • Yes

Authentication:

  • Requires user context



88
89
90
91
92
93
94
95
96
97
# File 'lib/twitter/rest/direct_messages.rb', line 88

def direct_messages(*args)
  arguments = Twitter::Arguments.new(args)
  if arguments.empty?
    direct_messages_received(arguments.options)
  else
    pmap(arguments) do |id|
      direct_message(id, arguments.options)
    end
  end
end

- (Array<Twitter::DirectMessage>) direct_messages_received(options = {})

Note:

This method requires an access token with RWD (read, write & direct message) permissions. Consult The Application Permission Model for more information.

Returns the 20 most recent direct messages sent to the authenticating user

Parameters:

  • options (Hash) (defaults to: {})

    A customizable set of options.

Options Hash (options):

  • :since_id (Integer)

    Returns results with an ID greater than (that is, more recent than) the specified ID.

  • :max_id (Integer)

    Returns results with an ID less than (that is, older than) or equal to the specified ID.

  • :count (Integer)

    Specifies the number of records to retrieve. Must be less than or equal to 200.

  • :page (Integer)

    Specifies the page of results to retrieve.

Returns:

Raises:

See Also:

Rate Limited?:

  • Yes

Authentication:

  • Requires user context



27
28
29
# File 'lib/twitter/rest/direct_messages.rb', line 27

def direct_messages_received(options = {})
  perform_with_objects(:get, '/1.1/direct_messages.json', options, Twitter::DirectMessage)
end

- (Array<Twitter::DirectMessage>) direct_messages_sent(options = {})

Note:

This method requires an access token with RWD (read, write & direct message) permissions. Consult The Application Permission Model for more information.

Returns the 20 most recent direct messages sent by the authenticating user

Parameters:

  • options (Hash) (defaults to: {})

    A customizable set of options.

Options Hash (options):

  • :since_id (Integer)

    Returns results with an ID greater than (that is, more recent than) the specified ID.

  • :max_id (Integer)

    Returns results with an ID less than (that is, older than) or equal to the specified ID.

  • :count (Integer)

    Specifies the number of records to retrieve. Must be less than or equal to 200.

  • :page (Integer)

    Specifies the page of results to retrieve.

Returns:

Raises:

See Also:

Rate Limited?:

  • Yes

Authentication:

  • Requires user context



44
45
46
# File 'lib/twitter/rest/direct_messages.rb', line 44

def direct_messages_sent(options = {})
  perform_with_objects(:get, '/1.1/direct_messages/sent.json', options, Twitter::DirectMessage)
end