Add create, update, move tags
This commit is contained in:
parent
c44fd6eb1a
commit
41899ce529
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
Reference in New Issue