Class: KazeClient::UploadAttachmentRequest

Inherits:
KazeClient::Utils::FinalRequest show all
Includes:
KazeClient::Utils::AuthentifiedRequest
Defined in:
lib/kaze_client/request/requests/upload_attachment_request.rb

Overview

Upload an ActiveStorage::Attachment to a job document from a job.

Examples:

How to use

rq = KazeClient::UploadAttachmentRequest.new(f).with_token(TOKEN)
response = KazeClient::Client.new(URL).execute(rq)
rq.send_attachment(response['direct_upload'])

See Also:

Author:

Since:

  • 0.3.2

Constant Summary

Constants inherited from Request

Request::DEFAULT_HEADERS

Instance Attribute Summary

Attributes included from KazeClient::Utils::AuthentifiedRequest

#token

Attributes inherited from Request

#body, #headers, #method, #query, #url

Instance Method Summary collapse

Methods included from KazeClient::Utils::AuthentifiedRequest

#with_token

Methods inherited from Request

#error_for, #parameters

Constructor Details

#initialize(attachment) ⇒ UploadAttachmentRequest

Returns a new instance of UploadAttachmentRequest.

Parameters:

  • attachment (ActiveStorage::Attachment)

Since:

  • 0.3.2



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/kaze_client/request/requests/upload_attachment_request.rb', line 20

def initialize(attachment)
  super(:post, 'api/direct_uploads')

  # @type [ActiveStorage::Attachment]
  @attachment = attachment

  @body = {
    blob: {
      filename:     @attachment.filename,
      byte_size:    @attachment.byte_size,
      checksum:     @attachment.checksum,
      content_type: @attachment.content_type
    }
  }
end

Instance Method Details

#send_attachment(direct_uploads) ⇒ Object

Since:

  • 0.3.2



36
37
38
39
# File 'lib/kaze_client/request/requests/upload_attachment_request.rb', line 36

def send_attachment(direct_uploads)
  header = direct_uploads['headers']
  HTTParty.put(direct_uploads['url'], { body: @attachment.download, headers: header })
end