Class: Twitterize::Item

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/twitterize.rb

Class Method Summary collapse

Class Method Details

.find_postableObject



18
19
20
# File 'lib/twitterize.rb', line 18

def Item.find_postable
  Item.find(:all, :conditions => ["posted = ?", 0], :order => 'published_at ASC')
end

.save_rss_item(feed, rss_item, shorturl) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/twitterize.rb', line 22

def Item.save_rss_item(feed, rss_item, shorturl)
  item = Item.find(:first, :conditions => ["guid = ? and feed_id = ?", rss_item.guid, feed.id])
  if item.nil? # not found
    then
    #puts "#{rss_item.guid} NEW"

    tinyurl = WWW::ShortURL.shorten(rss_item.link, shorturl)
    html_decoder = HTMLEntities.new
    
    max_title_len = MAX_TWITTER_CHARS - (tinyurl.size + 4)
    title = html_decoder.decode rss_item.title
    twitter = title[0, max_title_len]
    twitter += "..." if twitter.size == max_title_len
    twitter += " " + tinyurl

    item = Item.new
    item.link = rss_item.link
    item.guid = rss_item.guid
    item.title = title
    item.published_at = rss_item.published
    item.twitter = twitter
    item.posted = 0
    feed.items << item
    item.save
    item
  else
    #puts "#{rss_item.guid} ALREADY IN DB"
    nil
  end
end