Class: BrickFTP::API::FileUpload

Inherits:
Base
  • Object
show all
Defined in:
lib/brick_ftp/api/file_upload.rb

Constant Summary

Constants inherited from Base

Base::QUERY_PARAMS

Class Method Summary collapse

Methods inherited from Base

all, api_path_for, attributes, define_api, define_readonly_attributes, define_writable_attributes, #destroy, find, inherited, #initialize, #update

Constructor Details

This class inherits a constructor from BrickFTP::API::Base

Class Method Details

.create(path:, source:) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/brick_ftp/api/file_upload.rb', line 29

def self.create(path: , source:)
  api_client = BrickFTP::HTTPClient.new
  step1 = api_client.post(api_path_for(:create, path: path), params: { action: 'put' })

  upload_uri = URI.parse(step1['upload_uri'])
  upload_client = BrickFTP::HTTPClient.new(upload_uri.host)
  upload_client.put(step1['upload_uri'], params: source)

  step3 = api_client.post(api_path_for(:create, path: path), params: { action: 'end', ref: step1['ref'] })

  new(step1.merge(step3).symbolize_keys)
end