mirror of
https://github.com/zammad/zammad
synced 2026-05-24 09:48:36 +00:00
31 lines
No EOL
752 B
Ruby
31 lines
No EOL
752 B
Ruby
module RSS
|
|
def self.fetch(url, limit = 10)
|
|
cache_key = 'rss::' + url
|
|
items = Cache.get( cache_key )
|
|
return items if items
|
|
|
|
puts 'fetch rss...'
|
|
response = Net::HTTP.get_response( URI.parse(url) )
|
|
if response.code.to_s != '200'
|
|
return
|
|
end
|
|
rss = SimpleRSS.parse response.body
|
|
items = []
|
|
fetched = 0
|
|
rss.items.each { |item|
|
|
record = {
|
|
:id => item.id,
|
|
:title => item.title,
|
|
:summary => item.summary,
|
|
:link => item.link,
|
|
:published => item.published
|
|
}
|
|
items.push record
|
|
fetched += 1
|
|
break item if fetched == limit.to_i
|
|
}
|
|
Cache.write( cache_key, items, :expires_in => 4.hours )
|
|
|
|
return items
|
|
end
|
|
end |