- don't introduce global variable - don't prefix getter with get_ - single quotes instead of doubles for hash usage
46 lines
1.4 KiB
Ruby
46 lines
1.4 KiB
Ruby
class Crawlers::PeopleCrawlerController < Crawlers::TissCrawlerController
|
|
|
|
def show_basic
|
|
params[:api] = '/api/person/v22/psuche'
|
|
params[:search_parameter] = 'q'
|
|
puts params[:search_context]
|
|
@host = TissCrawler.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.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
|
|
favorite_hash = { tiss_id: @person['tiss_id'],
|
|
# the user who is currently active
|
|
user_id: current_user.id,
|
|
first_name: @person['first_name'],
|
|
last_name: @person['last_name'],
|
|
picture_uri: @person['picture_uri'] }
|
|
if FavoritePerson.create(favorite_hash).valid?
|
|
FavoritePerson.create(favorite_hash)
|
|
flash[:alert] = 'Person added to your favorites!'
|
|
else
|
|
flash[:alert] = 'Person is already favorited!'
|
|
end
|
|
redirect_back(fallback_location: search)
|
|
end
|
|
|
|
end
|