Class: TaxaController

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

Constant Summary

Constants included from FlashTruncation

FlashTruncation::STRING_OVERHEAD

Instance Method Summary collapse

Methods inherited from ApplicationController

#block_api_access, #evil_parameter_hack!, #extract_header_info, #set_cache_disabled!

Methods included from FlashTruncation

#max_flash_size, #truncate_flash, #truncate_flash_array

Instance Method Details

#indexObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/controllers/taxa_controller.rb', line 6

def index
  params.require(:term)

  # Lookup by term and render results
  term = params[:term].to_s.strip
  taxon = client.taxon_from_text(term)

  return head :not_found if taxon.nil?

  render json: taxon
rescue ActionController::ParameterMissing
  render plain: 'Missing required parameter: term', status: :bad_request
rescue Faraday::Error => e
  log_faraday_error(e)
  head :bad_gateway
end

#showObject



23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/controllers/taxa_controller.rb', line 23

def show
  # Lookup by id and render the taxon
  id = params[:id] # the given taxon ID
  taxon = client.taxon_from_id(id)

  return head :not_found if taxon['taxId'].nil?

  render json: taxon
rescue Faraday::Error => e
  log_faraday_error(e)
  head :bad_gateway
end