Class: KazeClient::UploadImageRequest
- Inherits:
-
KazeClient::Utils::FinalRequest
- Object
- Request
- KazeClient::Utils::FinalRequest
- KazeClient::UploadImageRequest
- 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.
Constant Summary
Constants inherited from Request
Instance Attribute Summary
Attributes included from KazeClient::Utils::AuthentifiedRequest
Attributes inherited from Request
#body, #headers, #method, #query, #url
Instance Method Summary collapse
-
#initialize(filepath) ⇒ UploadImageRequest
constructor
A new instance of UploadImageRequest.
- #send_image(direct_uploads) ⇒ Object
Methods included from KazeClient::Utils::AuthentifiedRequest
Methods inherited from Request
Constructor Details
#initialize(filepath) ⇒ UploadImageRequest
Returns a new instance of UploadImageRequest.
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
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 |