From 7a4bebc3c4ba5f76c2e0fc485ed64cbbf1c48673 Mon Sep 17 00:00:00 2001 From: Vince Broz Date: Sun, 18 Jun 2017 13:58:53 -0400 Subject: [PATCH 1/4] Fix inserting task at top/bottom of project The API's 'send null to specify top/bottom' protocol conflicted with how Asana::Resources::Task#add_project handled keyword arguments. Add workaround to distinguish between 'set to nil' and 'not provided' for the `insert_after` and `insert before` keyword args. --- lib/asana/resources/task.rb | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/asana/resources/task.rb b/lib/asana/resources/task.rb index 46fed1c..8a05550 100644 --- a/lib/asana/resources/task.rb +++ b/lib/asana/resources/task.rb @@ -230,10 +230,11 @@ def projects(per_page: 20, options: {}) # Returns an empty data block. # # project - [Id] The project to add the task to. - # insert_after - [Id] A task in the project to insert the task after, or `null` to + # + # insert_after - [Id] A task in the project to insert the task after, or `nil` to # insert at the beginning of the list. # - # insert_before - [Id] A task in the project to insert the task before, or `null` to + # insert_before - [Id] A task in the project to insert the task before, or `nil` to # insert at the end of the list. # # section - [Id] A section in the project to insert the task into. The task will be @@ -241,8 +242,10 @@ def projects(per_page: 20, options: {}) # # options - [Hash] the request I/O options. # data - [Hash] the attributes to post. - def add_project(project: required("project"), insert_after: nil, insert_before: nil, section: nil, options: {}, **data) - with_params = data.merge(project: project, insert_after: insert_after, insert_before: insert_before, section: section).reject { |_,v| v.nil? || Array(v).empty? } + def add_project(project: required("project"), insert_after: :not_provided, insert_before: :not_provided, section: nil, options: {}, **data) + with_params = data.merge(project: project, insert_after: insert_after, insert_before: insert_before, section: section).reject { |_,v| v.nil? || Array(v).empty? || v == :not_provided } + with_params[:insert_after] = nil if insert_after.nil? + with_params[:insert_before] = nil if insert_before.nil? client.post("/tasks/#{id}/addProject", body: with_params, options: options) && true end @@ -343,4 +346,4 @@ def add_comment(text: required("text"), options: {}, **data) end end -end \ No newline at end of file +end From e0f5a5cf1a58fca02144d54f76ddce3036ae6a9f Mon Sep 17 00:00:00 2001 From: Bundle updater Date: Mon, 2 Oct 2017 19:11:02 -0400 Subject: [PATCH 2/4] Fix nil issue with set_parent() --- lib/asana/resources/task.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/asana/resources/task.rb b/lib/asana/resources/task.rb index 8a05550..451536a 100644 --- a/lib/asana/resources/task.rb +++ b/lib/asana/resources/task.rb @@ -317,7 +317,8 @@ def add_subtask(options: {}, **data) # options - [Hash] the request I/O options. # data - [Hash] the attributes to post. def set_parent(parent: required("parent"), options: {}, **data) - with_params = data.merge(parent: parent).reject { |_,v| v.nil? || Array(v).empty? } + with_params = data.merge(project: project, insert_after: insert_after, insert_before: insert_before, section: section).reject { |_,v| v.nil? || Array(v).empty? || v == :not_provided } + with_params[:parent] = nil if parent.nil? client.post("/tasks/#{id}/setParent", body: with_params, options: options) && true end From 8bae32b2b91c83ba252fe510468a66b08d626c62 Mon Sep 17 00:00:00 2001 From: Bundle updater Date: Mon, 2 Oct 2017 19:13:25 -0400 Subject: [PATCH 3/4] Fix params included --- lib/asana/resources/task.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/asana/resources/task.rb b/lib/asana/resources/task.rb index 451536a..eb29426 100644 --- a/lib/asana/resources/task.rb +++ b/lib/asana/resources/task.rb @@ -317,7 +317,7 @@ def add_subtask(options: {}, **data) # options - [Hash] the request I/O options. # data - [Hash] the attributes to post. def set_parent(parent: required("parent"), options: {}, **data) - with_params = data.merge(project: project, insert_after: insert_after, insert_before: insert_before, section: section).reject { |_,v| v.nil? || Array(v).empty? || v == :not_provided } + with_params = data.merge(parent: parent).reject { |_,v| v.nil? || Array(v).empty? || v == :not_provided } with_params[:parent] = nil if parent.nil? client.post("/tasks/#{id}/setParent", body: with_params, options: options) && true end From 0648d396b58e48c46d11ee951011b5b6f42fa158 Mon Sep 17 00:00:00 2001 From: Vince Broz Date: Fri, 30 Aug 2019 16:22:36 -0400 Subject: [PATCH 4/4] Allow parent to be set to nil in Task#set_parent() --- lib/asana/resources/task.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/asana/resources/task.rb b/lib/asana/resources/task.rb index 6b0832e..263d825 100644 --- a/lib/asana/resources/task.rb +++ b/lib/asana/resources/task.rb @@ -478,6 +478,7 @@ def add_subtask(options: {}, **data) # data - [Hash] the attributes to post. def set_parent(parent: required("parent"), insert_after: nil, insert_before: nil, options: {}, **data) with_params = data.merge(parent: parent, insert_after: insert_after, insert_before: insert_before).reject { |_,v| v.nil? || Array(v).empty? } + with_params[:parent] = nil if parent.nil? client.post("/tasks/#{gid}/setParent", body: with_params, options: options) && true end