Class: Asana::Workspace

Inherits:
Resource
  • Object
show all
Defined in:
lib/asana/resources/workspace.rb

Instance Method Summary collapse

Methods inherited from Resource

collection_path, custom_method_collection_url, element_path, #method_not_allowed, new_element_path, #reload, remove_json_extension, singleton_path, #to_json

Instance Method Details

#create_tag(options = {}) ⇒ Object



34
35
36
37
# File 'lib/asana/resources/workspace.rb', line 34

def create_tag(options = {})
  response = post("tags", nil, {data: options}.to_json)
  Asana::Tag.new(connection.format.decode(response.body))
end

#create_task(options = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/asana/resources/workspace.rb', line 4

def create_task(options = {})
  # options.merge!(assignee: 'me') unless options[:assignee] or options['assignee']
  options.merge!(workspace: self.id)

  post_body = { data: options }
  response = Task.post(nil, nil, post_body.to_json)
  hash = connection.format.decode(response.body)

  # want to return a persisted record
  Task.find hash["id"]
rescue Exception => e
  $stderr.puts "ERROR: #{e.message}"
  $stderr.puts "RESPONSE: #{e.response.body}" if e.respond_to?(:response)
end

#find_or_create_tag(options = {}) ⇒ Object

TODO imporve this when Asana API is more advanced



30
31
32
# File 'lib/asana/resources/workspace.rb', line 30

def find_or_create_tag(options = {})
  tags.find {|t| t.name == options[:name]} || create_tag(options)
end

#tagsObject



39
40
41
# File 'lib/asana/resources/workspace.rb', line 39

def tags
  get(:tags).map{|h| Asana::Tag.find h["id"]}
end

#tasks(options = {}) ⇒ Object

From API docs: If you specify a workspace you must also specify an assignee to filter on.



20
21
22
23
24
25
26
27
# File 'lib/asana/resources/workspace.rb', line 20

def tasks(options = {})
  options.merge!(assignee: 'me') unless options[:assignee] or options['assignee']

  get("tasks?assignee=#{options[:assignee]}").map{|h| Asana::Task.find h["id"]}
rescue Exception => e
  $stderr.puts "ERROR: #{e.message}"
  $stderr.puts "RESPONSE: #{e.response.body}" if e.respond_to?(:response)
end