Module: StrawberryAPI::Client::Assets

Included in:
StrawberryAPI::Client
Defined in:
lib/strawberry_api/client/assets.rb

Instance Method Summary collapse

Instance Method Details

#asset(id:, path: nil) ⇒ StrawberryAPI::Asset

Fetches an asset

Parameters:

  • id (Integer)

    Id of the asset to retrieve

Returns:



22
23
24
25
26
27
28
29
30
# File 'lib/strawberry_api/client/assets.rb', line 22

def asset(id:, path: nil)
  if path.nil?
    data = get("/assets/#{id}").parse['asset']
  else
    data = get("/assets/by_path", body: path.to_json).parse['asset']
  end

  data.nil? ? nil : Asset.new(data)
end

#asset_custom_metadata(id:) ⇒ Array<Hash>

Fetches an asset custom metadata

Parameters:

  • id (Integer)

    Id of the asset to retrieve metadata from

Returns:

  • (Array<Hash>)

    The fetched asset custom metadata



74
75
76
# File 'lib/strawberry_api/client/assets.rb', line 74

def (id:)
  data = get("/assets/#{id}/custom_metadata").parse['array']
end

Fetches an asset links

Parameters:

  • ids (Integer)

    Ids of the asset to retrieve links from

Returns:

  • (Array<Hash>)

    The retrieved asset links



38
39
40
41
42
# File 'lib/strawberry_api/client/assets.rb', line 38

def asset_links(ids:)
  get("/assets/links", body: {asset_ids: ids}.to_json).parse['links']&.map do |link|
    link
  end
end

#asset_marker_descriptions(id:) ⇒ Array<StrawberryAPI::Marker>

Fetches an asset marker descriptions

Parameters:

  • id (Integer)

    Id of the asset to retrieve marker descriptions from

Returns:



50
51
52
53
54
55
# File 'lib/strawberry_api/client/assets.rb', line 50

def asset_marker_descriptions(id:)
  data = get("/assets/#{id}/marker_descriptions").parse['array']
  data.map do |marker|
    marker.nil? ? nil : Marker.new(marker)
  end
end

#assetsArray<StrawberryAPI::Asset>

Fetches all assets

Returns:



10
11
12
13
14
# File 'lib/strawberry_api/client/assets.rb', line 10

def assets
  get("/assets").parse['assets']&.map do |asset|
    Asset.new(asset)
  end
end

#delete_assets(project_id:, asset_ids:) ⇒ Boolean

Deletes a project assets

Parameters:

  • project_id (Integer)

    Id of the project to delete assets from

  • asset_ids (Array<Integer>)

    Ids of the assets to delete

Returns:

  • (Boolean)

    Success



64
65
66
# File 'lib/strawberry_api/client/assets.rb', line 64

def delete_assets(project_id:, asset_ids:)
  delete("/assets/destroy", body: {data: {project_id => {asset_ids: asset_ids}}}).success?
end

#update_asset_custom_metadata(id:, custom_metadata:) ⇒ Boolean

Updates an asset custom metadata

Parameters:

  • id (Integer)

    Id of the asset which to update custom metadata

  • custom_metadata (Hash)

    Custom metadata to update the asset with

Returns:

  • (Boolean)

    Success



85
86
87
88
# File 'lib/strawberry_api/client/assets.rb', line 85

def (id:, custom_metadata:)
  filthy_hash = StrawberryAPI::CustomMetadatum.filthify(custom_metadata: )
  put("/assets/#{id}/update_metadata", query: filthy_hash).success?
end