Create TagManager to list, get and delete
This commit is contained in:
parent
128314e5a0
commit
337b0a183a
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using RestSharp;
|
||||
using HabitSharp.Managers;
|
||||
|
||||
namespace HabitSharp
|
||||
{
|
||||
|
@ -9,12 +10,15 @@ namespace HabitSharp
|
|||
|
||||
private readonly RestClient Client;
|
||||
|
||||
public readonly TagManager Tags;
|
||||
|
||||
public HabiticaApi(string UserID, string ApiKey) : this(Guid.Parse(UserID), Guid.Parse(ApiKey)) { }
|
||||
|
||||
public HabiticaApi(Guid UserID, Guid ApiKey)
|
||||
{
|
||||
this.Client = new RestClient(BaseURL);
|
||||
this.Client.Authenticator = new HabiticaAuthenticator(UserID, ApiKey);
|
||||
this.Tags = new TagManager(this);
|
||||
}
|
||||
|
||||
public T Execute<T>(RestRequest request) where T : new() {
|
||||
|
@ -24,9 +28,5 @@ namespace HabitSharp
|
|||
response.ErrorException);
|
||||
return response.Data;
|
||||
}
|
||||
|
||||
public ListResult<Tag> ListTags() {
|
||||
return this.Execute<ListResult<Tag>>(new RestRequest("tags"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
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<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}");
|
||||
req.AddUrlSegment("tagId", id);
|
||||
return this.Client.Execute<Result<Object>>(req);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue