Class: Scale::Api::Tasks
- Inherits:
-
Struct
- Object
- Struct
- Scale::Api::Tasks
- Defined in:
- lib/scale/api/tasks.rb,
lib/scale/api/tasks/base_task.rb
Defined Under Namespace
Classes: BaseTask
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
Instance Method Summary collapse
- #cancel(task_id) ⇒ Object
- #create(args = {}) ⇒ Object
- #find(task_id) ⇒ Object
- #list(start_time: nil, end_time: nil, limit: 99, offset: 0, type: nil, status: nil) ⇒ Object (also: #all, #where)
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client
3 4 5 |
# File 'lib/scale/api/tasks.rb', line 3 def client @client end |
Instance Method Details
#cancel(task_id) ⇒ Object
38 39 40 41 |
# File 'lib/scale/api/tasks.rb', line 38 def cancel(task_id) response = client.post("task/#{task_id}/cancel") BaseTask.new(JSON.parse(response.body), client) end |
#create(args = {}) ⇒ Object
43 44 45 46 47 |
# File 'lib/scale/api/tasks.rb', line 43 def create(args = {}) raise ArgumentError.new('Task type is required') if (args[:type].nil? && args['type'].nil?) type = args.delete(:type) client.create_task(type, args) end |
#find(task_id) ⇒ Object
33 34 35 36 |
# File 'lib/scale/api/tasks.rb', line 33 def find(task_id) response = client.get("task/#{task_id}") BaseTask.new(JSON.parse(response.body), client) end |
#list(start_time: nil, end_time: nil, limit: 99, offset: 0, type: nil, status: nil) ⇒ Object Also known as: all, where
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/scale/api/tasks.rb', line 4 def list(start_time: nil, end_time: nil, limit: 99, offset: 0, type: nil, status: nil) if start_time and not start_time.instance_of? String start_time = start_time.iso8601 end if end_time and not end_time.instance_of? String end_time = end_time.iso8601 end params = { start_time: start_time ? start_time : nil, end_time: end_time ? end_time : nil, limit: limit, offset: offset, status: status, type: type } response = client.get('tasks', params) body = JSON.parse(response.body) TaskList.new({ client: client, docs: body['docs'], limit: body['limit'], offset: body['offset'], has_more: body['has_more'], params: params }) end |