Skip to content

Instantly share code, notes, and snippets.

@jacqui
Forked from dwillis/gist:573813
Created September 10, 2010 15:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jacqui/573815 to your computer and use it in GitHub Desktop.
Save jacqui/573815 to your computer and use it in GitHub Desktop.
def detail
return unless check_format
@request = request
@version = params[:version]
@cycle = params[:cycle].to_i
raise ActiveRecord::RecordNotFound if @cycle < 2000
@format = params[:format]
@base_uri = base_uri(@request, @cycle, @version)
@fec_candidate = FecCandidate.find_with_cycle_and_committee(@cycle.to_i,params[:id])
if not @fec_candidate
@fec_candidate = FecCandidate.find_with_cycle(@cycle.to_i,params[:id])
end
@latest_summary = @fec_candidate.summary_for_cycle(params[:cycle].to_i)
respond_to do |format|
format.xml { render :template => "api/fec/candidate_detail.xml.erb", :content_type => 'application/xml' }
format.json {
if @latest_summary.nil?
# render something in json
else
# render the default in json
render :json => { :status => 'OK', :copyright => copyright_notice, :base_uri => @base_uri, :results => [ :fec_candidate_id => @fec_candidate.id, :name => @fec_candidate.name, :party => @fec_candidate.party, :district => @fec_candidate.seat_uri(@format),
:fec_committee => @fec_candidate.committee_uri(@format), :state => @fec_candidate.state_uri(@format), :cycle => @cycle, :mailing_address => @fec_candidate.address_one,
:mailing_city => @fec_candidate.city, :mailing_state => @fec_candidate.state, :mailing_zip => @fec_candidate.zip, :other_cycles => (@fec_candidate.other_cycles.map do |f| { :cycle => f, :uri => @fec_candidate.candidate_uri(@format) } end) ]}
end
}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment