lucidiot/HabitSharp
lucidiot
/
HabitSharp
Archived
1
0
Fork 0

Add create, update, move tags

This commit is contained in:
Lucidiot 2019-04-07 23:48:12 +02:00
parent c44fd6eb1a
commit 41899ce529
No known key found for this signature in database
GPG Key ID: AE3F7205692FA205
2 changed files with 26 additions and 0 deletions

View File

@ -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;
}

View File

@ -14,6 +14,31 @@ namespace HabitSharp.Managers {
return this.Client.Execute<Result<Tag>>(req);
}
public Result<Tag> Create(Tag t) => this.Create(t.Name);
public Result<Tag> Create(string name) {
var req = new RestRequest("tags", Method.POST);
req.AddParameter("name", name);
return this.Client.Execute<Result<Tag>>(req);
}
public Result<Tag> Update(Tag t) => this.Update(t.Id, t.Name);
public Result<Tag> Update(Guid id, string name) => this.Update(id.ToString(), name);
public Result<Tag> 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<Result<Tag>>(req);
}
public Result<Object> Move(Tag t, int position) => this.Move(t.Id, position);
public Result<Object> Move(Guid id, int position) => this.Move(id.ToString(), position);
public Result<Object> 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<Result<Object>>(req);
}
public Result<Object> Delete(Tag t) => this.Delete(t.Id);
public Result<Object> Delete(Guid id) => this.Delete(id.ToString());
public Result<Object> Delete(string id) {