Class: Apiwork::ExportsController

Inherits:
ActionController::API
  • Object
show all
Defined in:
app/controllers/apiwork/exports_controller.rb

Instance Method Summary collapse

Instance Method Details

#showObject



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

def show
  api_class = API.find!(params[:api_base_path])
  export_name = params[:export_name].to_sym
  export_class = Export.find!(export_name)

  raw_options = { key_format: api_class.key_format }
    .merge(api_class.export_configs[export_name].to_h)
    .merge(params.to_unsafe_h.symbolize_keys)

  format = raw_options[:format]&.to_sym
  options = export_class.extract_options(raw_options)

  result = Export.generate(export_name, api_class.base_path, format:, **options)

  render content_type: export_class.content_type_for(format:), plain: result
end