14
15
16
17
18
19
20
21
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
52
53
54
55
56
57
58
|
# File 'lib/feedbase/feed.rb', line 14
def refresh(force=false)
raise "Missing feed_url" if feed_url.nil?
ff = Feedbase::FetchFeed.new(feed_url)
= ff.
if !force
if last_etag && ([:etag] == last_etag)
puts "-- #{feed_url} -- ETag cache hit"
return
end
end
data = ff.fetch
params = data[:feed_params].merge(:alpha_title => make_alpha_title(data[:feed_params][:title]))
if params[:feed_url] != self[:feed_url]
if x = self.class.filter(:feed_url => params[:feed_url]).first
raise Redirected.new("Redirected to existing feed: #{x.feed_url}")
end
end
params.delete(:feed_url)
begin Sequel::DatabaseError
update params
rescue StandardError puts "The offending record is #{self.inspect}"
raise
end
Feedbase::FeedDownload.create({feed_id: feed_id}.merge(data[:download_params]))
items_created = data[:items].
select {|item| Feedbase::Item[:guid => item[:guid]].nil?}.
map { |item|
params = {
feed_id: feed_id,
title: item[:title].encode("utf-8"),
guid: item[:guid],
link: item[:link],
content: item[:content],
author: item[:author],
word_count: item[:word_count],
pub_date: item[:pub_date]
}
Feedbase::Item.create params
}
items_created
end
|