lucidiot/HabitSharp
lucidiot
/
HabitSharp
Archived
1
0
Fork 0

Create TagManager to list, get and delete

This commit is contained in:
Lucidiot 2018-09-01 16:11:34 +02:00
parent 128314e5a0
commit 337b0a183a
No known key found for this signature in database
GPG Key ID: AE3F7205692FA205
2 changed files with 29 additions and 4 deletions

View File

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

25
Managers/TagManager.cs Normal file
View File

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