Class: Deta::DriveResource

Inherits:
Resource show all
Defined in:
lib/deta/resources/drive.rb

Constant Summary collapse

@@api_url =
"https://drive.deta.sh/v1"

Instance Attribute Summary

Attributes inherited from Resource

#client, #resource_name

Instance Method Summary collapse

Methods inherited from Resource

#initialize

Constructor Details

This class inherits a constructor from Deta::Resource

Instance Method Details

#delete(attributes) ⇒ Object



38
39
40
41
42
43
44
45
46
47
# File 'lib/deta/resources/drive.rb', line 38

def delete(attributes)
  params = {}
  if attributes.is_a?(Array)
    params[:names] = attributes
  else
    params[:names] = [attributes]
  end

  DriveObject.new delete_request_with_body([@@api_url, client.project_id, resource_name, "files"].join("/"), body: params).body
end

#get(name = nil) ⇒ Object



22
23
24
25
26
27
# File 'lib/deta/resources/drive.rb', line 22

def get(name = nil)
  params = {}
  params[:name] = name if name

  get_request([@@api_url, client.project_id, resource_name, "files", "download"].join("/"), params: params).body
end

#list(limit: nil, prefix: nil, last: nil) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/deta/resources/drive.rb', line 29

def list(limit: nil, prefix: nil, last: nil)
  params = {}
  params[:limit] = limit if limit
  params[:prefix] = prefix if prefix
  params[:last] = last if last

  DriveObject.new get_request([@@api_url, client.project_id, resource_name, "files"].join("/"), params: params).body
end

#put(name = nil, path: nil, data: nil, content_type: "application/octet-stream") ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/deta/resources/drive.rb', line 5

def put(name = nil, path: nil, data: nil, content_type: "application/octet-stream")
  payload = nil
  headers = {"Content-Type": content_type}
  
  if path
    payload = Faraday::Multipart::FilePart.new(path, content_type, name)
    headers["Content-Length"] = payload.size.to_s
  end

  if data
    headers["Content-Length"] = data.size.to_s
    payload = data 
  end
  
  DriveObject.new post_request([@@api_url, client.project_id, resource_name, "files?name=#{name}"].join("/"), body: payload, headers: headers).body
end