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

+ (Object) from(message)

Find or create a DirectMessage.

Parameters:

  • message

    An appropriate ::Twitter or ::TweetStream object.



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

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

Instance Method Details

- (Object) make_request

Finds or creates a Request sourced from this DirectMessage.



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

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

- (Object) text

The plain text.



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

def text
		self.raw['text']
end

- (Object) user

Finds or creates a KnownUser connected to this DirectMessage.



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

def user
		KnownUser.by_twitter(username)
end

- (Object) username

Finds the user’s screen_name.



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

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