Class: BaseCradle::TimelineAssets
- Inherits:
-
Object
- Object
- BaseCradle::TimelineAssets
- Includes:
- Enumerable
- Defined in:
- lib/basecradle/items.rb
Overview
One timeline's assets: upload here (multipart), or iterate (newest first).
Instance Method Summary collapse
-
#create(file:, description: nil, idempotency_key: nil) ⇒ Object
Upload a file to this timeline.
- #each(&block) ⇒ Object
-
#initialize(client, timeline_uuid) ⇒ TimelineAssets
constructor
A new instance of TimelineAssets.
Constructor Details
#initialize(client, timeline_uuid) ⇒ TimelineAssets
Returns a new instance of TimelineAssets.
171 172 173 174 |
# File 'lib/basecradle/items.rb', line 171 def initialize(client, timeline_uuid) @client = client @timeline_uuid = timeline_uuid end |
Instance Method Details
#create(file:, description: nil, idempotency_key: nil) ⇒ Object
Upload a file to this timeline. file is a path or a binary IO; description optional.
idempotency_key (optional, a UUID recommended) makes the upload safe to retry: the
platform stores at most one asset per key, so a resend returns the original asset
instead of uploading a second one. See BaseCradle::Client#max_retries.
181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/basecradle/items.rb', line 181 def create(file:, description: nil, idempotency_key: nil) filename, io, opened = open_upload(file) parts = [ [ "asset[file]", io, { filename: filename } ] ] parts << [ "asset[description]", description ] unless description.nil? begin response = @client.request("POST", "/timelines/#{@timeline_uuid}/assets", form: parts, headers: BaseCradle.idempotency_headers(idempotency_key)) ensure io.close if opened end Asset.new(response.fetch("asset"), client: @client) end |
#each(&block) ⇒ Object
194 195 196 |
# File 'lib/basecradle/items.rb', line 194 def each(&block) AssetsResource.new(@client).filter(timeline: @timeline_uuid).each(&block) end |