module StrawberryAPI::Client::Libraries

Public Instance Methods

create_library(project_id:, ingest_storage: 'media_1', ingest_path:, external: false, options: {mxf_handling: false}) click to toggle source

Creates a library

@param [Integer] project_id Id of the project where to ingest media @param [String] ingest_storage Name of the storage to ingest into @param [<type>] ingest_path Watchfoler path @param [<type>] external false Whether to keep in place ingest media @param [<type>] options {mxf_handling: false} Hash of options

@return [StrawberryAPI::Library] The created library

# File lib/strawberry_api/client/libraries.rb, line 38
def create_library(project_id:, ingest_storage: 'media_1', ingest_path:, external: false, options: {mxf_handling: false})
  update_project(id: project_id, options: {is_library_project: true, encoding_priority: 'high'})

  body = {
    project_id: project_id,
    ingest_storage: ingest_storage,
    ingest_path: ingest_path,
    external: external,
    options: options
  }.to_json

  job = post("/library_ingests", body: body).parse['job']

  count = 0
  library = nil
  # This is awful
  while library.nil? && count < 10
    sleep 1
    count += 1
    library = library(project_id: job['project_id'])
  end

  job.nil? ? nil : library
end
delete_library(id:) click to toggle source

Deletes a library

@param [Integer] id Id of the library to delete

@return [Boolean] Success

# File lib/strawberry_api/client/libraries.rb, line 69
def delete_library(id:)
  delete("/library_ingests/#{id}").success?
end
libraries() click to toggle source

Fetches all libraries

@return [Array<StrawberryAPI::Library>] A list of libraries

# File lib/strawberry_api/client/libraries.rb, line 10
def libraries
  get("/library_ingests").parse['array']&.map do |library|
    Library.new(library)
  end
end
library(id: nil, project_id: nil) click to toggle source

Fetches a library

@param [Integer] id Id of the library to retrieve

@return [StrawberryAPI::Library] The fetched library

# File lib/strawberry_api/client/libraries.rb, line 22
def library(id: nil, project_id: nil)
  libraries.find do |library|
    library.id == id.to_i || library.project_id == project_id.to_i
  end
end