Class: Asana::Task

Inherits:
Object
  • Object
show all
Defined in:
lib/asana-client.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Task

Returns a new instance of Task.



225
226
227
228
229
230
# File 'lib/asana-client.rb', line 225

def initialize(hash)
    self.id = hash[:id] || 0
    self.name = hash[:name] || ""
    self.workspace = hash[:workspace] || nil
    self.project = hash[:project] || nil
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



223
224
225
# File 'lib/asana-client.rb', line 223

def id
  @id
end

#nameObject

Returns the value of attribute name.



223
224
225
# File 'lib/asana-client.rb', line 223

def name
  @name
end

#projectObject

Returns the value of attribute project.



223
224
225
# File 'lib/asana-client.rb', line 223

def project
  @project
end

#workspaceObject

Returns the value of attribute workspace.



223
224
225
# File 'lib/asana-client.rb', line 223

def workspace
  @workspace
end

Class Method Details

.comment(id, text) ⇒ Object

comment on a task



263
264
265
# File 'lib/asana-client.rb', line 263

def self.comment(id, text)
    Asana.post "tasks/#{id}/stories", { "text" => text }
end

.create(workspace, name, assignee = nil, due = nil) ⇒ Object

create a new task on the server



233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
# File 'lib/asana-client.rb', line 233

def self.create(workspace, name, assignee = nil, due = nil)
    # if given string for workspace, convert to object
    if workspace.is_a? String
        workspace = Asana::Workspace.find workspace 
    end
    abort "Workspace not found" unless workspace

    # if assignee was given, get user
    if !assignee.nil?
        assignee = Asana::User.find workspace, assignee 
        abort "Assignee not found" unless assignee
    end

    # add task to workspace
    params = {
        "workspace" => workspace.id, 
        "name" => name,
        "assignee" => (assignee.nil?) ? "me" : assignee.id
    }
    
    # attach due date if given
    if !due.nil?
        params["due_on"] = due
    end

    # add task to workspace
    Asana.post "tasks", params
end

.finish(id) ⇒ Object

finish a task



273
274
275
# File 'lib/asana-client.rb', line 273

def self.finish(id)
    Asana.put "tasks/#{id}", { "completed" => true }
end

Instance Method Details

#comment(text) ⇒ Object

comment on the current task



268
269
270
# File 'lib/asana-client.rb', line 268

def comment(text)
    self.comment(self.id, text)
end

#finishObject

finish the current task



278
279
280
# File 'lib/asana-client.rb', line 278

def finish
    self.finish(self.id)
end

#to_sObject



282
283
284
# File 'lib/asana-client.rb', line 282

def to_s
    "(#{self.id}) #{self.name}"
end