51 lines
2.1 KiB
C#
51 lines
2.1 KiB
C#
using System;
|
|
using RestSharp;
|
|
|
|
namespace HabitSharp.Managers {
|
|
public class TagManager : Manager {
|
|
public TagManager(HabiticaApi client) : base(client) { }
|
|
|
|
public ListResult<Tag> List() => this.Client.Execute<ListResult<Tag>>(new RestRequest("tags"));
|
|
|
|
public Result<Tag> Get(Guid id) => this.Get(id.ToString());
|
|
public Result<Tag> Get(string id) {
|
|
var req = new RestRequest("tags/{tagId}");
|
|
req.AddUrlSegment("tagId", id);
|
|
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) {
|
|
var req = new RestRequest("tags/{tagId}", Method.DELETE);
|
|
req.AddUrlSegment("tagId", id);
|
|
return this.Client.Execute<Result<Object>>(req);
|
|
}
|
|
}
|
|
}
|