refactoring of project
This commit is contained in:
parent
e2f0bd7237
commit
c0a5b794ec
@ -3,22 +3,10 @@ class CoursesController < TissCrawlerController
|
||||
def index
|
||||
end
|
||||
|
||||
def show
|
||||
def show_basic
|
||||
end
|
||||
|
||||
def new
|
||||
end
|
||||
|
||||
def edit
|
||||
end
|
||||
|
||||
def create
|
||||
end
|
||||
|
||||
def update
|
||||
end
|
||||
|
||||
def destroy
|
||||
def show_detailed
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@ -3,22 +3,10 @@ class PeopleController < TissCrawlerController
|
||||
def index
|
||||
end
|
||||
|
||||
def show
|
||||
def show_basic
|
||||
end
|
||||
|
||||
def new
|
||||
end
|
||||
|
||||
def edit
|
||||
end
|
||||
|
||||
def create
|
||||
end
|
||||
|
||||
def update
|
||||
end
|
||||
|
||||
def destroy
|
||||
def show_detail
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@ -3,22 +3,10 @@ class ProjectsController < TissCrawlerController
|
||||
def index
|
||||
end
|
||||
|
||||
def show
|
||||
def show_basic
|
||||
end
|
||||
|
||||
def new
|
||||
end
|
||||
|
||||
def edit
|
||||
end
|
||||
|
||||
def create
|
||||
end
|
||||
|
||||
def update
|
||||
end
|
||||
|
||||
def destroy
|
||||
def show_detailed
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@ -3,22 +3,10 @@ class ThesesController < TissCrawlerController
|
||||
def index
|
||||
end
|
||||
|
||||
def show
|
||||
def show_basic
|
||||
end
|
||||
|
||||
def new
|
||||
end
|
||||
|
||||
def edit
|
||||
end
|
||||
|
||||
def create
|
||||
end
|
||||
|
||||
def update
|
||||
end
|
||||
|
||||
def destroy
|
||||
def show_detailed
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@ -1,76 +1,18 @@
|
||||
class TissCrawlerController < ApplicationController
|
||||
|
||||
require 'httparty'
|
||||
|
||||
$host = 'https://tiss.tuwien.ac.at'
|
||||
require 'tiss/tiss_crawler'
|
||||
|
||||
def search
|
||||
url = _build_search_url(params)
|
||||
context = _get_context(params)
|
||||
|
||||
response = HTTParty.get(url)
|
||||
context = params[:context]
|
||||
case context
|
||||
when 'People'
|
||||
_search_people_result(response)
|
||||
when "People"
|
||||
result = TissCrawler.search(params)
|
||||
@people = result.map { |person| Tiss::Person.new(person) }
|
||||
# render(people_show_path, detail: false)
|
||||
render template: people_show_basic_path
|
||||
else
|
||||
flash.now[:alert] = 'Unknown Tiss Crawler Context'
|
||||
flash.write[:alert] = "Unknown search context"
|
||||
end
|
||||
end
|
||||
|
||||
def _build_search_url(params)
|
||||
if params[:api].blank?
|
||||
flash.now[:alert] = 'No api configured!'
|
||||
return
|
||||
else
|
||||
# get the api ... e.g. /'api/person/v22/psuche'
|
||||
api = params[:api]
|
||||
end
|
||||
|
||||
if params[:search_parameter].blank?
|
||||
flash.now[:alert] = 'No search_parameter configured!'
|
||||
return
|
||||
else
|
||||
# get the search param ... e.g. 'q'
|
||||
search_parameter = params[:search_parameter]
|
||||
end
|
||||
|
||||
if params[:search_term].blank?
|
||||
flash.now[:alert] = 'No search_term configured!'
|
||||
return
|
||||
else
|
||||
# get and parameterize search term q, replace whitespaces with +
|
||||
search_term = params[:search_term].parameterize(separator: '+')
|
||||
end
|
||||
|
||||
# concat and return the api call url ... e.g. https://tiss.tuwien.ac.at/api/person/v22/psuche?q=max+mustermann
|
||||
$host + api + '?' + search_parameter + '=' + search_term
|
||||
end
|
||||
|
||||
def _get_context(params)
|
||||
if params[:context].blank?
|
||||
flash.now[:alert] = 'No context configured!'
|
||||
else
|
||||
# return the context
|
||||
params[:context]
|
||||
end
|
||||
end
|
||||
|
||||
def _search_people_result(response)
|
||||
# redirect_to(controller: 'people', :action => 'show', flash: {response: response})
|
||||
@response = "Test"
|
||||
puts('got here', response)
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def details
|
||||
|
||||
end
|
||||
|
||||
|
||||
39
app/services/tiss.rb
Normal file
39
app/services/tiss.rb
Normal file
@ -0,0 +1,39 @@
|
||||
module Tiss
|
||||
class Base
|
||||
|
||||
def initialize(args = {})
|
||||
args.each do |name, value|
|
||||
attr_name = name.to_s.underscore
|
||||
send("#{attr_name}=", value) if respond_to?("#{attr_name}=")
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Person < Base
|
||||
|
||||
# tiss json properties
|
||||
attr_accessor :tiss_id,
|
||||
:oid,
|
||||
:old_tiss_ids,
|
||||
:first_name,
|
||||
:last_name,
|
||||
:gender,
|
||||
:pseudoperson,
|
||||
:preceding_titles,
|
||||
:postpositioned_titles,
|
||||
:orcid,
|
||||
:card_uri,
|
||||
:picture_uri,
|
||||
:main_phone_number,
|
||||
:main_email,
|
||||
:other_emails,
|
||||
:main_addresses,
|
||||
:employee
|
||||
|
||||
def initialize(args = {})
|
||||
super(args)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
@ -1,2 +0,0 @@
|
||||
<h1>Courses#create</h1>
|
||||
<p>Find me in app/views/courses/create.html.erb</p>
|
||||
@ -1,2 +0,0 @@
|
||||
<h1>Courses#destroy</h1>
|
||||
<p>Find me in app/views/courses/destroy.html.erb</p>
|
||||
@ -1,2 +0,0 @@
|
||||
<h1>Courses#edit</h1>
|
||||
<p>Find me in app/views/courses/edit.html.erb</p>
|
||||
@ -1,2 +0,0 @@
|
||||
<h1>Courses#new</h1>
|
||||
<p>Find me in app/views/courses/new.html.erb</p>
|
||||
@ -1,2 +1,2 @@
|
||||
<h1>Courses#show</h1>
|
||||
<h1>Courses#show basic</h1>
|
||||
<p>Find me in app/views/courses/show.html.erb</p>
|
||||
2
app/views/courses/show_detailed.html.erb
Normal file
2
app/views/courses/show_detailed.html.erb
Normal file
@ -0,0 +1,2 @@
|
||||
<h1>Courses#show detailed</h1>
|
||||
<p>Find me in app/views/courses/show.html.erb</p>
|
||||
@ -1,2 +0,0 @@
|
||||
<h1>Courses#update</h1>
|
||||
<p>Find me in app/views/courses/update.html.erb</p>
|
||||
@ -1,2 +0,0 @@
|
||||
<h1>People#create</h1>
|
||||
<p>Find me in app/views/people/create.html.erb</p>
|
||||
@ -1,2 +0,0 @@
|
||||
<h1>People#destroy</h1>
|
||||
<p>Find me in app/views/people/destroy.html.erb</p>
|
||||
@ -1,2 +0,0 @@
|
||||
<h1>People#edit</h1>
|
||||
<p>Find me in app/views/people/edit.html.erb</p>
|
||||
@ -1,2 +0,0 @@
|
||||
<h1>People#new</h1>
|
||||
<p>Find me in app/views/people/new.html.erb</p>
|
||||
@ -1,2 +1,4 @@
|
||||
<h1>People#show</h1>
|
||||
<h1>People#show basic</h1>
|
||||
<p>Find me in app/views/people/show.html.erb</p>
|
||||
|
||||
<%= @people %>
|
||||
4
app/views/people/show_detailed.html.erb
Normal file
4
app/views/people/show_detailed.html.erb
Normal file
@ -0,0 +1,4 @@
|
||||
<h1>People#show detailed</h1>
|
||||
<p>Find me in app/views/people/show.html.erb</p>
|
||||
|
||||
<%= @people %>
|
||||
@ -1,2 +0,0 @@
|
||||
<h1>People#update</h1>
|
||||
<p>Find me in app/views/people/update.html.erb</p>
|
||||
@ -1,2 +0,0 @@
|
||||
<h1>Projects#create</h1>
|
||||
<p>Find me in app/views/projects/create.html.erb</p>
|
||||
@ -1,2 +0,0 @@
|
||||
<h1>Projects#destroy</h1>
|
||||
<p>Find me in app/views/projects/destroy.html.erb</p>
|
||||
@ -1,2 +0,0 @@
|
||||
<h1>Projects#edit</h1>
|
||||
<p>Find me in app/views/projects/edit.html.erb</p>
|
||||
@ -1,2 +0,0 @@
|
||||
<h1>Projects#new</h1>
|
||||
<p>Find me in app/views/projects/new.html.erb</p>
|
||||
@ -1,2 +1,2 @@
|
||||
<h1>Projects#show</h1>
|
||||
<h1>Projects#show basic</h1>
|
||||
<p>Find me in app/views/projects/show.html.erb</p>
|
||||
2
app/views/projects/show_detailed.html.erb
Normal file
2
app/views/projects/show_detailed.html.erb
Normal file
@ -0,0 +1,2 @@
|
||||
<h1>Projects#show detailed</h1>
|
||||
<p>Find me in app/views/projects/show.html.erb</p>
|
||||
@ -1,2 +0,0 @@
|
||||
<h1>Projects#update</h1>
|
||||
<p>Find me in app/views/projects/update.html.erb</p>
|
||||
@ -1,2 +0,0 @@
|
||||
<h1>Theses#create</h1>
|
||||
<p>Find me in app/views/theses/create.html.erb</p>
|
||||
@ -1,2 +0,0 @@
|
||||
<h1>Theses#destroy</h1>
|
||||
<p>Find me in app/views/theses/destroy.html.erb</p>
|
||||
@ -1,2 +0,0 @@
|
||||
<h1>Theses#edit</h1>
|
||||
<p>Find me in app/views/theses/edit.html.erb</p>
|
||||
@ -1,2 +0,0 @@
|
||||
<h1>Theses#new</h1>
|
||||
<p>Find me in app/views/theses/new.html.erb</p>
|
||||
@ -1,2 +1,2 @@
|
||||
<h1>Theses#show</h1>
|
||||
<h1>Theses#show basic</h1>
|
||||
<p>Find me in app/views/theses/show.html.erb</p>
|
||||
2
app/views/theses/show_detailed.html.erb
Normal file
2
app/views/theses/show_detailed.html.erb
Normal file
@ -0,0 +1,2 @@
|
||||
<h1>Theses#show detailed</h1>
|
||||
<p>Find me in app/views/theses/show.html.erb</p>
|
||||
@ -1,2 +0,0 @@
|
||||
<h1>Theses#update</h1>
|
||||
<p>Find me in app/views/theses/update.html.erb</p>
|
||||
@ -1 +0,0 @@
|
||||
<% render @response %>
|
||||
@ -1,40 +1,17 @@
|
||||
Rails.application.routes.draw do
|
||||
devise_for :users, path_names: {sign_in: 'log_in', sign_out: 'log out'}
|
||||
get 'theses/index'
|
||||
get 'theses/show'
|
||||
get 'theses/new'
|
||||
get 'theses/edit'
|
||||
get 'theses/create'
|
||||
get 'theses/update'
|
||||
get 'theses/destroy'
|
||||
get 'theses/show_basic'
|
||||
get 'theses/show_detailed'
|
||||
get 'projects/index'
|
||||
get 'projects/show'
|
||||
get 'projects/new'
|
||||
get 'projects/edit'
|
||||
get 'projects/create'
|
||||
get 'projects/update'
|
||||
get 'projects/destroy'
|
||||
get 'projects/show_basic'
|
||||
get 'projects/show_detailed'
|
||||
get 'people/index'
|
||||
get 'people/show'
|
||||
get 'people/new'
|
||||
get 'people/edit'
|
||||
get 'people/create'
|
||||
get 'people/update'
|
||||
get 'people/destroy'
|
||||
get 'login/index'
|
||||
get 'login/show'
|
||||
get 'login/new'
|
||||
get 'login/edit'
|
||||
get 'login/create'
|
||||
get 'login/update'
|
||||
get 'login/destroy'
|
||||
get 'people/show_basic'
|
||||
get 'people/show_detailed'
|
||||
get 'courses/index'
|
||||
get 'courses/show'
|
||||
get 'courses/new'
|
||||
get 'courses/edit'
|
||||
get 'courses/create'
|
||||
get 'courses/update'
|
||||
get 'courses/destroy'
|
||||
get 'courses/show_basic'
|
||||
get 'courses/show_detailed'
|
||||
get 'login/index'
|
||||
|
||||
get 'tisscrawler/search', :to => 'tiss_crawler#search'
|
||||
|
||||
23
lib/tiss/tiss_crawler.rb
Normal file
23
lib/tiss/tiss_crawler.rb
Normal file
@ -0,0 +1,23 @@
|
||||
class TissCrawler
|
||||
|
||||
require 'httparty'
|
||||
|
||||
$host = 'https://tiss.tuwien.ac.at'
|
||||
|
||||
def self.search(params)
|
||||
api = params[:api]
|
||||
search_parameter = params[:search_parameter]
|
||||
search_term = params[:search_term].parameterize(separator: '+')
|
||||
url = $host + api + '?' + search_parameter + '=' + search_term
|
||||
puts(url)
|
||||
|
||||
response = HTTParty.get(url)
|
||||
JSON.parse(response.body)["results"]
|
||||
end
|
||||
|
||||
|
||||
def details
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
@ -6,7 +6,7 @@ class CoursesControllerTest < ActionDispatch::IntegrationTest
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should get show" do
|
||||
test "should get show_basic" do
|
||||
get courses_show_url
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
@ -6,7 +6,7 @@ class LoginControllerTest < ActionDispatch::IntegrationTest
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should get show" do
|
||||
test "should get show_basic" do
|
||||
get login_show_url
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
@ -6,7 +6,7 @@ class PeopleControllerTest < ActionDispatch::IntegrationTest
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should get show" do
|
||||
test "should get show_basic" do
|
||||
get people_show_url
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
@ -6,7 +6,7 @@ class ProjectsControllerTest < ActionDispatch::IntegrationTest
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should get show" do
|
||||
test "should get show_basic" do
|
||||
get projects_show_url
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
@ -6,7 +6,7 @@ class ThesesControllerTest < ActionDispatch::IntegrationTest
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should get show" do
|
||||
test "should get show_basic" do
|
||||
get theses_show_url
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user