Class: Ribose::SpaceFile

Inherits:
Base
  • Object
show all
Includes:
Actions::All, Actions::Delete, Actions::Fetch, Actions::Update
Defined in:
lib/ribose/space_file.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Actions::Delete

#delete

Methods included from Actions::Base

#included

Methods included from Actions::Update

#update

Methods included from Actions::Fetch

#fetch

Methods included from Actions::All

#all

Methods inherited from Base

#initialize

Methods included from ResourceHelper

#resource_id, #resource_path, #resources

Constructor Details

This class inherits a constructor from Ribose::Base

Class Method Details

.all(space_id, options = {}) ⇒ Array<Sawyer::Resource>

List Files for Space

This interface retrieves the files for any specific space, and the usages is pretty simple all we need to do, provide the space id and it will return the files as ‘Sawyer::Resource`

Parameters:

  • space_id (String)

    The spcific space Id

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

    Query parameters as a Hash

Returns:

  • (Array<Sawyer::Resource>)


20
21
22
# File 'lib/ribose/space_file.rb', line 20

def self.all(space_id, options = {})
  new(space_id: space_id, **options).all
end

.create(space_id, file:, **attributes) ⇒ Sawyer::Resource

Create a new file upload

Parameters:

  • space_id (String)

    The Space UUID

  • file (String)

    The complete path for the file

  • attributes (Hash)

    The file attributes as Hash

Returns:

  • (Sawyer::Resource)

    The file upload response.



59
60
61
62
# File 'lib/ribose/space_file.rb', line 59

def self.create(space_id, file:, **attributes)
  upload = FileUploader.upload(space_id, attributes.merge(file: file))
  upload[:attachment]
end

.delete(space_id, file_id, options = {}) ⇒ Object

Delete a space file

Parameters:

  • space_id (String)

    The Space UUID

  • file_id (String)

    The space file ID



80
81
82
# File 'lib/ribose/space_file.rb', line 80

def self.delete(space_id, file_id, options = {})
  new(space_id: space_id, resource_id: file_id, **options).delete
end

.download(space_id, file_id, options = {}) ⇒ Object

Download a space file

Parameters:

  • space_id (UUID)

    The Space UUID

  • file_id (Integer)

    The File Id

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

    Options as key and value pair.

    Two important keys are :version_id, and :output and if these are provided then it will use those otherwise it will do additional request to retirve those details



47
48
49
50
# File 'lib/ribose/space_file.rb', line 47

def self.download(space_id, file_id, options = {})
  options[:version_id] ||= fetch(space_id, file_id).current_version_id
  Ribose::FileVersion.download(space_id, file_id, **options)
end

.fetch(space_id, file_id, options = {}) ⇒ Sawyer::Resource

Fetch a space file

This interface retrieve the details for a single file in any given user space. The response is a ‘Sawyer::Resource`.

Parameters:

  • space_id (String)

    The space UUID

  • file_id (String)

    The space file ID

Returns:

  • (Sawyer::Resource)


33
34
35
# File 'lib/ribose/space_file.rb', line 33

def self.fetch(space_id, file_id, options = {})
  new(space_id: space_id, resource_id: file_id, **options).fetch
end

.fetch_icon(space_id, file_id, options = {}) ⇒ Sawyer::Resource

Fetch a space file icon

Parameters:

  • space_id (String)

    The Space UUID

  • file_id (String)

    The space file ID

Returns:

  • (Sawyer::Resource)


94
95
96
# File 'lib/ribose/space_file.rb', line 94

def self.fetch_icon(space_id, file_id, options = {})
  new(space_id: space_id, resource_id: file_id, **options).fetch_icon
end

.update(space_id, file_id, attributes) ⇒ Sawyer::Resource

Update a space file

Parameters:

  • space_id (String)

    The Space UUID

  • file_id (String)

    The space file ID

  • attributes (Hash)

    The file attributes

Returns:

  • (Sawyer::Resource)


71
72
73
# File 'lib/ribose/space_file.rb', line 71

def self.update(space_id, file_id, attributes)
  new(space_id: space_id, resource_id: file_id, **attributes).update
end

Instance Method Details

#fetch_iconObject



84
85
86
# File 'lib/ribose/space_file.rb', line 84

def fetch_icon
  Ribose::Request.get([resource_path, "icon"].join("/"))
end