Module: Uploadcare::GroupApi

Included in:
Api
Defined in:
lib/uploadcare/api/group_api.rb

Instance Method Summary collapse

Instance Method Details

#create_group(ary) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/uploadcare/api/group_api.rb', line 9

def create_group ary
  unless ary.kind_of?(Array)
    raise ArgumentError.new "You should send and array of files or valid UUIDs"
  else
    if ary.select {|f| !!f.kind_of?(Uploadcare::Api::File) }.any?
      files = Hash.new
      ary.each_with_index do |file, i|
        files["files[#{i}]"] = file.uuid
      end
    elsif ary.select {|f| !!f.kind_of?(String) }.any?
      files = Hash.new
      ary.each_with_index do |uuid, i|
        files["files[#{i}]"] = uuid
      end
    else
      raise ArgumentError.new "You should send and array of files or valid UUIDs"
    end
  end


  data = {
    pub_key: @options[:public_key],
  }

  data.merge! files
  post = @upload_connection.send :post, "/group/", data
  group = Uploadcare::Api::Group.new self, post.body["id"], post.body
end

#group(uuid_or_cdn_url) ⇒ Object



4
5
6
# File 'lib/uploadcare/api/group_api.rb', line 4

def group uuid_or_cdn_url
  group = Uploadcare::Api::Group.new self, uuid_or_cdn_url
end