From 6b1b85c6dfd8c00efa5d87500f480f3c889be3ef Mon Sep 17 00:00:00 2001 From: Joerg Reichert Date: Sun, 3 Apr 2016 12:14:37 +0200 Subject: [PATCH] #21: added web hook for paper scraper notification --- app/controllers/import_controller.rb | 9 +++++++++ config/routes.rb | 6 +++--- 2 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 app/controllers/import_controller.rb diff --git a/app/controllers/import_controller.rb b/app/controllers/import_controller.rb new file mode 100644 index 0000000..e7ed14b --- /dev/null +++ b/app/controllers/import_controller.rb @@ -0,0 +1,9 @@ +class ImportController < ApplicationController + 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 \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 5cc218c..d0100e2 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -3,11 +3,11 @@ Rails.application.routes.draw do 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' + scope '/a7d34068d8e22f75898ce838c0e59669bc047e46', :controller => :import do + post :new_papers_callback + end resource :session, only: [:create, :destroy]