Module: Twitter::Client::DirectMessages

Included in:
Twitter::Client
Defined in:
lib/twitter/client/direct_messages.rb

Overview

Defines methods related to direct messages

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 single direct message, specified by id.

Examples:

Return the direct message with the id 1825786345

Twitter.direct_message(1825786345)

Parameters:

  • id (Integer)

    The ID of the direct message to retrieve.

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

    A customizable set of options.

Returns:

Raises:

See Also:

Rate Limited?:

  • Yes

Requires Authentication?:

  • Yes



104
105
106
107
# File 'lib/twitter/client/direct_messages.rb', line 104

def direct_message(id, options={})
  direct_message = get("/1/direct_messages/show/#{id}.json", options)
  Twitter::DirectMessage.new(direct_message)
end

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

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 the Twitter Ruby Gem!")
Twitter.direct_message_create(7505382, "I'm sending you this message via the Twitter Ruby Gem!")  # Same as above

Parameters:

  • user (Integer, String)

    A Twitter user ID or screen name.

  • text (String)

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

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

    A customizable set of options.

Options Hash (options):

  • :include_entities (Boolean, String, Integer)

    Include Tweet Entities when set to true, 't' or 1.

Returns:

Raises:

See Also:

Rate Limited?:

  • No

Requires Authentication?:

  • Yes



85
86
87
88
89
# File 'lib/twitter/client/direct_messages.rb', line 85

def direct_message_create(user, text, options={})
  options.merge_user!(user)
  direct_message = post("/1/direct_messages/new.json", options.merge(:text => text))
  Twitter::DirectMessage.new(direct_message)
end

#direct_message_destroy(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.

Destroys a direct message

Examples:

Destroys the direct message with the ID 1825785544

Twitter.direct_message_destroy(1825785544)

Parameters:

  • id (Integer)

    The ID of the direct message to delete.

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

    A customizable set of options.

Options Hash (options):

  • :include_entities (Boolean, String, Integer)

    Include Tweet Entities when set to true, 't' or 1.

Returns:

Raises:

See Also:

Rate Limited?:

  • No

Requires Authentication?:

  • Yes



66
67
68
69
# File 'lib/twitter/client/direct_messages.rb', line 66

def direct_message_destroy(id, options={})
  direct_message = delete("/1/direct_messages/destroy/#{id}.json", options)
  Twitter::DirectMessage.new(direct_message)
end

#direct_messages(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

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.

  • :include_entities (Boolean, String, Integer)

    Include Tweet Entities when set to true, 't' or 1.

Returns:

Raises:

See Also:

Rate Limited?:

  • Yes

Requires Authentication?:

  • Yes



25
26
27
28
29
# File 'lib/twitter/client/direct_messages.rb', line 25

def direct_messages(options={})
  get("/1/direct_messages.json", options).map do |direct_message|
    Twitter::DirectMessage.new(direct_message)
  end
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.

  • :include_entities (Boolean, String, Integer)

    Include Tweet Entities when set to true, 't' or 1.

Returns:

Raises:

See Also:

Rate Limited?:

  • Yes

Requires Authentication?:

  • Yes



47
48
49
50
51
# File 'lib/twitter/client/direct_messages.rb', line 47

def direct_messages_sent(options={})
  get("/1/direct_messages/sent.json", options).map do |direct_message|
    Twitter::DirectMessage.new(direct_message)
  end
end