Class: Uploadcare::Client::RestGroupClient

Inherits:
RestClient
  • Object
show all
Defined in:
lib/uploadcare/client/rest_group_client.rb

Overview

Instance Method Summary collapse

Methods inherited from RestClient

#api_root, #api_struct_delete, #api_struct_get, #api_struct_post, #api_struct_put, #get, #headers, #post, #put, #request

Methods included from Uploadcare::Concerns::ThrottleHandler

#handle_throttling

Methods included from Uploadcare::Concerns::ErrorHandler

#failure, #wrap

Instance Method Details

#delete(uuid) ⇒ Object

Delete a file group by its ID.



38
39
40
# File 'lib/uploadcare/client/rest_group_client.rb', line 38

def delete(uuid)
  request(method: 'DELETE', uri: "/groups/#{uuid}/")
end

#info(uuid) ⇒ Object

Get a file group by its ID.



25
26
27
# File 'lib/uploadcare/client/rest_group_client.rb', line 25

def info(uuid)
  get(uri: "/groups/#{uuid}/")
end

#list(options = {}) ⇒ Object

return paginated list of groups



31
32
33
34
# File 'lib/uploadcare/client/rest_group_client.rb', line 31

def list(options = {})
  query = options.empty? ? '' : "?#{URI.encode_www_form(options)}"
  get(uri: "/groups/#{query}")
end

#store(uuid) ⇒ Object

store all files in a group



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/uploadcare/client/rest_group_client.rb', line 11

def store(uuid)
  files = info(uuid).success[:files].compact
  client = ::Uploadcare::Client::FileClient.new
  files.each_slice(Uploadcare.config.file_chunk_size) do |file_chunk|
    file_chunk.each do |file|
      client.store(file[:uuid])
    end
  end

  Dry::Monads::Result::Success.call(nil)
end