setup abstract search
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
class CoursesController < ApplicationController
|
||||
class CoursesController < TissCrawlerController
|
||||
|
||||
def index
|
||||
end
|
||||
|
||||
@@ -19,4 +20,5 @@ class CoursesController < ApplicationController
|
||||
|
||||
def destroy
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
class PeopleController < ApplicationController
|
||||
class PeopleController < TissCrawlerController
|
||||
|
||||
def index
|
||||
end
|
||||
|
||||
@@ -19,4 +20,5 @@ class PeopleController < ApplicationController
|
||||
|
||||
def destroy
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
class ProjectsController < ApplicationController
|
||||
class ProjectsController < TissCrawlerController
|
||||
|
||||
def index
|
||||
end
|
||||
|
||||
@@ -19,4 +20,5 @@ class ProjectsController < ApplicationController
|
||||
|
||||
def destroy
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
class ThesesController < ApplicationController
|
||||
class ThesesController < TissCrawlerController
|
||||
|
||||
def index
|
||||
end
|
||||
|
||||
@@ -19,4 +20,5 @@ class ThesesController < ApplicationController
|
||||
|
||||
def destroy
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
class TissCrawlerController < ApplicationController
|
||||
|
||||
require 'httparty'
|
||||
|
||||
$host = 'https://tiss.tuwien.ac.at'
|
||||
|
||||
def search
|
||||
url = _build_search_url(params)
|
||||
context = _get_context(params)
|
||||
|
||||
response = HTTParty.get(url)
|
||||
case context
|
||||
when 'People'
|
||||
_search_people_result(response)
|
||||
else
|
||||
flash.now[:alert] = 'Unknown Tiss Crawler 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
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user