refactored crawler controllers and bundled them in crawlers namespace
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
class Crawlers::CoursesCrawlerController < TissCrawlerController
|
||||
|
||||
def show_basic
|
||||
params[:api] = '/api/search/course/v1.0/quickSearch'
|
||||
params[:search_parameter] = 'searchterm'
|
||||
puts params[:search_context]
|
||||
@host = TissCrawler.get_host
|
||||
|
||||
# TissCrawler performs general search over the available courses
|
||||
@courses = TissCrawler.search(params)
|
||||
end
|
||||
|
||||
def show_detail
|
||||
params[:api] = '/api/course/'
|
||||
regex = params[:detail_url].match(/courseNr=(?<number>\S{6})/)
|
||||
params[:number] = regex[:number]
|
||||
regex = params[:detail_url].match(/semester=(?<semester>\d{4}[SW])/)
|
||||
params[:semester] = regex[:semester]
|
||||
|
||||
puts params
|
||||
|
||||
# TissCrawler fetches the course's detail information
|
||||
@course = TissCrawler.get_course_details(params)
|
||||
puts @course
|
||||
|
||||
# Get all the org ids into one array
|
||||
@lecturers_oid = @course['lecturers']['oid']
|
||||
@lecturers_names = []
|
||||
|
||||
if @lecturers_oid != nil
|
||||
@lecturers_oid.each do |item|
|
||||
# For each org id get the associated name
|
||||
puts TissCrawler.get_oid_name(item)
|
||||
@lecturers_names << (TissCrawler.get_oid_name(item))
|
||||
end
|
||||
end
|
||||
|
||||
# Host is needed for image rendering
|
||||
@host = TissCrawler.get_host
|
||||
end
|
||||
|
||||
def add_to_fav
|
||||
end
|
||||
|
||||
end
|
||||
@@ -0,0 +1,41 @@
|
||||
class Crawlers::PeopleCrawlerController < TissCrawlerController
|
||||
|
||||
def show_basic
|
||||
params[:api] = '/api/person/v22/psuche'
|
||||
params[:search_parameter] = 'q'
|
||||
puts params[:search_context]
|
||||
@host = TissCrawler.get_host
|
||||
|
||||
# TissCrawler performs general search over the available people
|
||||
@people = TissCrawler.search(params)
|
||||
end
|
||||
|
||||
def show_detail
|
||||
params[:api] = '/api/person/v22/id/'
|
||||
params[:tiss_id] = params[:tiss_id]
|
||||
|
||||
puts params
|
||||
# TissCrawler fetches the person's detail information
|
||||
@person = TissCrawler.get_details(params)
|
||||
# Host is needed for image rendering
|
||||
@host = TissCrawler.get_host
|
||||
end
|
||||
|
||||
def add_to_fav
|
||||
params[:api] = '/api/person/v22/id/'
|
||||
puts params[:tiss_id]
|
||||
@person = TissCrawler.get_details(params)
|
||||
|
||||
# create stores the object to the db after creation
|
||||
if FavoritePerson.create(tiss_id: @person['tiss_id'], first_name: @person['first_name'], last_name: @person['last_name'], picture_uri: @person['picture_uri']).valid?
|
||||
FavoritePerson.create(tiss_id: @person['tiss_id'], first_name: @person['first_name'], last_name: @person['last_name'], picture_uri: @person['picture_uri'])
|
||||
respond_to do |format|
|
||||
format.html { redirect_to favorites_people_url, notice: 'Favorite person stored' }
|
||||
end
|
||||
else
|
||||
flash[:alert] = "Person is already favorited!"
|
||||
redirect_back(fallback_location: search)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
@@ -0,0 +1,13 @@
|
||||
class Crawlers::ProjectsCrawlerController < TissCrawlerController
|
||||
def show_basic
|
||||
|
||||
end
|
||||
|
||||
def show_detail
|
||||
|
||||
end
|
||||
|
||||
def add_to_fav
|
||||
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,13 @@
|
||||
class Crawlers::ThesesCrawlerController < TissCrawlerController
|
||||
def show_basic
|
||||
|
||||
end
|
||||
|
||||
def show_detail
|
||||
|
||||
end
|
||||
|
||||
def add_to_fav
|
||||
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,34 @@
|
||||
class Crawlers::TissCrawlerController < ApplicationController
|
||||
|
||||
# self designed lib to call the Tiss API
|
||||
require 'tiss/tiss_crawler'
|
||||
|
||||
def search
|
||||
# search context like 'People', 'Courses', etc is mandatory
|
||||
$search_context = params[:search_context]
|
||||
|
||||
# evaluate the proper action regarding to the $search_context
|
||||
case $search_context
|
||||
when 'People'
|
||||
# redirect to people_show_basic, propagate the search_term
|
||||
redirect_to :controller => 'crawlers/people_crawler', :action => :show_basic, :search_term => params[:search_term]
|
||||
when 'Courses'
|
||||
# redirect to courses_show_basic, propagate the search_term
|
||||
redirect_to :controller => 'crawlers/courses_crawler', :action => :show_basic, :search_term => params[:search_term]
|
||||
when 'Theses'
|
||||
when 'Projects'
|
||||
else
|
||||
puts 'Undefined search context'
|
||||
end
|
||||
end
|
||||
|
||||
def show_basic
|
||||
end
|
||||
|
||||
def show_detail
|
||||
end
|
||||
|
||||
def add_to_fav
|
||||
end
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user