class Uploadcare::Client::GroupClient

Groups serve a purpose of better organizing files in your Uploadcare projects. You can create one from a set of files by using their UUIDs. @see uploadcare.com/docs/api_reference/upload/groups/

Public Instance Methods

create(file_list, **options) click to toggle source

Create files group from a set of files by using their UUIDs. @see uploadcare.com/api-refs/upload-api/#operation/createFilesGroup

# File lib/uploadcare/client/group_client.rb, line 13
def create(file_list, **options)
  body_hash = group_body_hash(file_list, **options)
  body = HTTP::FormData::Multipart.new(body_hash)
  post(path: 'group/',
       headers: { 'Content-type': body.content_type },
       body: body)
end
info(group_id) click to toggle source

Get group info @see uploadcare.com/api-refs/upload-api/#operation/filesGroupInfo

# File lib/uploadcare/client/group_client.rb, line 23
def info(group_id)
  get(path: 'group/info/', params: { 'pub_key': Uploadcare.config.public_key, 'group_id': group_id })
end

Private Instance Methods

file_params(file_ids) click to toggle source
# File lib/uploadcare/client/group_client.rb, line 29
def file_params(file_ids)
  ids = (0...file_ids.size).map { |i| "files[#{i}]" }
  ids.zip(file_ids).to_h
end
group_body_hash(file_list, **options) click to toggle source
# File lib/uploadcare/client/group_client.rb, line 34
def group_body_hash(file_list, **options)
  { pub_key: Uploadcare.config.public_key }.merge(file_params(parse_file_list(file_list))).merge(**options)
end
parse_file_list(file_list) click to toggle source

API accepts only list of ids, but some users may want to upload list of files @return [Array] of [String]

# File lib/uploadcare/client/group_client.rb, line 40
def parse_file_list(file_list)
  file_list.map { |file| file.methods.include?(:uuid) ? file.uuid : file }
end