Class: TelestreamCloud::Uploader

Inherits:
Object
  • Object
show all
Defined in:
lib/telestream_cloud/uploader.rb,
lib/telestream_cloud/uploader/file_reader.rb

Direct Known Subclasses

ParallelUploader

Defined Under Namespace

Classes: FileReader, MissingPartError, UploadError

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Uploader

Returns a new instance of Uploader.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/telestream_cloud/uploader.rb', line 16

def initialize(options)
  file = options.delete(:file) { |key| fail KeyError, "key not found: #{key}" }

  @reader = FileReader.new(file)

  defaults = {
    file_size: reader.size,
    file_name: reader.name,
    multi_chunk: true
  }

  @params = defaults.merge(options)
  @status = :ready
end

Instance Attribute Details

#errorObject (readonly)

Returns the value of attribute error.



9
10
11
# File 'lib/telestream_cloud/uploader.rb', line 9

def error
  @error
end

#readerObject (readonly)

Returns the value of attribute reader.



9
10
11
# File 'lib/telestream_cloud/uploader.rb', line 9

def reader
  @reader
end

#statusObject

Returns the value of attribute status.



9
10
11
# File 'lib/telestream_cloud/uploader.rb', line 9

def status
  @status
end

#videoObject (readonly)

Returns the value of attribute video.



9
10
11
# File 'lib/telestream_cloud/uploader.rb', line 9

def video
  @video
end

Class Method Details

.upload(options) ⇒ Object



11
12
13
14
# File 'lib/telestream_cloud/uploader.rb', line 11

def self.upload(options)
  retries = options.delete(:retries)
  new(options).tap { |x| x.upload(*[retries].compact) }.video
end

Instance Method Details

#success?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/telestream_cloud/uploader.rb', line 46

def success?
  status == :success
end

#upload(retries = 5) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/telestream_cloud/uploader.rb', line 31

def upload(retries = 5)
  count = 0
  begin
    count += 1
    upload!
    fail MissingPartError unless success?
  rescue => e
    @error = e
    retry if count < retries
    self.status = :failed
  end

  success?
end