Class: Safubot::Twitter::DirectMessage

Inherits:
Object
  • Object
show all
Includes:
MongoMapper::Document
Defined in:
lib/safubot/twitter.rb

Overview

DirectMessage is a Request source. All DirectMessages are made into Requests as they are received.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from(message) ⇒ Object

Find or create a DirectMessage.

Parameters:

  • message

    An appropriate ::Twitter or ::TweetStream object.



133
134
135
136
# File 'lib/safubot/twitter.rb', line 133

def from(message)
  DirectMessage.where('raw.id' => message['id']||message.id).first ||
	DirectMessage.create(:raw => message['attrs']||message)
end

Instance Method Details

#make_requestObject

Finds or creates a Request sourced from this DirectMessage.



155
156
157
# File 'lib/safubot/twitter.rb', line 155

def make_request
		self.request || self.request = Request.create(:user => user, :source => self, :text => self.text)
end

#textObject

The plain text.



140
141
142
# File 'lib/safubot/twitter.rb', line 140

def text
		self.raw['text']
end

#userObject

Finds or creates a KnownUser connected to this DirectMessage.



150
151
152
# File 'lib/safubot/twitter.rb', line 150

def user
		KnownUser.by_twitter(username)
end

#usernameObject

Finds the user’s screen_name.



145
146
147
# File 'lib/safubot/twitter.rb', line 145

def username
		self.raw['sender']['screen_name']
end