Class: Tweetable::Message
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Persistable
#client, #config, find_or_create, #needs_update?
Instance Attribute Details
#owner ⇒ Object
Returns the value of attribute owner.
3
4
5
|
# File 'lib/tweetable/message.rb', line 3
def owner
@owner
end
|
Class Method Details
.create_from_status(text, client) ⇒ Object
45
46
47
|
# File 'lib/tweetable/message.rb', line 45
def self.create_from_status(text, client)
self.create_from_timeline(client.update(text), true)
end
|
.create_from_timeline(message, create_user = false) ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/tweetable/message.rb', line 25
def self.create_from_timeline(message, create_user = false)
m = Message.find_or_create(:message_id, message[:id])
m.update(
:favorited => message.favorited,
:photos_parsed => '0',
:links_parsed => '0',
:created_at => Time.now.utc.to_s,
:sent_at => message.created_at,
:text => message.text,
:from_screen_name => message.user.screen_name.downcase,
:from_user_id => message.user[:id])
if create_user and m.valid?
u = User.create_from_timeline(message.user)
u.messages << m if u.valid?
end
m
end
|
.purge(&block) ⇒ Object
49
50
51
52
53
|
# File 'lib/tweetable/message.rb', line 49
def self.purge(&block)
all.sort.each do |message|
message.delete if yield(message)
end
end
|
Instance Method Details
#<=>(o) ⇒ Object
It seems that, at least using streaming, message id’s are not sequential anymore So comparisons are done on the official sent_at date/time
114
115
116
117
|
# File 'lib/tweetable/message.rb', line 114
def <=>(o)
return 1 if o.nil?
Time.parse(self.sent_at) <=> Time.parse(o.sent_at)
end
|
#==(comparee) ⇒ Object
Objects are equal if they have the same unique custom identifier.
108
109
110
|
# File 'lib/tweetable/message.rb', line 108
def ==(comparee)
self.id == comparee.id
end
|
#eql?(comparee) ⇒ Boolean
Simply delegate to == in this example.
102
103
104
|
# File 'lib/tweetable/message.rb', line 102
def eql?(comparee)
self == comparee
end
|
#from_user ⇒ Object
55
56
57
58
|
# File 'lib/tweetable/message.rb', line 55
def from_user
return nil if self.from_screen_name.nil?
User.find(:screen_name => self.from_screen_name.downcase).first
end
|
#hash ⇒ Object
97
98
99
|
# File 'lib/tweetable/message.rb', line 97
def hash
self.id.hash
end
|
#parse_links(force = false, longify = true) ⇒ Object
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/tweetable/message.rb', line 60
def parse_links(force = false, longify = true)
return unless (force or self.links_parsed != '1')
urls = self.text.scan(Link::URL_PATTERN).flatten
urls.each do |url|
link = Link.find(:url => url).first
if !link
link = Link.create(:url => url, :created_at => Time.new.to_s)
next if !link.valid?
long_url = URL.lookup_long_url(url)
link.update(:long_url => long_url) unless (long_url.nil? or long_url == url)
end
link.increment_usage_count(from_user)
update(:links_parsed => '1')
links.add(link)
end
links
end
|
85
86
87
|
# File 'lib/tweetable/message.rb', line 85
def
"http://twitter.com/#{from_screen_name}/status/#{message_id}"
end
|
#validate ⇒ Object
89
90
91
92
93
94
95
|
# File 'lib/tweetable/message.rb', line 89
def validate
super
assert_unique :message_id
assert_present :text
assert_format :links_parsed, /^[0,1]$/
assert_format :photos_parsed, /^[0,1]$/
end
|