-def tag_remove(tag, obj_uuid=nil)
- request_body = {
- :api_token => ENV['ARVADOS_API_TOKEN'],
- :link => {
- :name => tag,
- :link_class => :tag,
- :head_uuid => obj_uuid,
- }
- }
+def tag_add(tag, obj_uuid)
+ return api_call($arvados.links.create,
+ request_body: {
+ :link => {
+ :name => tag,
+ :link_class => :tag,
+ :head_uuid => obj_uuid,
+ }
+ })
+end
+
+def tag_remove(tag, obj_uuids=nil)
+ # If we got a list of objects to untag, look up the uuids for the
+ # links that need to be deleted.
+ link_uuids = []
+ if obj_uuids
+ obj_uuids.each do |uuid|
+ link = api_call($arvados.links.list,
+ request_body: {
+ :where => {
+ :link_class => :tag,
+ :name => tag,
+ :head_uuid => uuid,
+ }
+ })
+ if link['items_available'] > 0
+ link_uuids.push link['items'][0]['uuid']
+ end
+ end
+ else
+ all_tag_links = api_call($arvados.links.list,
+ request_body: {
+ :where => {
+ :link_class => :tag,
+ :name => tag,
+ }
+ })
+ link_uuids = all_tag_links['items'].map { |obj| obj['uuid'] }
+ end