Module: Filespot::Objects
- Included in:
- Client
- Defined in:
- lib/filespot/client/objects.rb
Overview
Objects module wraps methods with ‘/objects` resource
Instance Method Summary collapse
-
#delete_object(object_id) ⇒ Object
DELETE /objects/:object_id returns removal status.
-
#delete_object_by_path(path) ⇒ Object
deletes object which has been found by path.
-
#exists?(path) ⇒ Boolean
checks if object exists.
-
#get_object(object_id) ⇒ Object
GET /objects/:object_id returns an object.
-
#get_object_by_path(path) ⇒ Object
GET /objects/:path returns an objects list.
-
#get_objects(folder = nil) ⇒ Object
GET /objects returns an objects list.
-
#post_object(file, name = nil) ⇒ Object
POST /objects *
file
- file path(required) *name
- name that will be stored in API service returns a file info.
Instance Method Details
#delete_object(object_id) ⇒ Object
DELETE /objects/:object_id returns removal status
39 40 41 42 |
# File 'lib/filespot/client/objects.rb', line 39 def delete_object(object_id) res = Response.new(Request.delete("/objects/#{object_id}")) res end |
#delete_object_by_path(path) ⇒ Object
deletes object which has been found by path
45 46 47 48 49 50 |
# File 'lib/filespot/client/objects.rb', line 45 def delete_object_by_path(path) object = get_object_by_path(path) return delete_object(object.id) if object nil end |
#exists?(path) ⇒ Boolean
checks if object exists
66 67 68 |
# File 'lib/filespot/client/objects.rb', line 66 def exists?(path) !!get_object_by_path(path) end |
#get_object(object_id) ⇒ Object
GET /objects/:object_id returns an object
19 20 21 22 23 |
# File 'lib/filespot/client/objects.rb', line 19 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
GET /objects/:path returns an objects list
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/filespot/client/objects.rb', line 54 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
GET /objects returns an objects list
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
POST /objects
-
file
- file path(required) -
name
- name that will be stored in API service
returns a file info
29 30 31 32 33 34 35 |
# File 'lib/filespot/client/objects.rb', line 29 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 |