Class: Qa::TermsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/qa/terms_controller.rb

Overview

This controller is used for all requests to all authorities. It will verify params and figure out which class to instantiate based on the “vocab” param. All the authotirty classes inherit from a super class so they implement the same methods.

Instance Method Summary collapse

Instance Method Details

#check_authorityObject



56
57
58
59
60
61
62
# File 'app/controllers/qa/terms_controller.rb', line 56

def check_authority
  begin
    authority_class.constantize
  rescue
    redirect_to :status => 400
  end 
end

#check_search_paramsObject



50
51
52
53
54
# File 'app/controllers/qa/terms_controller.rb', line 50

def check_search_params
  unless params[:q].present? && params[:vocab].present?
    redirect_to :status => 400
  end
end

#check_sub_authorityObject



64
65
66
67
68
# File 'app/controllers/qa/terms_controller.rb', line 64

def check_sub_authority
  unless params[:sub_authority].nil?
    redirect_to :status => 400 unless authority_class.constantize.authority_valid?(params[:sub_authority])
  end
end

#check_vocab_paramObject



44
45
46
47
48
# File 'app/controllers/qa/terms_controller.rb', line 44

def check_vocab_param
  unless params[:vocab].present?
    redirect_to :status => 400
  end
end

#indexObject

search that returns all results



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/controllers/qa/terms_controller.rb', line 11

def index
  #initialize the authority and run the search. if there's a sub-authority and it's valid, include that param
  @authority = authority_class.constantize.new(params[:q], params[:sub_authority])
  
  #parse the results
  @authority.parse_authority_response
  
  respond_to do |format|
    format.html { render :layout => false, :text => @authority.results }
    format.json { render :layout => false, :text => @authority.results }
    format.js   { render :layout => false, :text => @authority.results }
  end
end

#searchObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/controllers/qa/terms_controller.rb', line 25

def search
  
  #convert wildcard to be URI encoded
  params[:q].gsub!("*", "%2A")
 
  #initialize the authority and run the search. if there's a sub-authority and it's valid, include that param
  @authority = authority_class.constantize.new(params[:q], params[:sub_authority])
  
  #parse the results
  @authority.parse_authority_response
  
  respond_to do |format|
    format.html { render :layout => false, :text => @authority.results }
    format.json { render :layout => false, :text => @authority.results }
    format.js   { render :layout => false, :text => @authority.results }
  end

end