1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class Tweet < ActiveRecord::Base
    def self.update_from_feed(feed_url)
      feed = Feedzirra::Feed.fetch_and_parse(feed_url)
      add_entries(feed.entries)
    end

    private

    def self.add_entries(entries)
      entries.each do |entry|
        unless exists? :guid => entry.id
          create!(
            :links        => entry.links,
            :author       => entry.author,
            :content      => entry.content,
            :url          => entry.url,
            :published_at => entry.published,
            :guid         => entry.id
          )
        end
      end
    end
end