mirror of
https://github.com/CodeforLeipzig/stadtratmonitor.git
synced 2024-12-22 23:53:15 +01:00
Merge pull request #32 from joergreichert/rss_and_scraper_webhook
Rss and scraper webhook
This commit is contained in:
commit
297e63cd95
8 changed files with 64 additions and 35 deletions
|
@ -1,6 +1,7 @@
|
|||
sudo: required
|
||||
|
||||
language: ruby
|
||||
cache: bundler
|
||||
|
||||
services:
|
||||
- docker
|
||||
|
|
11
app/controllers/import_controller.rb
Normal file
11
app/controllers/import_controller.rb
Normal file
|
@ -0,0 +1,11 @@
|
|||
class ImportController < ApplicationController
|
||||
skip_before_filter :verify_authenticity_token, :only => [:new_papers_callback]
|
||||
|
||||
def new_papers_callback
|
||||
require 'open-uri'
|
||||
api_key = Rails.application.config_for(:morph)["key"]
|
||||
uri = URI.parse("https://api.morph.io/jrlover/city_council_leipzig_recent_papers/data.json?key=#{api_key}&query=select%20*%20from%20%27data%27")
|
||||
Paper.import_from_json(uri.read)
|
||||
render :nothing => true
|
||||
end
|
||||
end
|
|
@ -1,19 +0,0 @@
|
|||
class SessionsController < ApplicationController
|
||||
def create
|
||||
if user = User.find_or_create_from_auth_hash(auth_hash)
|
||||
session[:user_id] = user.id
|
||||
end
|
||||
redirect_to root_path
|
||||
end
|
||||
|
||||
def destroy
|
||||
reset_session
|
||||
redirect_to root_path
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def auth_hash
|
||||
request.env['omniauth.auth']
|
||||
end
|
||||
end
|
|
@ -11,7 +11,7 @@ html
|
|||
.row
|
||||
.small-12.columns
|
||||
.clearfix
|
||||
h1#title = link_to 'Stadtratmonitor Leipzig', root_path
|
||||
h1#title = 'Stadtratmonitor Leipzig'
|
||||
- flash.each do |name, msg|
|
||||
= content_tag :div, msg, class: name
|
||||
= yield
|
||||
|
|
|
@ -1,15 +1,37 @@
|
|||
require 'date'
|
||||
|
||||
xml.instruct! :xml, :version => "1.0"
|
||||
xml.rss :version => "2.0" do
|
||||
xml.rss :version => "2.0", "xmlns:dc" => "http://purl.org/dc/elements/1.1/" do
|
||||
xml.channel do
|
||||
xml.title "Search results"
|
||||
xml.description "Papers matching search criteria"
|
||||
xml.link root_url
|
||||
|
||||
@papers.each do |doc|
|
||||
xml.item do
|
||||
xml.title doc.name
|
||||
xml.description truncate(doc.content, length: 768)
|
||||
xml.pubDate doc.published_at.to_date.to_s(:rfc822)
|
||||
if !doc.content.blank?
|
||||
xml.description do
|
||||
xml.cdata! truncate(doc.content, length: 768)
|
||||
end
|
||||
end
|
||||
if !doc.published_at.blank?
|
||||
xml.pubDate DateTime.parse(doc.published_at).utc.strftime("%a, %d %b %Y %H:%M:%S %z")
|
||||
end
|
||||
doc.originator.each do |originator|
|
||||
xml.dc :creator do
|
||||
xml.cdata! originator
|
||||
end
|
||||
end
|
||||
if !doc.paper_type.blank?
|
||||
xml.category do
|
||||
xml.cdata! doc.paper_type
|
||||
end
|
||||
end
|
||||
if !doc.resolution.blank?
|
||||
xml.category do
|
||||
xml.cdata! doc.resolution
|
||||
end
|
||||
end
|
||||
xml.link doc.url
|
||||
xml.guid doc.url
|
||||
end
|
||||
|
|
|
@ -1,15 +1,6 @@
|
|||
Rails.application.routes.draw do
|
||||
root to: redirect { |path_params| "/leipzig" }
|
||||
|
||||
scope ':body' do
|
||||
get '/' => 'search#index', as: :search
|
||||
get '/:id' => 'search#show', as: :saved_search
|
||||
end
|
||||
|
||||
post '/auth/:provider/callback', to: 'sessions#create'
|
||||
get '/auth/browser_id', as: 'sign_in'
|
||||
|
||||
resource :session, only: [:create, :destroy]
|
||||
root :to => 'search#index', as: :search
|
||||
post '/import' => 'import#new_papers_callback'
|
||||
|
||||
# Example of regular route:
|
||||
# get 'products/:id' => 'catalog#view'
|
||||
|
|
|
@ -28,6 +28,21 @@ RSpec.describe SearchController, type: :controller, elasticsearch: true do
|
|||
get :index, body: 'leipzig'
|
||||
end
|
||||
|
||||
|
||||
it "returns rss" do
|
||||
get :index, :format => "rss", body: 'leipzig'
|
||||
expect(response).to be_success
|
||||
expect(response).to render_template(:index)
|
||||
expect(response.content_type).to eq("application/rss+xml")
|
||||
#expect(response.body).to have_tag "rss" do
|
||||
# with_tag "channel" do
|
||||
# with_tag "title"
|
||||
# with_tag "description"
|
||||
# with_tag "link"
|
||||
# end
|
||||
#end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
8
test/integration/routes_test.rb
Normal file
8
test/integration/routes_test.rb
Normal file
|
@ -0,0 +1,8 @@
|
|||
require 'test_helper'
|
||||
|
||||
class RoutesTest < ActionDispatch::IntegrationTest
|
||||
test "route test" do
|
||||
assert_generates "/import", { :controller => "import", :action => "new_papers_callback" }
|
||||
assert_generates "/", :controller => "search", :action => "index"
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue