Class: Twitter::Message

Inherits:
Object
  • Object
show all
Includes:
ModelMixin
Defined in:
lib/twitter/model.rb

Overview

Represents a direct message on Twitter between Twitter users.

Constant Summary collapse

@@ATTRIBUTES =
[:id, :recipient, :sender, :text, :created_at]

Class Method Summary collapse

Methods included from ModelMixin

included

Class Method Details

.attributesObject

Used as factory method callback



296
# File 'lib/twitter/model.rb', line 296

def attributes; @@ATTRIBUTES; end

.create(params) ⇒ Object

Creates a new direct message from the authenticated user of the given client context.

You MUST include a valid/authenticated client context in the given params argument.

For example:

status = Twitter::Message.create(
  :text => 'I am shopping for flip flops',
  :receipient => 'anotherlogin',
  :client => client)

An ArgumentError will be raised if no valid client context is given in the params Hash. For example,

status = Twitter::Status.create(:text => 'I am shopping for flip flops')

The above line of code will raise an ArgumentError.

The same is true when you do not provide any of the following key-value pairs in the params argument given:

  • text - the String that will be the message text to send to user

  • recipient - the user ID, screen_name or Twitter::User object representation of the recipient of the direct message

The Twitter::Message object returned after the direct message is successfully sent on the Twitter server side is returned from this method.

Raises:

  • (ArgumentError)


330
331
332
333
334
335
336
# File 'lib/twitter/model.rb', line 330

def create(params)
	client, text, recipient = params[:client], params[:text], params[:recipient]
	raise ArgumentError, 'Valid client context must be given' unless client.is_a?(Twitter::Client)
	raise ArgumentError, 'Message text must be supplied to send direct message' unless text.is_a?(String)
	raise ArgumentError, 'Recipient user must be specified to send direct message' unless [Twitter::User, Integer, String].member?(recipient.class)
	client.message(:post, text, recipient)
end

.find(id, client) ⇒ Object

Raises NotImplementedError because currently Twitter doesn’t provide a facility to retrieve one message by unique ID.

Raises:

  • (NotImplementedError)


301
302
303
# File 'lib/twitter/model.rb', line 301

def find(id, client)
  raise NotImplementedError, 'Twitter has yet to implement a REST API for this.  This is not a Twitter4R library limitation.'
end