Class: Asana::Workspace
- Defined in:
- lib/asana/resources/workspace.rb
Instance Method Summary collapse
- #completed_tasks ⇒ Object
- #create_tag(options = {}) ⇒ Object
- #create_task(options = {}) ⇒ Object
-
#find_or_create_tag(options = {}) ⇒ Object
TODO imporve this when Asana API is more advanced.
- #find_tag_from_list(tag_list, options = {}) ⇒ Object
-
#load_tags_by_id ⇒ Object
expensive query: reload each task by id only use this if Asana::Tag.new(tag, true) doesn’t work as expected.
-
#tags(force_reload = false) ⇒ Object
Resource.new(record, true) is the trick to initialize a persisted record.
-
#tasks(options = {}) ⇒ Object
From API docs: If you specify a workspace you must also specify an assignee to filter on.
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
#completed_tasks ⇒ Object
32 33 34 |
# File 'lib/asana/resources/workspace.rb', line 32 def completed_tasks tasks.select(&:completed?) end |
#create_tag(options = {}) ⇒ Object
44 45 46 47 |
# File 'lib/asana/resources/workspace.rb', line 44 def create_tag( = {}) response = post("tags", nil, {data: }.to_json) Asana::Tag.new(connection.format.decode(response.body), true) end |
#create_task(options = {}) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/asana/resources/workspace.rb', line 3 def create_task( = {}) # options.merge!(assignee: 'me') unless options[:assignee] or options['assignee'] .merge!(workspace: self.id) post_body = { data: } 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.}" $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
37 38 39 40 41 42 |
# File 'lib/asana/resources/workspace.rb', line 37 def find_or_create_tag( = {}) [:name].strip! if [:name] # try to load from cache first, if not found, force reload, if still not found, create one find_tag_from_list(, ) || find_tag_from_list((true), ) || create_tag() end |
#find_tag_from_list(tag_list, options = {}) ⇒ Object
61 62 63 |
# File 'lib/asana/resources/workspace.rb', line 61 def find_tag_from_list(tag_list, = {}) tag_list.find {|t| t.name && [:name] && t.name.strip == [:name] } end |
#load_tags_by_id ⇒ Object
expensive query: reload each task by id only use this if Asana::Tag.new(tag, true) doesn’t work as expected
57 58 59 |
# File 'lib/asana/resources/workspace.rb', line 57 def get(:tags).map{|h| Asana::Tag.find h["id"]} end |
#tags(force_reload = false) ⇒ Object
Resource.new(record, true) is the trick to initialize a persisted record
50 51 52 53 |
# File 'lib/asana/resources/workspace.rb', line 50 def (force_reload = false) return @tags if defined?(@tags) and !force_reload @tags ||= get(:tags).map{|h| Asana::Tag.new(h, true)} end |
#tasks(options = {}) ⇒ Object
From API docs: If you specify a workspace you must also specify an assignee to filter on.
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/asana/resources/workspace.rb', line 19 def tasks( = {}) .merge!(assignee: 'me') unless [:assignee] or ['assignee'] url = "tasks?assignee=#{[:assignee]}" url += "&include_archived=true" if [:include_archived] get(url).map { |h| Asana::Task.find h["id"] } rescue Exception => e $stderr.puts "ERROR: #{e.}" $stderr.puts "RESPONSE: #{e.response.body}" if e.respond_to?(:response) end |