Class: BaseCradle::TimelineAssets

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/basecradle/items.rb

Overview

One timeline’s assets: upload here (multipart), or iterate (newest first).

Instance Method Summary collapse

Constructor Details

#initialize(client, timeline_uuid) ⇒ TimelineAssets

Returns a new instance of TimelineAssets.



164
165
166
167
# File 'lib/basecradle/items.rb', line 164

def initialize(client, timeline_uuid)
  @client = client
  @timeline_uuid = timeline_uuid
end

Instance Method Details

#create(file:, description: nil) ⇒ Object

Upload a file to this timeline. file is a path or a binary IO; description optional.



170
171
172
173
174
175
176
177
178
179
180
# File 'lib/basecradle/items.rb', line 170

def create(file:, description: 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)
  ensure
    io.close if opened
  end
  Asset.new(response.fetch("asset"), client: @client)
end

#each(&block) ⇒ Object



182
183
184
# File 'lib/basecradle/items.rb', line 182

def each(&block)
  AssetsResource.new(@client).filter(timeline: @timeline_uuid).each(&block)
end