tiss2go/lib/tiss/tiss_crawler.rb
Pfingstfrosch cfcbf5acdb Ad requirement 4
I have no idea how this requirement shall be implemented at the end, but at first step, the tiss_crawler.rb lib checks if the search_term is an empty string and returns an error msg if found

otherwise it returns the result, but appended to 'content' key
2020-05-31 15:48:17 +02:00

79 lines
1.8 KiB
Ruby

class TissCrawler
require 'httparty'
def self.host
'https://tiss.tuwien.ac.at'
end
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('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
end
def self.get_details(params)
api = params[:api]
id = params[:tiss_id]
url = host + api + id
puts(url)
response = HTTParty.get(url)
JSON.parse(response.body)
end
def self.get_course_details(params)
api = params[:api]
number = params[:number]
semester = params[:semester]
url = host + api + number + '-' + semester
puts(url)
response = HTTParty.get(url)
response.parsed_response['tuvienna']['course']
end
def self.get_thesis_details(params)
api = params[:api]
id = params[:id]
url = host + api + id
puts(url)
response = HTTParty.get(url)
response.parsed_response['tuvienna']['thesis']
end
def self.get_project_details(params)
api = params[:api]
id = params[:id]
url = host + api + id
puts(url)
response = HTTParty.get(url)
response.parsed_response['tuVienna']['project']
end
def self.get_oid_name(item)
# Fetches a person's name based on the org id
# Example: https://tiss.tuwien.ac.at/api/person/v22/oid/250197
api = '/api/person/v22/oid/'
url = host + api + item
puts(url)
response = HTTParty.get(url)
parsed_response = response.parsed_response
parsed_response['error'] ||
parsed_response['first_name'] + ' ' + response.parsed_response['last_name']
end
end