Class: Uploadcare::Resources::Group
- Inherits:
-
BaseResource
- Object
- BaseResource
- Uploadcare::Resources::Group
- Defined in:
- lib/uploadcare/resources/group.rb
Overview
Group resource representing a collection of files in Uploadcare.
Constant Summary collapse
- ATTRIBUTES =
API fields assigned onto group resources.
%i[ id datetime_removed datetime_stored datetime_uploaded is_image is_ready mime_type original_file_url cdn_url original_filename size url uuid variations content_info metadata appdata source datetime_created files_count files ].freeze
Instance Attribute Summary collapse
-
#appdata ⇒ Object
Returns the value of attribute appdata.
-
#cdn_url ⇒ String
Returns the CDN URL for this group.
-
#content_info ⇒ Object
Returns the value of attribute content_info.
-
#datetime_created ⇒ Object
Returns the value of attribute datetime_created.
-
#datetime_removed ⇒ Object
Returns the value of attribute datetime_removed.
-
#datetime_stored ⇒ Object
Returns the value of attribute datetime_stored.
-
#datetime_uploaded ⇒ Object
Returns the value of attribute datetime_uploaded.
-
#files ⇒ Object
Returns the value of attribute files.
-
#files_count ⇒ Object
Returns the value of attribute files_count.
-
#id ⇒ String?
Returns group ID, extracting from CDN URL if needed.
-
#is_image ⇒ Object
Returns the value of attribute is_image.
-
#is_ready ⇒ Object
Returns the value of attribute is_ready.
-
#metadata ⇒ Object
Returns the value of attribute metadata.
-
#mime_type ⇒ Object
Returns the value of attribute mime_type.
-
#original_file_url ⇒ Object
Returns the value of attribute original_file_url.
-
#original_filename ⇒ Object
Returns the value of attribute original_filename.
-
#size ⇒ Object
Returns the value of attribute size.
-
#source ⇒ Object
Returns the value of attribute source.
-
#url ⇒ Object
Returns the value of attribute url.
-
#uuid ⇒ Object
Returns the value of attribute uuid.
-
#variations ⇒ Object
Returns the value of attribute variations.
Class Method Summary collapse
-
.create(uuids:, client: nil, config: Uploadcare.configuration, request_options: {}, **options) ⇒ Uploadcare::Resources::Group
Create a group from file UUIDs.
-
.find(group_id:, client: nil, config: Uploadcare.configuration, request_options: {}) ⇒ Uploadcare::Resources::Group
(also: retrieve, info)
Find a group by ID.
-
.list(params: {}, client: nil, config: Uploadcare.configuration, request_options: {}) ⇒ Uploadcare::Collections::Paginated
List groups with optional filtering and pagination.
Instance Method Summary collapse
-
#delete(request_options: {}) ⇒ nil
Delete this group.
-
#file_cdn_urls ⇒ Array<String>
Returns CDN URLs for all files in the group.
-
#reload(request_options: {}) ⇒ self
(also: #load)
Reload group information from the API.
Instance Attribute Details
#appdata ⇒ Object
Returns the value of attribute appdata.
17 18 19 |
# File 'lib/uploadcare/resources/group.rb', line 17 def appdata @appdata end |
#cdn_url ⇒ String
Returns the CDN URL for this group.
128 129 130 131 132 |
# File 'lib/uploadcare/resources/group.rb', line 128 def cdn_url return @cdn_url if @cdn_url && !@cdn_url.empty? "#{config.cdn_base}#{id}/" end |
#content_info ⇒ Object
Returns the value of attribute content_info.
17 18 19 |
# File 'lib/uploadcare/resources/group.rb', line 17 def content_info @content_info end |
#datetime_created ⇒ Object
Returns the value of attribute datetime_created.
17 18 19 |
# File 'lib/uploadcare/resources/group.rb', line 17 def datetime_created @datetime_created end |
#datetime_removed ⇒ Object
Returns the value of attribute datetime_removed.
17 18 19 |
# File 'lib/uploadcare/resources/group.rb', line 17 def datetime_removed @datetime_removed end |
#datetime_stored ⇒ Object
Returns the value of attribute datetime_stored.
17 18 19 |
# File 'lib/uploadcare/resources/group.rb', line 17 def datetime_stored @datetime_stored end |
#datetime_uploaded ⇒ Object
Returns the value of attribute datetime_uploaded.
17 18 19 |
# File 'lib/uploadcare/resources/group.rb', line 17 def datetime_uploaded @datetime_uploaded end |
#files ⇒ Object
Returns the value of attribute files.
17 18 19 |
# File 'lib/uploadcare/resources/group.rb', line 17 def files @files end |
#files_count ⇒ Object
Returns the value of attribute files_count.
17 18 19 |
# File 'lib/uploadcare/resources/group.rb', line 17 def files_count @files_count end |
#id ⇒ String?
Returns group ID, extracting from CDN URL if needed.
116 117 118 119 120 121 122 123 |
# File 'lib/uploadcare/resources/group.rb', line 116 def id return @id if @id return @uuid if defined?(@uuid) && !@uuid.to_s.empty? return unless @cdn_url uri = URI.parse(@cdn_url) @id = uri.path.split('/').reject(&:empty?).first end |
#is_image ⇒ Object
Returns the value of attribute is_image.
17 18 19 |
# File 'lib/uploadcare/resources/group.rb', line 17 def is_image @is_image end |
#is_ready ⇒ Object
Returns the value of attribute is_ready.
17 18 19 |
# File 'lib/uploadcare/resources/group.rb', line 17 def is_ready @is_ready end |
#metadata ⇒ Object
Returns the value of attribute metadata.
17 18 19 |
# File 'lib/uploadcare/resources/group.rb', line 17 def @metadata end |
#mime_type ⇒ Object
Returns the value of attribute mime_type.
17 18 19 |
# File 'lib/uploadcare/resources/group.rb', line 17 def mime_type @mime_type end |
#original_file_url ⇒ Object
Returns the value of attribute original_file_url.
17 18 19 |
# File 'lib/uploadcare/resources/group.rb', line 17 def original_file_url @original_file_url end |
#original_filename ⇒ Object
Returns the value of attribute original_filename.
17 18 19 |
# File 'lib/uploadcare/resources/group.rb', line 17 def original_filename @original_filename end |
#size ⇒ Object
Returns the value of attribute size.
17 18 19 |
# File 'lib/uploadcare/resources/group.rb', line 17 def size @size end |
#source ⇒ Object
Returns the value of attribute source.
17 18 19 |
# File 'lib/uploadcare/resources/group.rb', line 17 def source @source end |
#url ⇒ Object
Returns the value of attribute url.
17 18 19 |
# File 'lib/uploadcare/resources/group.rb', line 17 def url @url end |
#uuid ⇒ Object
Returns the value of attribute uuid.
17 18 19 |
# File 'lib/uploadcare/resources/group.rb', line 17 def uuid @uuid end |
#variations ⇒ Object
Returns the value of attribute variations.
17 18 19 |
# File 'lib/uploadcare/resources/group.rb', line 17 def variations @variations end |
Class Method Details
.create(uuids:, client: nil, config: Uploadcare.configuration, request_options: {}, **options) ⇒ Uploadcare::Resources::Group
Create a group from file UUIDs.
78 79 80 81 82 83 84 85 86 |
# File 'lib/uploadcare/resources/group.rb', line 78 def self.create(uuids:, client: nil, config: Uploadcare.configuration, request_options: {}, **) resolved_client = resolve_client(client: client, config: config) response = Uploadcare::Result.unwrap( resolved_client.api.upload.groups.create( files: uuids, request_options: , ** ) ) new(response, resolved_client) end |
.find(group_id:, client: nil, config: Uploadcare.configuration, request_options: {}) ⇒ Uploadcare::Resources::Group Also known as: retrieve, info
Find a group by ID.
57 58 59 60 61 62 63 |
# File 'lib/uploadcare/resources/group.rb', line 57 def self.find(group_id:, client: nil, config: Uploadcare.configuration, request_options: {}) resolved_client = resolve_client(client: client, config: config) response = Uploadcare::Result.unwrap( resolved_client.api.rest.groups.info(uuid: group_id, request_options: ) ) new(response, resolved_client) end |
.list(params: {}, client: nil, config: Uploadcare.configuration, request_options: {}) ⇒ Uploadcare::Collections::Paginated
List groups with optional filtering and pagination.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/uploadcare/resources/group.rb', line 30 def self.list(params: {}, client: nil, config: Uploadcare.configuration, request_options: {}) resolved_client = resolve_client(client: client, config: config) response = Uploadcare::Result.unwrap( resolved_client.api.rest.groups.list(params: params, request_options: ) ) groups = response['results'].map { |data| new(data, resolved_client) } Uploadcare::Collections::Paginated.new( resources: groups, next_page: response['next'], previous_page: response['previous'], per_page: response['per_page'], total: response['total'], api_client: resolved_client.api.rest.groups, resource_class: self, client: resolved_client, request_options: ) end |
Instance Method Details
#delete(request_options: {}) ⇒ nil
Delete this group.
107 108 109 110 111 |
# File 'lib/uploadcare/resources/group.rb', line 107 def delete(request_options: {}) Uploadcare::Result.unwrap( client.api.rest.groups.delete(uuid: id, request_options: ) ) end |
#file_cdn_urls ⇒ Array<String>
Returns CDN URLs for all files in the group.
137 138 139 140 141 |
# File 'lib/uploadcare/resources/group.rb', line 137 def file_cdn_urls return [] if files_count.nil? files_count.times.map { |i| "#{cdn_url}nth/#{i}/" } end |
#reload(request_options: {}) ⇒ self Also known as: load
Reload group information from the API.
94 95 96 97 98 99 100 |
# File 'lib/uploadcare/resources/group.rb', line 94 def reload(request_options: {}) response = Uploadcare::Result.unwrap( client.api.rest.groups.info(uuid: id, request_options: ) ) assign_attributes(response) self end |