diff --git a/Gemfile b/Gemfile index 76bff44..71ae393 100644 --- a/Gemfile +++ b/Gemfile @@ -27,6 +27,9 @@ gem 'jbuilder', '~> 2.7' # Authentication gem (uses bcrypt by default) gem 'devise', '4.7.1' +gem 'httparty', '0.18.0' +gem 'faraday', '1.0.1' + # Needed to encrypt passwords with something else than bcrypt gem 'devise-encryptable', '0.2.0' diff --git a/Gemfile.lock b/Gemfile.lock index 24627d3..7e4399f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -84,10 +84,15 @@ GEM devise-encryptable (0.2.0) devise (>= 2.1.0) erubi (1.9.0) + faraday (1.0.1) + multipart-post (>= 1.2, < 3) ffi (1.12.2) ffi (1.12.2-x64-mingw32) globalid (0.4.2) activesupport (>= 4.2.0) + httparty (0.18.0) + mime-types (~> 3.0) + multi_xml (>= 0.5.2) i18n (1.8.2) concurrent-ruby (~> 1.0) jbuilder (2.10.0) @@ -100,12 +105,17 @@ GEM marcel (0.3.3) mimemagic (~> 0.3.2) method_source (1.0.0) + mime-types (3.3.1) + mime-types-data (~> 3.2015) + mime-types-data (3.2019.1009) mimemagic (0.3.4) mini_mime (1.0.2) mini_portile2 (2.4.0) minitest (5.14.0) msgpack (1.3.3) msgpack (1.3.3-x64-mingw32) + multi_xml (0.6.0) + multipart-post (2.1.1) nio4r (2.5.2) nokogiri (1.10.9) mini_portile2 (~> 2.4.0) @@ -217,6 +227,8 @@ DEPENDENCIES capybara (>= 2.15) devise (= 4.7.1) devise-encryptable (= 0.2.0) + faraday (= 1.0.1) + httparty (= 0.18.0) jbuilder (~> 2.7) puma (~> 4.1) rails (= 6.0.2.1) diff --git a/app/assets/stylesheets/details.scss b/app/assets/stylesheets/details.scss new file mode 100644 index 0000000..9c4cdd7 --- /dev/null +++ b/app/assets/stylesheets/details.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the details controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: https://sass-lang.com/ diff --git a/app/assets/stylesheets/search.scss b/app/assets/stylesheets/search.scss new file mode 100644 index 0000000..1b26d4a --- /dev/null +++ b/app/assets/stylesheets/search.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the search controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: https://sass-lang.com/ diff --git a/app/assets/stylesheets/tiss_crawler.scss b/app/assets/stylesheets/tiss_crawler.scss new file mode 100644 index 0000000..00b82ff --- /dev/null +++ b/app/assets/stylesheets/tiss_crawler.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the tiss_crawler controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: https://sass-lang.com/ diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index ae67716..679dda3 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -1,4 +1,5 @@ -class CoursesController < ApplicationController +class CoursesController < TissCrawlerController + def index end @@ -19,4 +20,5 @@ class CoursesController < ApplicationController def destroy end + end diff --git a/app/controllers/people_controller.rb b/app/controllers/people_controller.rb index 8f79db3..4c4f7ee 100644 --- a/app/controllers/people_controller.rb +++ b/app/controllers/people_controller.rb @@ -1,4 +1,5 @@ -class PeopleController < ApplicationController +class PeopleController < TissCrawlerController + def index end @@ -19,4 +20,5 @@ class PeopleController < ApplicationController def destroy end + end diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index d9b7e5b..9b5a756 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -1,4 +1,5 @@ -class ProjectsController < ApplicationController +class ProjectsController < TissCrawlerController + def index end @@ -19,4 +20,5 @@ class ProjectsController < ApplicationController def destroy end + end diff --git a/app/controllers/theses_controller.rb b/app/controllers/theses_controller.rb index bb2bce7..77423cd 100644 --- a/app/controllers/theses_controller.rb +++ b/app/controllers/theses_controller.rb @@ -1,4 +1,5 @@ -class ThesesController < ApplicationController +class ThesesController < TissCrawlerController + def index end @@ -19,4 +20,5 @@ class ThesesController < ApplicationController def destroy end + end diff --git a/app/controllers/tiss_crawler_controller.rb b/app/controllers/tiss_crawler_controller.rb new file mode 100644 index 0000000..b792b48 --- /dev/null +++ b/app/controllers/tiss_crawler_controller.rb @@ -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 diff --git a/app/helpers/tiss_crawler_helper.rb b/app/helpers/tiss_crawler_helper.rb new file mode 100644 index 0000000..ef4a1b8 --- /dev/null +++ b/app/helpers/tiss_crawler_helper.rb @@ -0,0 +1,2 @@ +module TissCrawlerHelper +end diff --git a/app/views/login/create.html.erb b/app/views/login/create.html.erb deleted file mode 100644 index f529ae0..0000000 --- a/app/views/login/create.html.erb +++ /dev/null @@ -1,2 +0,0 @@ -

Login#create

-

Find me in app/views/login/create.html.erb

diff --git a/app/views/login/destroy.html.erb b/app/views/login/destroy.html.erb deleted file mode 100644 index f241338..0000000 --- a/app/views/login/destroy.html.erb +++ /dev/null @@ -1,2 +0,0 @@ -

Login#destroy

-

Find me in app/views/login/destroy.html.erb

diff --git a/app/views/login/edit.html.erb b/app/views/login/edit.html.erb deleted file mode 100644 index 124a823..0000000 --- a/app/views/login/edit.html.erb +++ /dev/null @@ -1,2 +0,0 @@ -

Login#edit

-

Find me in app/views/login/edit.html.erb

diff --git a/app/views/login/index.html.erb b/app/views/login/index.html.erb index 531536a..139f7ff 100644 --- a/app/views/login/index.html.erb +++ b/app/views/login/index.html.erb @@ -1,2 +1,2 @@ -

Login#index

-

Find me in app/views/login/index.html.erb

+

Successfully logged in

+

Now you can crawl Tiss

diff --git a/app/views/login/new.html.erb b/app/views/login/new.html.erb deleted file mode 100644 index a8b508d..0000000 --- a/app/views/login/new.html.erb +++ /dev/null @@ -1,2 +0,0 @@ -

Login#new

-

Find me in app/views/login/new.html.erb

diff --git a/app/views/login/show.html.erb b/app/views/login/show.html.erb deleted file mode 100644 index 3d30229..0000000 --- a/app/views/login/show.html.erb +++ /dev/null @@ -1,2 +0,0 @@ -

Login#show

-

Find me in app/views/login/show.html.erb

diff --git a/app/views/login/update.html.erb b/app/views/login/update.html.erb deleted file mode 100644 index d3b8015..0000000 --- a/app/views/login/update.html.erb +++ /dev/null @@ -1,2 +0,0 @@ -

Login#update

-

Find me in app/views/login/update.html.erb

diff --git a/app/views/people/index.html.erb b/app/views/people/index.html.erb index 72f624e..91b0b69 100644 --- a/app/views/people/index.html.erb +++ b/app/views/people/index.html.erb @@ -1,2 +1,11 @@

People#index

Find me in app/views/people/index.html.erb

+ +<%= form_tag('/tisscrawler/search', :method => "get") do %> + <%= hidden_field_tag(:context, 'People') %> + <%= hidden_field_tag(:api, '/api/person/v22/psuche') %> + <%= hidden_field_tag(:search_parameter, 'q') %> + <%= label_tag(:search_term, "Search for:") %> + <%= text_field_tag(:search_term) %> + <%= submit_tag("Search") %> +<% end %> \ No newline at end of file diff --git a/app/views/tiss_crawler/search.html.erb b/app/views/tiss_crawler/search.html.erb new file mode 100644 index 0000000..5b628fa --- /dev/null +++ b/app/views/tiss_crawler/search.html.erb @@ -0,0 +1 @@ +<% render @response %> \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index c9c4a08..fb2a15b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -36,6 +36,9 @@ Rails.application.routes.draw do get 'courses/update' get 'courses/destroy' get 'login/index' + + get 'tisscrawler/search', :to => 'tiss_crawler#search' + # For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html root 'login#index' end diff --git a/test/controllers/details_controller_test.rb b/test/controllers/details_controller_test.rb new file mode 100644 index 0000000..d8779ec --- /dev/null +++ b/test/controllers/details_controller_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class DetailsControllerTest < ActionDispatch::IntegrationTest + # test "the truth" do + # assert true + # end +end diff --git a/test/controllers/search_controller_test.rb b/test/controllers/search_controller_test.rb new file mode 100644 index 0000000..9341b7a --- /dev/null +++ b/test/controllers/search_controller_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class SearchControllerTest < ActionDispatch::IntegrationTest + # test "the truth" do + # assert true + # end +end diff --git a/test/controllers/tiss_crawler_controller_test.rb b/test/controllers/tiss_crawler_controller_test.rb new file mode 100644 index 0000000..dee75f8 --- /dev/null +++ b/test/controllers/tiss_crawler_controller_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class TissCrawlerControllerTest < ActionDispatch::IntegrationTest + # test "the truth" do + # assert true + # end +end