Class: LoopsSdk::Uploads

Inherits:
Base
  • Object
show all
Defined in:
lib/loops_sdk/uploads.rb

Constant Summary collapse

SUPPORTED_CONTENT_TYPES =
%w[image/jpeg image/png image/gif image/webp].freeze

Class Method Summary collapse

Class Method Details

.upload(path:, content_type: nil) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/loops_sdk/uploads.rb', line 8

def upload(path:, content_type: nil)
  data = File.binread(path)
  content_type ||= detect_content_type(data)
  validate_content_type!(content_type)

  create_response = make_request(
    method: :post,
    path: "v1/uploads",
    body: { contentType: content_type, contentLength: data.bytesize }
  )

  put_to_presigned_url(create_response["presignedUrl"], data, content_type)

  make_request(
    method: :post,
    path: "v1/uploads/#{create_response["emailAssetId"]}/complete"
  )
end