123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- require 'rss'
- class Sessions::Backend::Rss
- def initialize( user, client, client_id )
- @user = user
- @client = client
- @client_id = client_id
- end
- def collection_key
- "rss::load::#{ self.class.to_s }::#{ @user.id }"
- end
- def load
- # check timeout
- cache = Sessions::CacheIn.get( self.collection_key )
- return cache if cache
- url = 'http://www.heise.de/newsticker/heise-atom.xml'
- rss_items = Rss.fetch( url, 8 )
- # set new timeout
- Sessions::CacheIn.set( self.collection_key, rss_items, { :expires_in => 1.hours } )
- rss_items
- end
- def client_key
- "rss::load::#{ self.class.to_s }::#{ @user.id }::#{ @client_id }"
- end
- def push
- # check timeout
- timeout = Sessions::CacheIn.get( self.client_key )
- return if timeout
- # set new timeout
- Sessions::CacheIn.set( self.client_key, true, { :expires_in => 5.minutes } )
- data = self.load
- return if !data||data.empty?
- if !@client
- return {
- :event => 'rss_rebuild',
- :collection => 'dashboard_rss',
- :data => data,
- }
- end
- @client.log 'notify', "push rss for user #{@user.id}"
- @client.send({
- :event => 'rss_rebuild',
- :collection => 'dashboard_rss',
- :data => data,
- })
- end
- end
|