Class: KazeClient::UploadImageRequest

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

Overview

Upload an image to a job document from a job.

Examples:

How to use

request  = KazeClient::UploadImageRequest.new(Rails.root.join('public/images/test.jpg'))
response = KazeClient::Client.new(URL).execute(request)
request.send_image(response['direct_upload'])

See Also:

Author:

Since:

  • 0.3.0

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(filepath) ⇒ UploadImageRequest

Returns a new instance of UploadImageRequest.

Since:

  • 0.3.0



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

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

  @filepath = filepath.is_a?(Pathname) ? filepath : Pathname.new(filepath.to_s)
  @filename = @filepath.basename.to_s

  @body = {
    blob: {
      filename: @filename, byte_size: File.size(@filepath),
      checksum: Digest::MD5.base64digest(@filepath.read),
      content_type: "image/#{@filename.split('.')[1]}"
    }
  }
end

Instance Method Details

#send_image(direct_uploads) ⇒ Object

Since:

  • 0.3.0



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

def send_image(direct_uploads)
  body   = @filepath.read
  header = direct_uploads['headers']
  HTTParty.put(direct_uploads['url'], { body: body, headers: header })
end