Class: Harborapp::Upload

Inherits:
Object
  • Object
show all
Includes:
ApiModel
Defined in:
lib/harborapp/upload.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ApiModel

#attrs, #errors, #errors=, included, #initialize, #new_record?, #populate, #success?

Instance Attribute Details

#curl_paramsObject

Returns the value of attribute curl_params.



7
8
9
# File 'lib/harborapp/upload.rb', line 7

def curl_params
  @curl_params
end

#file_pathObject

Returns the value of attribute file_path.



7
8
9
# File 'lib/harborapp/upload.rb', line 7

def file_path
  @file_path
end

#keyObject

Returns the value of attribute key.



7
8
9
# File 'lib/harborapp/upload.rb', line 7

def key
  @key
end

#s3_folderObject

Returns the value of attribute s3_folder.



7
8
9
# File 'lib/harborapp/upload.rb', line 7

def s3_folder
  @s3_folder
end

Class Method Details

.get_curl_params(file) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/harborapp/upload.rb', line 9

def self.get_curl_params file
  params = (file ? {:file => file} : {} )
    upload = Harborapp::Api.request :post, "/uploads/curl", params
  upload.file_path = file
  upload.key = upload.s3_folder + "/" + SecureRandom.hex(6) + "-" + File.basename(file)
  upload
end

Instance Method Details

#deliverObject



17
18
19
# File 'lib/harborapp/upload.rb', line 17

def deliver
  `curl https://s3.amazonaws.com/harborapp -F AWSAccessKeyId="#{curl_params["AWSAccessKeyId"]}" -F acl="public-read"  -F key="#{key}" -F "content-type=#{curl_params["content-type"]}" -F "x-amz-security-token=#{curl_params["x-amz-security-token"]}" -F success_action_status="200" -F policy="#{curl_params["policy"]}" -F signature="#{curl_params["signature"]}" -F file=@"#{file_path}"`
end