Class: BrickFTP::API::FileOperation::UploadingSession

Inherits:
Base
  • Object
show all
Includes:
Enumerable
Defined in:
lib/brick_ftp/api/file_operation/uploading_session.rb

Instance Attribute Summary

Attributes inherited from Base

#properties

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

all, #delete_property, #destroy, find, inherited, #initialize, #read_property, #to_json, #update, #write_property

Constructor Details

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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class BrickFTP::API::Base

Class Method Details

.create(path:) ⇒ BrickFTP::API::FileOperation::UploadingSession

Get uploading URL.

Parameters:

  • path (String) —

    Remote file path.

Returns:

See Also:



32
33
34
35
36
# File 'lib/brick_ftp/api/file_operation/uploading_session.rb', line 32

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

.upload(upload_uri:, data:) ⇒ Object

Upload data.

Parameters:

  • upload_uri (String) —

    A uplading URL.

  • data (IO) —

    An IO object to upload.



43
44
45
46
47
# File 'lib/brick_ftp/api/file_operation/uploading_session.rb', line 43

def self.upload(upload_uri:, data:)
  uri = URI.parse(upload_uri)
  upload_client = BrickFTP::HTTPClient.new(uri.host)
  upload_client.put(uri.to_s, params: data)
end

Instance Method Details

#as_json(*_args) ⇒ Hash

Return single uploading session object.

NOTE: The #as_json method will be overwritten by active_supprt.

Returns:

  • (Hash) —

    a JSON serializable object



89
90
91
# File 'lib/brick_ftp/api/file_operation/uploading_session.rb', line 89

def as_json(*_args)
  properties.dup
end

#at(part_number) ⇒ BrickFTP::API::FileOperation::UploadingSession

Get uploading URL for multi part uploading.

Parameters:

  • part_number (Integer) —

    The part number.

Returns:



54
55
56
57
58
59
# File 'lib/brick_ftp/api/file_operation/uploading_session.rb', line 54

def at(part_number)
  params = { action: 'put', ref: ref, part: part_number }
  api_client = BrickFTP::HTTPClient.new
  res = api_client.post(self.class.api_path_for(:create, path: path), params: params)
  self.class.new(res.symbolize_keys)
end

#commit ⇒ BrickFTP::API::FileOperation::UploadingResult

Complete uploading file.

Returns:



79
80
81
# File 'lib/brick_ftp/api/file_operation/uploading_session.rb', line 79

def commit
  UploadingResult.create(path: path, ref: ref)
end

#each {|session| ... } ⇒ Object

Get each uploading URLs.

Yields:

  • (session) —

    Gives uploading session object to the block.

Yield Parameters:



66
67
68
69
70
71
72
73
# File 'lib/brick_ftp/api/file_operation/uploading_session.rb', line 66

def each
  return enum_for(__method__) unless block_given?

  yield self
  (part_number + 1).upto(available_parts) do |n|
    yield at(n)
  end
end