Module: Filespot::Objects

Included in:
Client
Defined in:
lib/filespot/client/objects.rb

Instance Method Summary collapse

Instance Method Details

#delete_object(object_id) ⇒ Object



27
28
29
30
# File 'lib/filespot/client/objects.rb', line 27

def delete_object(object_id)
  res = Response.new(Request.delete("/objects/#{object_id}"))
  res
end

#get_object(object_id) ⇒ Object



13
14
15
16
17
# File 'lib/filespot/client/objects.rb', line 13

def get_object(object_id)
  res = Response.new(Request.get("/objects/#{object_id}"))
  return nil unless res.code == 200
  Object.new(res.data['object'])
end

#get_objectsObject



3
4
5
6
7
8
9
10
11
# File 'lib/filespot/client/objects.rb', line 3

def get_objects
  res = Response.new(Request.get("/objects"))
  return [] unless res.code == 200

  arr = []
  count, objects = res.data['count'].to_i, res.data['objects']
  count.times { |i| arr << Object.new(objects[i]) }
  arr
end

#post_object(file, name = nil) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/filespot/client/objects.rb', line 19

def post_object(file, name = nil)
  file_io = Faraday::UploadIO.new(file, 'application/octet-stream')
  res = Response.new(Request.post("/objects", {}, { file: file_io, name: name }))
  return res unless res.code == 200

  Object.new(res.data['object'])
end