Class: Kloudless::File

Inherits:
Model
  • Object
show all
Defined in:
lib/kloudless/file.rb

Overview

Class Method Summary collapse

Methods inherited from Model

http, #http, #initialize, #method_missing

Constructor Details

This class inherits a constructor from Kloudless::Model

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Kloudless::Model

Class Method Details

.convert_id(account_id:, raw_id:, type:, params: {}, **data) ⇒ Object



63
64
65
66
67
68
# File 'lib/kloudless/file.rb', line 63

def self.convert_id(account_id:, raw_id:, type:, params: {}, **data)
  path = "/accounts/#{}/storage/convert_id"
  data[:raw_id] = raw_id
  data[:type] = type
  http.post(path, params: params, data: data)
end

.copy(account_id:, file_id:, parent_id:, params: {}, **data) ⇒ Object



42
43
44
45
46
# File 'lib/kloudless/file.rb', line 42

def self.copy(account_id:, file_id:, parent_id:, params: {}, **data)
  path = "/accounts/#{}/storage/files/#{file_id}/copy"
  data[:parent_id] = parent_id
  new(http.post(path, params: params, data: data))
end

.delete(account_id:, file_id:, **params) ⇒ Object



48
49
50
51
# File 'lib/kloudless/file.rb', line 48

def self.delete(account_id:, file_id:, **params)
  path = "/accounts/#{}/storage/files/#{file_id}"
  new(http.delete(path, params: params))
end

.download(account_id:, file_id:, **params) ⇒ Object



37
38
39
40
# File 'lib/kloudless/file.rb', line 37

def self.download(account_id:, file_id:, **params)
  path = "/accounts/#{}/storage/files/#{file_id}/contents"
  http.get(path, params: params, parse_response: false)
end

.metadata(account_id:, file_id:, **params) ⇒ Object



21
22
23
24
# File 'lib/kloudless/file.rb', line 21

def self.(account_id:, file_id:, **params)
  path = "/accounts/#{}/storage/files/#{file_id}"
  new(http.get(path, params: params))
end

.recent(account_ids:, **params) ⇒ Object



53
54
55
56
# File 'lib/kloudless/file.rb', line 53

def self.recent(account_ids:, **params)
  path = "/accounts/#{.join(',')}/storage/recent"
  Kloudless::Collection.new(self, http.get(path, params: params))
end

.rename(account_id:, file_id:, params: {}, **data) ⇒ Object



26
27
28
29
# File 'lib/kloudless/file.rb', line 26

def self.rename(account_id:, file_id:, params: {}, **data)
  path = "/accounts/#{}/storage/files/#{file_id}"
  new(http.patch(path, params: params, data: data))
end

.search(account_ids:, **params) ⇒ Object



58
59
60
61
# File 'lib/kloudless/file.rb', line 58

def self.search(account_ids:, **params)
  path = "/accounts/#{.join(',')}/storage/search"
  Kloudless::Collection.new(self, http.get(path, params: params))
end

.update(account_id:, file_id:, data:) ⇒ Object



31
32
33
34
35
# File 'lib/kloudless/file.rb', line 31

def self.update(account_id:, file_id:, data:)
  path = "/accounts/#{}/storage/files/#{file_id}"
  new(http.put(path, data: data, parse_request: false,
               headers: {'Content-Type' => 'application/octet-stream'}))
end

.upload(account_id:, data:, parent_id:, file_name:, **params) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/kloudless/file.rb', line 6

def self.upload(account_id:, data:, parent_id:, file_name:, **params)
  headers = {
    'X-Kloudless-Metadata' => {parent_id: parent_id, name: file_name}.to_json,
    'Content-Type' => 'application/octet-stream'
  }
  path = "/accounts/#{}/storage/files"
  new(http.post(path, params: params, data: data, headers: headers,
                parse_request: false))
end

.upload_from_url(account_id:, params: {}, **data) ⇒ Object



16
17
18
19
# File 'lib/kloudless/file.rb', line 16

def self.upload_from_url(account_id:, params: {}, **data)
  path = "/accounts/#{}/storage/files"
  new(http.post(path, params: params, data: data))
end