class MilkCap::RTM::Task

The RTM Task class.

Attributes

list_id[R]
tags[R]
task_id[R]
taskseries_id[R]

Public Class Methods

add!(name, opts = {}) click to toggle source

Adds a new task (and returns it).

# File lib/milk_cap/rtm/resources.rb, line 181
def self.add! (name, opts = {})
  opts = { list_id: nil, parse: true }.merge(opts)

  args = {}
  args[:name] = name
  args[:list_id] = opts[:list_id] if opts[:list_id]
  args[:timeline] = timeline
  args[:parse] = 1 unless !opts[:parse]

  h = execute('add', args)

  parse_tasks(h)[0]
end
find(params={}) click to toggle source
# File lib/milk_cap/rtm/resources.rb, line 174
def self.find (params={})

  parse_tasks(execute('getList', params))
end
new(list_id, task_series_hash, task_hash) click to toggle source

Task series may have multiple tasks. task_hash used to specify which task in series.

Calls superclass method MilkCap::RTM::MilkResource::new
# File lib/milk_cap/rtm/resources.rb, line 132
def initialize (list_id, task_series_hash, task_hash)

  super(task_series_hash)
  @task_hash = task_hash

  @list_id = list_id
  @taskseries_id = task_series_hash['id']
  @task_id = @task_hash['id']

  # Normalize the RTM structure and put it in TagArray
  tags = normalize_rtm_tags_hash( task_series_hash['tags'] )
  @tags = TagArray.new(self, tags)
end

Protected Class Methods

parse_tasks(o) click to toggle source
# File lib/milk_cap/rtm/resources.rb, line 206
def self.parse_tasks (o)

  o = if o.is_a?(Hash)

    r = o[resource_name]
    o = r if r
    o['list']
  end

  o = [ o ] unless o.is_a?(Array)
    # Nota bene : not the same thing as  o = Array(o)

  o.inject([]) do |r, h|

    list_id = h['id']
    s = h['taskseries']
    r += parse_taskseries(list_id, s) if s
    r
  end
end
parse_taskseries(list_id, o) click to toggle source
# File lib/milk_cap/rtm/resources.rb, line 227
def self.parse_taskseries (list_id, o)
  o = [ o ] unless o.is_a?(Array)

  # o is an array of taskseries.  Collect flattened array of tasks out of
  # all taskseries
  o.inject([]) do |m,s|
    tasks = s['task']
    tasks = [ tasks ] unless tasks.is_a?(Array)
    m + tasks.collect { |t| self.new(list_id, s, t) }
  end
end

Public Instance Methods

complete!() click to toggle source

Marks the task as completed.

# File lib/milk_cap/rtm/resources.rb, line 162
def complete!

  self.class.execute('complete', prepare_api_args)
end
delete!() click to toggle source

Deletes the task.

# File lib/milk_cap/rtm/resources.rb, line 155
def delete!

  self.class.execute('delete', prepare_api_args)
end
save!() click to toggle source
# File lib/milk_cap/rtm/resources.rb, line 146
def save!
  if self.tags.dirty?
    args = prepare_api_args.merge( tags: self.tags.join(",") )
    self.class.execute('setTags', args)
  end
end
tags=(tags) click to toggle source

Sets the tags for the task.

# File lib/milk_cap/rtm/resources.rb, line 169
def tags= (tags)
  @tags = TagArray.new(self, normalize_tags_array(tags))
  @tags.dirty!
end

Protected Instance Methods

prepare_api_args() click to toggle source
# File lib/milk_cap/rtm/resources.rb, line 197
def prepare_api_args
  {
    :timeline => timeline,
    :list_id => list_id,
    :taskseries_id => taskseries_id,
    :task_id => task_id
  }
end