Instead of passing the complete XML response to the page, only the part where the interesting fields for a course are stored should be passed as a parameter. It also shortens the code in the html.erb file that is necessary to pull out the wanted fields.
43 lines
918 B
Ruby
43 lines
918 B
Ruby
class TissCrawler
|
|
|
|
require 'httparty'
|
|
|
|
$host = 'https://tiss.tuwien.ac.at'
|
|
|
|
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(url)
|
|
|
|
response = HTTParty.get(url)
|
|
JSON.parse(response.body)["results"]
|
|
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_host
|
|
$host
|
|
end
|
|
|
|
end |