Module: Twitter::API::DirectMessages

Includes:
Utils
Included in:
Client
Defined in:
lib/twitter/api/direct_messages.rb

Constant Summary

Constants included from Utils

Utils::DEFAULT_CURSOR

Instance Method Summary collapse

Instance Method Details

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

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

Examples:

Return the direct message with the id 1825786345

Twitter.direct_message(1825786345)

Parameters:

  • id (Integer)

    A Tweet IDs.

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

    A customizable set of options.

Returns:

Raises:

See Also:

Rate Limited?:

  • Yes

Authentication:

  • Requires user context



61
62
63
64
# File 'lib/twitter/api/direct_messages.rb', line 61

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

#direct_message_create(user, text, options = {}) ⇒ Twitter::DirectMessage Also known as: d, m

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

Examples:

Send a direct message to @sferik from the authenticating user

Twitter.direct_message_create('sferik', "I'm sending you this message via @gem!")
Twitter.direct_message_create(7505382, "I'm sending you this message via @gem!")  # Same as above

Parameters:

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

    A Twitter user ID, screen name, 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



138
139
140
141
142
# File 'lib/twitter/api/direct_messages.rb', line 138

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

#direct_message_destroy(*ids) ⇒ Array<Twitter::DirectMessage> #direct_message_destroy(*ids, options) ⇒ Array<Twitter::DirectMessage>

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:

  • #direct_message_destroy(*ids) ⇒ Array<Twitter::DirectMessage>

    Examples:

    Destroys the direct message with the ID 1825785544

    Twitter.direct_message_destroy(1825785544)
    

    Parameters:

    • ids (Array<Integer>, Set<Integer>)

      An array of Tweet IDs.

  • #direct_message_destroy(*ids, options) ⇒ Array<Twitter::DirectMessage>

    Parameters:

    • ids (Array<Integer>, Set<Integer>)

      An array of Tweet IDs.

    • options (Hash)

      A customizable set of options.

Returns:

Raises:

See Also:

Rate Limited?:

  • No

Authentication:

  • Requires user context



121
122
123
# File 'lib/twitter/api/direct_messages.rb', line 121

def direct_message_destroy(*args)
  threaded_object_from_response(Twitter::DirectMessage, :post, "/1.1/direct_messages/destroy.json", args)
end

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

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:

  • #direct_messages(options = {}) ⇒ Array<Twitter::DirectMessage>

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

    Examples:

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

    Twitter.direct_messages
    

    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.

    See Also:

  • #direct_messages(*ids) ⇒ Array<Twitter::DirectMessage>

    Returns direct messages

    Examples:

    Return the direct message with the id 1825786345

    Twitter.direct_messages(1825786345)
    

    Parameters:

    • ids (Array<Integer>, Set<Integer>)

      An array of Tweet IDs.

    See Also:

  • #direct_messages(*ids, options) ⇒ Array<Twitter::DirectMessage>

    Returns direct messages

    Parameters:

    • ids (Array<Integer>, Set<Integer>)

      An array of Tweet IDs.

    • options (Hash)

      A customizable set of options.

    See Also:

Returns:

Raises:

Rate Limited?:

  • Yes

Authentication:

  • Requires user context



95
96
97
98
99
100
101
102
103
104
# File 'lib/twitter/api/direct_messages.rb', line 95

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

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

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

Examples:

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

Twitter.direct_messages_received

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



26
27
28
# File 'lib/twitter/api/direct_messages.rb', line 26

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

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

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

Examples:

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

Twitter.direct_messages_sent

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



45
46
47
# File 'lib/twitter/api/direct_messages.rb', line 45

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