Sha256: 7e014f56b6004b8a1f8ada23ac26cce10d6d010f276a8abc5832a40c42f665f3

Contents?: true

Size: 795 Bytes

Versions: 121

Compression:

Stored size: 795 Bytes

Contents

# frozen_string_literal: true

require 'digest'

module SdrClient
  module Deposit
    module Files
      DirectUploadRequest = Struct.new(:checksum, :byte_size, :content_type, :filename, keyword_init: true) do
        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

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

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

Version data entries

121 entries across 121 versions & 1 rubygems

Version Path
sdr-client-2.4.0 lib/sdr_client/deposit/files/direct_upload_request.rb
sdr-client-2.3.1 lib/sdr_client/deposit/files/direct_upload_request.rb
sdr-client-2.3.0 lib/sdr_client/deposit/files/direct_upload_request.rb
sdr-client-2.2.0 lib/sdr_client/deposit/files/direct_upload_request.rb
sdr-client-2.1.0 lib/sdr_client/deposit/files/direct_upload_request.rb
sdr-client-2.0.1 lib/sdr_client/deposit/files/direct_upload_request.rb
sdr-client-2.0.0 lib/sdr_client/deposit/files/direct_upload_request.rb
sdr-client-1.0.0 lib/sdr_client/deposit/files/direct_upload_request.rb
sdr-client-0.97.0 lib/sdr_client/deposit/files/direct_upload_request.rb
sdr-client-0.96.0 lib/sdr_client/deposit/files/direct_upload_request.rb
sdr-client-0.95.0 lib/sdr_client/deposit/files/direct_upload_request.rb
sdr-client-0.94.0 lib/sdr_client/deposit/files/direct_upload_request.rb
sdr-client-0.93.0 lib/sdr_client/deposit/files/direct_upload_request.rb
sdr-client-0.92.0 lib/sdr_client/deposit/files/direct_upload_request.rb
sdr-client-0.91.0 lib/sdr_client/deposit/files/direct_upload_request.rb
sdr-client-0.90.0 lib/sdr_client/deposit/files/direct_upload_request.rb
sdr-client-0.89.0 lib/sdr_client/deposit/files/direct_upload_request.rb
sdr-client-0.88.0 lib/sdr_client/deposit/files/direct_upload_request.rb
sdr-client-0.87.0 lib/sdr_client/deposit/files/direct_upload_request.rb
sdr-client-0.86.0 lib/sdr_client/deposit/files/direct_upload_request.rb