Class: Asana::Workspace

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) ⇒ Workspace

Returns a new instance of Workspace.



320
321
322
323
# File 'lib/asana-client.rb', line 320

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

Instance Attribute Details

#idObject

Returns the value of attribute id.



318
319
320
# File 'lib/asana-client.rb', line 318

def id
  @id
end

#nameObject

Returns the value of attribute name.



318
319
320
# File 'lib/asana-client.rb', line 318

def name
  @name
end

Class Method Details

.find(name) ⇒ Object

search a workspace by name



326
327
328
329
330
331
332
333
334
335
336
# File 'lib/asana-client.rb', line 326

def self.find(name)
    # check if any workspace contains the given name, and return first hit
    name.downcase!
    Asana.workspaces.each do |workspace|
        if workspace.name.downcase.include? name
            return workspace
        end
    end

    nil
end

Instance Method Details

#projectsObject

get all projects associated with a workspace



339
340
341
342
343
344
345
346
347
348
# File 'lib/asana-client.rb', line 339

def projects
    project_objects = Asana.get "projects?workspace=#{self.id}"
    list = []

    project_objects["data"].each do |project|
        list.push Project.new :id => project["id"], :name => project["name"], :workspace => self
    end

    list
end

#tasksObject

get tasks assigned to me within this workspace



351
352
353
354
355
356
357
358
359
360
361
# File 'lib/asana-client.rb', line 351

def tasks
    task_objects = Asana.get "tasks?workspace=#{self.id}&assignee=me"
    list = []

    task_objects["data"].each do |task|
        list.push Task.new :id => task["id"], :name => task["name"],
            :workspace => self
    end

    list
end

#usersObject

get all users in the workspace



364
365
366
367
368
369
370
371
372
373
# File 'lib/asana-client.rb', line 364

def users
    user_objects = Asana.get "workspaces/#{self.id}/users"
    list = []

    user_objects["data"].each do |user|
        list.push User.new :id => user["id"], :name => user["name"]
    end

    list
end