Module: Filespot::Objects
- Included in:
- Client
- Defined in:
- lib/filespot/client/objects.rb
Instance Method Summary collapse
- #delete_object(object_id) ⇒ Object
- #delete_object_by_path(path) ⇒ Object
- #exists?(path) ⇒ Boolean
- #get_object(object_id) ⇒ Object
- #get_object_by_path(path) ⇒ Object
- #get_objects(folder = nil) ⇒ Object
- #post_object(file, name = nil) ⇒ Object
Instance Method Details
#delete_object(object_id) ⇒ Object
31 32 33 34 |
# File 'lib/filespot/client/objects.rb', line 31 def delete_object(object_id) res = Response.new(Request.delete("/objects/#{object_id}")) res end |
#delete_object_by_path(path) ⇒ Object
36 37 38 39 40 |
# File 'lib/filespot/client/objects.rb', line 36 def delete_object_by_path(path) object = get_object_by_path path return delete_object(object.id) if object nil end |
#exists?(path) ⇒ Boolean
3 4 5 |
# File 'lib/filespot/client/objects.rb', line 3 def exists?(path) !!get_object_by_path(path) end |
#get_object(object_id) ⇒ Object
17 18 19 20 21 |
# File 'lib/filespot/client/objects.rb', line 17 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_object_by_path(path) ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/filespot/client/objects.rb', line 42 def get_object_by_path(path) full_path = path[0] == '/' ? path : "/#{path}" folder = File.dirname full_path get_objects(folder).each do |object| return object if object.path == full_path end nil end |
#get_objects(folder = nil) ⇒ Object
7 8 9 10 11 12 13 14 15 |
# File 'lib/filespot/client/objects.rb', line 7 def get_objects(folder=nil) res = Response.new(Request.get("/objects", folder: folder)) 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
23 24 25 26 27 28 29 |
# File 'lib/filespot/client/objects.rb', line 23 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 |