Removed not used rss backend.

This commit is contained in:
Martin Edenhofer 2016-09-29 21:15:13 +02:00
parent 146bd7f9d4
commit 7ae82024ad
8 changed files with 0 additions and 209 deletions

View file

@ -1,52 +0,0 @@
class App.DashboardRss extends App.Controller
constructor: ->
super
# bind to rebuild view event
@bind('rss_rebuild', @fetch)
# refresh list ever 600 sec.
@fetch()
fetch: =>
# get data from cache
cache = App.SessionStorage.get('dashboard_rss')
if cache
cache.head = 'Heise ATOM'
@render( cache )
# init fetch via ajax, all other updates on time via websockets
else
@ajax(
id: 'dashboard_rss'
type: 'GET'
url: @apiPath + '/rss_fetch'
data: {
limit: 8
url: 'http://www.heise.de/newsticker/heise-atom.xml'
}
processData: true
success: (data) =>
if data.message
@render(
head: 'Heise ATOM'
message: data.message
)
else
App.SessionStorage.set('dashboard_rss', data)
data.head = 'Heise ATOM'
@render(data)
error: =>
@render(
head: 'Heise ATOM'
message: 'Unable to fetch rss!'
)
)
render: (data) ->
@html App.view('dashboard/rss')(
head: data.head,
items: data.items || []
message: data.message
)

View file

@ -1,11 +0,0 @@
<div class="span3">
<h2 class="can-move"><%- @T( @head ) %></h2>
<% if @message: %>
<%- @T(@message) %>
<% end %>
<ul>
<% for item in @items: %>
<li><a href="<%= item.link %>" title="<%= item.summary %>" target="_blank"><%= item.title %>"</a></li>
<% end %>
</ul>
</div>

View file

@ -1,27 +0,0 @@
# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
class RssController < ApplicationController
before_action :authentication_check
=begin
Resource:
GET /api/v1/rss_fetch
Response:
{
...
}
Test:
curl http://localhost/api/v1/rss_fetch.json -v -u #{login}:#{password} -H "Content-Type: application/json" -X GET
=end
def fetch
items = Rss.fetch(params[:url], params[:limit])
raise Exceptions::UnprocessableEntity, "failed to fetch #{params[:url]}" if items.nil?
render json: { items: items }
end
end

View file

@ -1,7 +0,0 @@
Zammad::Application.routes.draw do
api_path = Rails.configuration.api_path
# rss
match api_path + '/rss_fetch', to: 'rss#fetch', via: :get
end

View file

@ -1,38 +0,0 @@
require 'simple-rss'
module Rss
def self.fetch(url, limit = 10)
cache_key = 'rss::' + url
items = Cache.get( cache_key )
return items if items
begin
Rails.logger.info "fetch rss... #{url}"
response = UserAgent.request(url)
if !response.success?
raise "Can't fetch '#{url}', http code: #{response.code}"
end
rss = SimpleRSS.parse response.body
items = []
fetched = 0
rss.items.each { |item|
record = {
id: item.id,
title: Encode.conv( 'utf8', item.title ),
summary: Encode.conv( 'utf8', 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 )
rescue => e
Rails.logger.error "can't fetch #{url}"
Rails.logger.error e.inspect
return
end
items
end
end

View file

@ -1,57 +0,0 @@
require 'rss'
class Sessions::Backend::Rss < Sessions::Backend::Base
def collection_key
"rss::load::#{self.class}::#{@user.id}"
end
def load
# check timeout
cache = Sessions::CacheIn.get(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(collection_key, rss_items, { expires_in: 1.hour })
rss_items
end
def client_key
"rss::load::#{self.class}::#{@user.id}::#{@client_id}"
end
def push
# check timeout
timeout = Sessions::CacheIn.get(client_key)
return if timeout
# set new timeout
Sessions::CacheIn.set(client_key, true, { expires_in: @ttl.seconds })
data = load
return if !data || data.empty?
if !@client
return {
event: 'rss_rebuild',
collection: 'dashboard_rss',
data: data,
}
end
@client.log "push rss for user #{@user.id}"
@client.send(
event: 'rss_rebuild',
collection: 'dashboard_rss',
data: data,
)
end
end

View file

@ -12,7 +12,6 @@ class Sessions::Client
backends = [
'Sessions::Backend::TicketOverviewList',
'Sessions::Backend::Collections',
'Sessions::Backend::Rss',
'Sessions::Backend::ActivityStream',
'Sessions::Backend::TicketCreate',
]

View file

@ -186,22 +186,6 @@ class SessionBasicTest < ActiveSupport::TestCase
assert_equal(result1, result2, 'check collections')
end
test 'c rss' do
user = User.lookup(id: 1)
collection_client1 = Sessions::Backend::Rss.new(user, {}, false, '123-1')
# get whole collections
result1 = collection_client1.push
#puts "RSS1: #{result1.inspect}"
assert(!result1.empty?, 'check rss')
sleep 0.5
# next check should be empty
result1 = collection_client1.push
#puts "R1: #{result1.inspect}"
assert(!result1, 'check rss - recall')
end
test 'c activity stream' do
# create users