Class: Netfira::WebConnect::RackApp::Action::Version8::Files

Inherits:
Netfira::WebConnect::RackApp::Action show all
Defined in:
lib/netfira/web_connect/rack_app/actions/version_8/files.rb

Constant Summary

Constants inherited from Netfira::WebConnect::RackApp::Action

Netfira::WebConnect::RackApp::Action::VALID_BASE64

Instance Attribute Summary

Attributes inherited from Netfira::WebConnect::RackApp::Action

#env, #headers, #input, #path, #query_string, #shop, #timeout, #verb

Instance Method Summary collapse

Methods inherited from Netfira::WebConnect::RackApp::Action

action_classes, #allow, #class_for_record_type, #class_for_relation_type, create, #dispatch_event, #header, #import_env, #initialize, latest_version, #send_file

Constructor Details

This class inherits a constructor from Netfira::WebConnect::RackApp::Action

Instance Method Details

#callObject

Raises:

  • (BadRequest)


4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/netfira/web_connect/rack_app/actions/version_8/files.rb', line 4

def call
  allow :post
  klass = class_for_record_type(path[0])
  raise BadRequest, "You can't upload files for that data type" unless klass < Netfira::WebConnect::Model::Record::FileRecord

  file_name = path[1]
  raise BadRequest, 'You must specify a file name' unless file_name.length > 0

  file = klass.find_or_initialize_by_origin_id(shop, file_name)
  file << input
  file.file_name = file_name

  file.save or raise InternalServerError, file.errors
  {}
end