From 41899ce529e3bb107bd2028fe20249e58fceaf82 Mon Sep 17 00:00:00 2001 From: Lucidiot Date: Sun, 7 Apr 2019 23:48:12 +0200 Subject: [PATCH] Add create, update, move tags --- HabitSharp/HabiticaApi.cs | 1 + HabitSharp/Managers/TagManager.cs | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/HabitSharp/HabiticaApi.cs b/HabitSharp/HabiticaApi.cs index c6b991c..d1ca64f 100644 --- a/HabitSharp/HabiticaApi.cs +++ b/HabitSharp/HabiticaApi.cs @@ -39,6 +39,7 @@ namespace HabitSharp if (response.ErrorException != null) throw new ApplicationException( "An error occured while running a Habitica API request. See inner exception for more info", response.ErrorException); + // TODO: Raise exception on error, error message, param errors or !Success return response.Data; } diff --git a/HabitSharp/Managers/TagManager.cs b/HabitSharp/Managers/TagManager.cs index bb7fa4a..259fb31 100644 --- a/HabitSharp/Managers/TagManager.cs +++ b/HabitSharp/Managers/TagManager.cs @@ -14,6 +14,31 @@ namespace HabitSharp.Managers { return this.Client.Execute>(req); } + public Result Create(Tag t) => this.Create(t.Name); + public Result Create(string name) { + var req = new RestRequest("tags", Method.POST); + req.AddParameter("name", name); + return this.Client.Execute>(req); + } + + public Result Update(Tag t) => this.Update(t.Id, t.Name); + public Result Update(Guid id, string name) => this.Update(id.ToString(), name); + public Result Update(string id, string name) { + var req = new RestRequest("tags/{tagId}", Method.PUT); + req.AddUrlSegment("tagId", id); + req.AddParameter("name", name); + return this.Client.Execute>(req); + } + + public Result Move(Tag t, int position) => this.Move(t.Id, position); + public Result Move(Guid id, int position) => this.Move(id.ToString(), position); + public Result Move(string id, int position) { + var req = new RestRequest("reorder-tags", Method.POST); + req.AddParameter("tagId", id); + req.AddParameter("to", position); + return this.Client.Execute>(req); + } + public Result Delete(Tag t) => this.Delete(t.Id); public Result Delete(Guid id) => this.Delete(id.ToString()); public Result Delete(string id) {