Class: GroupDocs::Storage::Package

Inherits:
Api::Entity show all
Includes:
Api::Helpers::Path
Defined in:
lib/groupdocs/storage/package.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Api::Helpers::Path

included

Methods inherited from Api::Entity

#initialize, #inspect, #to_hash

Methods included from Api::Helpers::Accessor

#alias_accessor

Constructor Details

This class inherits a constructor from GroupDocs::Api::Entity

Instance Attribute Details

#nameObject



8
9
10
# File 'lib/groupdocs/storage/package.rb', line 8

def name
  @name
end

#objectsObject



10
11
12
# File 'lib/groupdocs/storage/package.rb', line 10

def objects
  @objects
end

Instance Method Details

#add(object) ⇒ Object Also known as: <<

Appends object to be packed.



17
18
19
20
# File 'lib/groupdocs/storage/package.rb', line 17

def add(object)
  @objects ||= Array.new
  @objects << object
end

#create!(access = {}) ⇒ String

Creates package on server.

Parameters:

  • access (Hash) (defaults to: {})

    Access credentials

Options Hash (access):

  • :client_id (String)
  • :private_key (String)

Returns:

  • (String)

    URL of package for downloading



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/groupdocs/storage/package.rb', line 31

def create!(access = {})
  paths = @objects.map do |object|
    prepare_path("#{object.path}/#{object.name}")
  end

  json = Api::Request.new do |request|
    request[:access] = access
    request[:method] = :POST
    request[:path] = "/storage/{{client_id}}/packages/#{name}.zip"
    request[:request_body] = paths
  end.execute!

  json[:url]
end