Class: Vermonster::Tasks::Task

Inherits:
Hash
  • Object
show all
Defined in:
lib/vermonster/tasks.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Task

Returns a new instance of Task.



8
9
10
11
12
13
14
15
# File 'lib/vermonster/tasks.rb', line 8

def initialize(options = {})
  self.merge!(options)

  options.each do |(attr, val)|      
    instance_variable_set("@#{attr}", val)
    instance_eval "def #{attr}() @#{attr} end"
  end
end

Class Method Details

.archive(list) ⇒ Object



48
49
50
# File 'lib/vermonster/tasks.rb', line 48

def archive(list)
  Vermonster::Client.connection.post("lists/#{list}/tasks/archive_completed")
end

.archive!(list) ⇒ Object



52
53
54
# File 'lib/vermonster/tasks.rb', line 52

def archive!(list)
  Vermonster::Client.connection.post("lists/#{list}/tasks/archive_all")
end

.create(list, options = {}) ⇒ Object



41
42
43
# File 'lib/vermonster/tasks.rb', line 41

def create(list, options = {})
  Task.new(Vermonster::Client.connection.post("lists/#{list}/tasks", "{\"task\": #{options.to_json}}").body)
end

.find(id) ⇒ Object



37
38
39
# File 'lib/vermonster/tasks.rb', line 37

def find(id)
  Task.new(Vermonster::Client.connection.get("tasks/#{id}").body)
end

.from_list(id) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/vermonster/tasks.rb', line 27

def from_list(id)
  tasks_raw = Vermonster::Client.connection.get("lists/#{id}/tasks").body
  tasks = []
  tasks_raw.each do |task|
    tasks.push(Task.new(task))
  end

  tasks
end

.reorder(list, options = {}) ⇒ Object



45
46
# File 'lib/vermonster/tasks.rb', line 45

def reorder(list, options = {})
end

Instance Method Details

#move(list) ⇒ Object



22
23
24
# File 'lib/vermonster/tasks.rb', line 22

def move(list)
  self.replace(Vermonster::Client.connection.put("tasks/#{self["id"]}/move", "{\"task\": { \"list_id\": #{list} } }").body)
end

#update(options = {}) ⇒ Object

Note this overrides Hash#update. Use Hash#merge! instead.



18
19
20
# File 'lib/vermonster/tasks.rb', line 18

def update(options = {})
  self.merge!(Vermonster::Client.connection.put("tasks/#{self["id"]}", "{\"task\": #{options.to_json}}").body)
end