2018-08-30 22:43:02 +00:00
|
|
|
|
using System;
|
2018-09-01 14:18:53 +00:00
|
|
|
|
using System.Collections.Generic;
|
2018-08-30 22:43:02 +00:00
|
|
|
|
using RestSharp;
|
2018-09-01 14:11:34 +00:00
|
|
|
|
using HabitSharp.Managers;
|
2018-08-30 22:43:02 +00:00
|
|
|
|
|
|
|
|
|
namespace HabitSharp
|
|
|
|
|
{
|
|
|
|
|
public class HabiticaApi
|
|
|
|
|
{
|
|
|
|
|
const string BaseURL = "https://habitica.com/api/v3";
|
|
|
|
|
|
|
|
|
|
private readonly RestClient Client;
|
|
|
|
|
|
2018-09-01 14:11:34 +00:00
|
|
|
|
public readonly TagManager Tags;
|
|
|
|
|
|
2018-08-30 22:43:02 +00:00
|
|
|
|
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);
|
2018-09-01 14:11:34 +00:00
|
|
|
|
this.Tags = new TagManager(this);
|
2018-08-30 22:43:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public T Execute<T>(RestRequest request) where T : new() {
|
|
|
|
|
var response = Client.Execute<T>(request);
|
|
|
|
|
if (response.ErrorException != null) throw new ApplicationException(
|
|
|
|
|
"An error occured while running a Habitica API request. See inner exception for more info",
|
|
|
|
|
response.ErrorException);
|
|
|
|
|
return response.Data;
|
|
|
|
|
}
|
2018-09-01 14:18:53 +00:00
|
|
|
|
|
|
|
|
|
public Result<Dictionary<string, string>> GetModelPaths(string ModelName) {
|
|
|
|
|
var req = new RestRequest("models/{model}/paths");
|
|
|
|
|
req.AddUrlSegment("model", ModelName);
|
|
|
|
|
return this.Execute<Result<Dictionary<string, string>>>(req);
|
|
|
|
|
}
|
2018-08-30 22:43:02 +00:00
|
|
|
|
}
|
|
|
|
|
}
|