Sha256: 1c07086c9113de9118cf6b4158ad22126a69804d568fc87a4061e44fc54d1584

Contents?: true

Size: 1.18 KB

Versions: 7

Compression:

Stored size: 1.18 KB

Contents

# frozen_string_literal: true

require 'uploadcare/entity/file'

module Uploadcare
  module Entity
    # 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 https://uploadcare.com/docs/api_reference/upload/groups/
    class Group < Entity
      client_service RestGroupClient, prefix: 'rest', only: :store
      client_service GroupClient

      attr_entity :id, :datetime_created, :datetime_stored, :files_count, :cdn_url, :url
      has_entities :files, as: Uploadcare::Entity::File

      # Remove these lines and bump api_struct version when this PR is accepted:
      # @see https://github.com/rubygarage/api_struct/pull/15
      def self.store(uuid)
        rest_store(uuid)
      end

      # gets groups's id - even if it's only initialized with cdn_url
      # @return [String]
      def id
        return @entity.id if @entity.id

        id = @entity.cdn_url.gsub('https://ucarecdn.com/', '')
        id.gsub(%r{/.*}, '')
      end

      # loads group metadata, if it's initialized with url or id
      def load
        initialize(Group.info(id).entity)
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
uploadcare-ruby-3.3.2 lib/uploadcare/entity/group.rb
uploadcare-ruby-3.3.1 lib/uploadcare/entity/group.rb
uploadcare-ruby-3.3.0 lib/uploadcare/entity/group.rb
uploadcare-ruby-3.2.0 lib/uploadcare/entity/group.rb
uploadcare-ruby-3.1.1 lib/uploadcare/entity/group.rb
uploadcare-ruby-3.1.0 lib/uploadcare/entity/group.rb
uploadcare-ruby-3.1.0.pre.rc1 lib/uploadcare/entity/group.rb