Class: RepositoryClient::Deposit::Files::DirectUploadRequest

Inherits:
Struct
  • Object
show all
Defined in:
lib/repository_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/repository_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/repository_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/repository_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/repository_client/deposit/files/direct_upload_request.rb', line 8

def filename
  @filename
end

Class Method Details

.from_file(filename) ⇒ Object



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

def self.from_file(filename)
  checksum = Digest::MD5.file(filename).base64digest
  new(checksum: checksum,
      byte_size: File.size(filename),
      content_type: 'text/html',
      filename: File.basename(filename))
end

Instance Method Details

#as_jsonObject



17
18
19
20
21
# File 'lib/repository_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/repository_client/deposit/files/direct_upload_request.rb', line 23

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