class Manatoo::Task

Constants

ATTRIBUTES_STRUCT
TASK_KEYS

Attributes

attributes[R]
last_json_response[R]

Public Class Methods

add_labels(task_id, labels) click to toggle source

labels should not be empty, should be array

# File lib/manatoo/task.rb, line 112
def self.add_labels(task_id, labels)
  url = "tasks/#{task_id}/labels"
  resp = Manatoo.post(url, {
    labels: labels
  })
  JSON.parse(resp.body).to_snake_keys
end
add_users(task_id, users) click to toggle source

users should not be empty, should be array

# File lib/manatoo/task.rb, line 140
def self.add_users(task_id, users)
  url = "tasks/#{task_id}/users"
  resp = Manatoo.post(url, {
    users: users
  })
  JSON.parse(resp.body).to_snake_keys
end
add_weight(task_id, weight) click to toggle source

weight REQUIRED, should be integer

# File lib/manatoo/task.rb, line 126
def self.add_weight(task_id, weight)
  url = "tasks/#{task_id}/weight"
  resp = Manatoo.post(url, {
    weight: weight
  })
  JSON.parse(resp.body).to_snake_keys
end
create(attrs, return_task=false) click to toggle source

list_id, title REQUIRED

# File lib/manatoo/task.rb, line 48
def self.create(attrs, return_task=false)
  raise ArgumentError.new('Task attributes must be passed in as a Hash') unless attrs.is_a?(Hash)

  list_id = attrs[:list_id]
  title = attrs[:title]
  raise ArgumentError.new(
    'Both list_id and title must be passed in and not blank'
  ) if list_id.nil? or list_id.empty? or title.nil? or title.empty?

  url = "tasks"
  resp = Manatoo.post(url, attrs.merge({
      title: title,
      list_id: list_id,
    }))
  snake_cased_json = JSON.parse(resp.body).to_snake_keys
  attrs = snake_cased_json['data']
  return Task.new(attrs, snake_cased_json) if return_task
  return snake_cased_json
end
find(task_id, return_task=false) click to toggle source

task_id REQUIRED

# File lib/manatoo/task.rb, line 69
def self.find(task_id, return_task=false)
  url = "tasks/#{task_id}"
  resp = Manatoo.get(url)
  snake_cased_json = JSON.parse(resp.body).to_snake_keys
  attrs = snake_cased_json['data']
  return Task.new(attrs, snake_cased_json) if return_task
  return snake_cased_json
end
new(data, snake_cased_json) click to toggle source
# File lib/manatoo/task.rb, line 78
def initialize(data, snake_cased_json)
  @attributes = ATTRIBUTES_STRUCT.new
  set_attributes_from_hash(data)
  @last_json_response = snake_cased_json
  self
end
remove_users(task_id, users) click to toggle source

users should not be empty, should be array

# File lib/manatoo/task.rb, line 154
def self.remove_users(task_id, users)
  url = "tasks/#{task_id}/users"
  resp = Manatoo.delete(url, {
    users: users
  })
  JSON.parse(resp.body).to_snake_keys
end
update(task_id, attrs) click to toggle source

task_id REQUIRED

# File lib/manatoo/task.rb, line 86
def self.update(task_id, attrs)
  url = "tasks/#{task_id}"
  resp = Manatoo.put(url, attrs)
  JSON.parse(resp.body).to_snake_keys
end
update_status(task_id, status) click to toggle source

task_id, status REQUIRED

# File lib/manatoo/task.rb, line 98
def self.update_status(task_id, status)
  url = "tasks/#{task_id}/status"
  resp = Manatoo.put(url, {
    status: status
  })
  JSON.parse(resp.body).to_snake_keys
end

Public Instance Methods

add_labels(labels) click to toggle source
# File lib/manatoo/task.rb, line 120
def add_labels(labels)
  snake_cased_json = Task.add_labels(id, labels)
  handle_snake_cased_json(snake_cased_json)
end
add_users(users) click to toggle source
# File lib/manatoo/task.rb, line 148
def add_users(users)
  snake_cased_json = Task.add_users(id, weight)
  handle_snake_cased_json(snake_cased_json)
end
add_weight(weight) click to toggle source
# File lib/manatoo/task.rb, line 134
def add_weight(weight)
  snake_cased_json = Task.add_weight(id, weight)
  handle_snake_cased_json(snake_cased_json)
end
handle_snake_cased_json(snake_cased_json) click to toggle source
# File lib/manatoo/task.rb, line 32
def handle_snake_cased_json(snake_cased_json)
  # if a user wanted the last_response_json, I assume they would want it
  # in a snake_cased ruby usable fashion
  @last_json_response = snake_cased_json
  task_attrs = @last_json_response['data']
  set_attributes_from_hash(task_attrs)
  self
end
remove_members(users) click to toggle source
# File lib/manatoo/task.rb, line 162
def remove_members(users)
  snake_cased_json = Task.remove_users(id, weight)
  handle_snake_cased_json(snake_cased_json)
end
set_attributes_from_hash(hash) click to toggle source
# File lib/manatoo/task.rb, line 41
def set_attributes_from_hash(hash)
  hash.each do |k, v|
    attributes[k] = v
  end
end
update(attrs) click to toggle source
# File lib/manatoo/task.rb, line 92
def update(attrs)
  snake_cased_json = Task.update(id, attrs)
  handle_snake_cased_json(snake_cased_json)
end
update_status(status) click to toggle source
# File lib/manatoo/task.rb, line 106
def update_status(status)
  snake_cased_json = Task.update_status(id, status)
  handle_snake_cased_json(snake_cased_json)
end