Class: Twinkies::Item

Inherits:
Object
  • Object
show all
Includes:
DataMapper::Resource
Defined in:
lib/twinkies/item.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.latestObject



28
29
30
# File 'lib/twinkies/item.rb', line 28

def self.latest
  all :order => [:twitter_id.desc], :limit => 100
end

.refresh(username, password) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/twinkies/item.rb', line 32

def self.refresh(username, password)
  raise "Must provide credentials" if username.nil? || password.nil?

  tweets = FriendSearcher.new(username, password).search('http')
  UrlList.new(tweets) {|t| t.text}.each do |item|
    create :link => item[:url], :tweet => item[:item]
  end
end

Instance Method Details

#saveObject



18
19
20
21
22
23
24
25
26
# File 'lib/twinkies/item.rb', line 18

def save
  @existing = Item.first(:twitter_id => twitter_id)
  if @existing && @existing.link == link
    self.id = @existing.id
    true
  else
    super
  end
end

#tweet=(tweet) ⇒ Object



11
12
13
14
15
16
# File 'lib/twinkies/item.rb', line 11

def tweet=(tweet)
  self.twitter_id = tweet.id
  self.text = tweet.text
  self.user = tweet.user.screen_name
  self.created_at = tweet.created_at
end