Module: Filespot::Download
- Included in:
- Client
- Defined in:
- lib/filespot/client/download.rb
Overview
Download module wraps methods with ‘/download` resource
Constant Summary collapse
- STATUS_ERROR =
'Error'.freeze
Instance Method Summary collapse
-
#delete_download_task(task_id) ⇒ Object
DELETE /download_tasks/:task_id returns removal status.
-
#get_download_task(task_id) ⇒ Object
GET /download_tasks/:task_id returns task data.
-
#get_download_tasks ⇒ Object
GET /download_tasks returns tasks list.
-
#post_download(url, path = nil) ⇒ Object
POST /download returns task_id.
Instance Method Details
#delete_download_task(task_id) ⇒ Object
DELETE /download_tasks/:task_id returns removal status
40 41 42 43 |
# File 'lib/filespot/client/download.rb', line 40 def delete_download_task(task_id) res = Response.new(Request.delete("/download_tasks/#{task_id}")) res end |
#get_download_task(task_id) ⇒ Object
GET /download_tasks/:task_id returns task data
29 30 31 32 33 34 35 36 |
# File 'lib/filespot/client/download.rb', line 29 def get_download_task(task_id) res = Response.new(Request.get("/download_tasks/#{task_id}")) return nil unless res.code == 200 task = Task.new(res.data['task'], res.data['files']) raise(Filespot::TaskError, task.body) if task.status == STATUS_ERROR task end |
#get_download_tasks ⇒ Object
GET /download_tasks returns tasks list
17 18 19 20 21 22 23 24 25 |
# File 'lib/filespot/client/download.rb', line 17 def get_download_tasks res = Response.new(Request.get("/download_tasks")) return [] unless res.code == 200 arr = [] count, tasks = res.data['count'].to_i, res.data['tasks'] count.times { |i| arr << Task.new(tasks[i]) } arr end |
#post_download(url, path = nil) ⇒ Object
POST /download returns task_id
9 10 11 12 13 |
# File 'lib/filespot/client/download.rb', line 9 def post_download(url, path = nil) res = Response.new(Request.post("/download", {}, { url: url, path: path })) return nil unless res.code == 200 res.data['task_id'] end |