Class: SdrClient::Deposit::Files::DirectUploadRequest

Inherits:
Struct
  • Object
show all
Defined in:
lib/sdr_client/deposit/files/direct_upload_request.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#byte_sizeObject

Returns the value of attribute byte_size

Returns:

  • (Object)

    the current value of byte_size



8
9
10
# File 'lib/sdr_client/deposit/files/direct_upload_request.rb', line 8

def byte_size
  @byte_size
end

#checksumObject

Returns the value of attribute checksum

Returns:

  • (Object)

    the current value of checksum



8
9
10
# File 'lib/sdr_client/deposit/files/direct_upload_request.rb', line 8

def checksum
  @checksum
end

#content_typeObject

Returns the value of attribute content_type

Returns:

  • (Object)

    the current value of content_type



8
9
10
# File 'lib/sdr_client/deposit/files/direct_upload_request.rb', line 8

def content_type
  @content_type
end

#filenameObject

Returns the value of attribute filename

Returns:

  • (Object)

    the current value of filename



8
9
10
# File 'lib/sdr_client/deposit/files/direct_upload_request.rb', line 8

def filename
  @filename
end

Class Method Details

.from_file(path, file_name:, content_type:) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/sdr_client/deposit/files/direct_upload_request.rb', line 9

def self.from_file(path, file_name:, content_type:)
  checksum = Digest::MD5.file(path).base64digest
  new(checksum: checksum,
      byte_size: ::File.size(path),
      content_type: content_type || 'application/octet-stream',
      filename: file_name)
end

Instance Method Details

#as_jsonObject



17
18
19
20
21
# File 'lib/sdr_client/deposit/files/direct_upload_request.rb', line 17

def as_json
  {
    blob: { filename: filename, byte_size: byte_size, checksum: checksum, content_type: content_type }
  }
end

#to_json(*_args) ⇒ Object



23
24
25
# File 'lib/sdr_client/deposit/files/direct_upload_request.rb', line 23

def to_json(*_args)
  JSON.generate(as_json)
end