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

Instance Method Details

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

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

Raises:

See Also:

Rate Limited?:

  • No

Authentication:

  • Requires user context



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

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

#destroy_direct_message(*ids) ⇒ Array<Twitter::DirectMessage> #destroy_direct_message(*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

Raises:

See Also:

Rate Limited?:

  • No

Authentication:

  • Requires user context



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

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

#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

Raises:

See Also:

Rate Limited?:

  • Yes

Authentication:

  • Requires user context



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

def direct_message(id, options = {})
  options[:id] = id
  perform_get_with_object('/1.1/direct_messages/show.json', options, Twitter::DirectMessage)
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:

Raises:

Rate Limited?:

  • Yes

Authentication:

  • Requires user context



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

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

#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

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.

Raises:

See Also:

Rate Limited?:

  • Yes

Authentication:

  • Requires user context



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

def direct_messages_received(options = {})
  perform_get_with_objects('/1.1/direct_messages.json', options, Twitter::DirectMessage)
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

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.

Raises:

See Also:

Rate Limited?:

  • Yes

Authentication:

  • Requires user context



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

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