diff --git a/app/controllers/crawlers/courses_crawler_controller.rb b/app/controllers/crawlers/courses_crawler_controller.rb index 6708d4b..dc41553 100644 --- a/app/controllers/crawlers/courses_crawler_controller.rb +++ b/app/controllers/crawlers/courses_crawler_controller.rb @@ -7,7 +7,14 @@ class Crawlers::CoursesCrawlerController < Crawlers::TissCrawlerController @host = TissCrawler.host # TissCrawler performs general search over the available courses - @courses = TissCrawler.search(params) + result = TissCrawler.search(params) + if result.has_key? :error + flash[:alert] = 'Something went wrong! ' + result[:error] + redirect_back(fallback_location: crawlers_tiss_crawler_search_path) + else + # TissCrawler performs general search over the available people + @courses = result[:content] + end end def show_detail diff --git a/app/controllers/crawlers/people_crawler_controller.rb b/app/controllers/crawlers/people_crawler_controller.rb index 5fb3d88..ffb605d 100644 --- a/app/controllers/crawlers/people_crawler_controller.rb +++ b/app/controllers/crawlers/people_crawler_controller.rb @@ -6,8 +6,16 @@ class Crawlers::PeopleCrawlerController < Crawlers::TissCrawlerController puts params[:search_context] @host = TissCrawler.host - # TissCrawler performs general search over the available people - @people = TissCrawler.search(params) + result = TissCrawler.search(params) + + if result.has_key? :error + flash[:alert] = 'Something went wrong! ' + result[:error] + redirect_back(fallback_location: crawlers_tiss_crawler_search_path) + else + # TissCrawler performs general search over the available people + @people = result[:content] + end + end def show_detail @@ -39,7 +47,7 @@ class Crawlers::PeopleCrawlerController < Crawlers::TissCrawlerController else flash[:alert] = 'Person is already favorited!' end - redirect_back(fallback_location: search) + redirect_back(fallback_location: crawlers_tiss_crawler_search_path) end end diff --git a/app/controllers/crawlers/projects_crawler_controller.rb b/app/controllers/crawlers/projects_crawler_controller.rb index 3992598..605efe2 100644 --- a/app/controllers/crawlers/projects_crawler_controller.rb +++ b/app/controllers/crawlers/projects_crawler_controller.rb @@ -6,7 +6,14 @@ class Crawlers::ProjectsCrawlerController < Crawlers::TissCrawlerController @host = TissCrawler.host # TissCrawler performs general search over the available projects - @projects = TissCrawler.search(params) + result = TissCrawler.search(params) + if result.has_key? :error + flash[:alert] = 'Something went wrong! ' + result[:error] + redirect_back(fallback_location: crawlers_tiss_crawler_search_path) + else + # TissCrawler performs general search over the available people + @projects = result[:content] + end end def show_detail diff --git a/app/controllers/crawlers/theses_crawler_controller.rb b/app/controllers/crawlers/theses_crawler_controller.rb index 62046ba..711b1a0 100644 --- a/app/controllers/crawlers/theses_crawler_controller.rb +++ b/app/controllers/crawlers/theses_crawler_controller.rb @@ -6,7 +6,14 @@ class Crawlers::ThesesCrawlerController < Crawlers::TissCrawlerController @host = TissCrawler.host # TissCrawler performs general search over the available theses - @theses = TissCrawler.search(params) + result = TissCrawler.search(params) + if result.has_key? :error + flash[:alert] = 'Something went wrong! ' + result[:error] + redirect_back(fallback_location: crawlers_tiss_crawler_search_path) + else + # TissCrawler performs general search over the available people + @theses = result[:content] + end end def show_detail diff --git a/lib/tiss/tiss_crawler.rb b/lib/tiss/tiss_crawler.rb index 0d04494..17cd662 100644 --- a/lib/tiss/tiss_crawler.rb +++ b/lib/tiss/tiss_crawler.rb @@ -10,10 +10,15 @@ class TissCrawler search_parameter = params[:search_parameter] search_term = params[:search_term].parameterize(separator: '+') url = host + api + '?' + search_parameter + '=' + search_term - puts(url) + puts('generated url:', url) + + if search_term == "" + {'error': 'Dare you try! Empty searches are not allowed!'} + else + response = HTTParty.get(url) + {'content': JSON.parse(response.body)['results']} + end - response = HTTParty.get(url) - JSON.parse(response.body)['results'] end def self.get_details(params)