lucidiot/HabitSharp
lucidiot
/
HabitSharp
Archived
1
0
Fork 0

Add NotificationManager

This commit is contained in:
Lucidiot 2019-01-10 00:45:04 +01:00
parent bf306c53e7
commit d98548a918
No known key found for this signature in database
GPG Key ID: AE3F7205692FA205
2 changed files with 46 additions and 0 deletions

View File

@ -14,6 +14,8 @@ namespace HabitSharp
public readonly TagManager Tags;
public readonly NotificationManager Notifications;
public HabiticaApi(string UserID, string ApiKey) : this(Guid.Parse(UserID), Guid.Parse(ApiKey)) { }
public HabiticaApi(Guid UserID, Guid ApiKey)
@ -29,6 +31,7 @@ namespace HabitSharp
this.Client.AddHandler("*+json", NewtonsoftJsonSerializer.Default);
this.Tags = new TagManager(this);
this.Notifications = new NotificationManager(this);
}
public T Execute<T>(RestRequest request) where T : new() {

View File

@ -0,0 +1,43 @@
using System;
using System.Linq;
using System.Collections.Generic;
using RestSharp;
using HabitSharp.Notifications;
namespace HabitSharp.Managers {
public class NotificationManager : Manager {
public NotificationManager(HabiticaApi client) : base(client) { }
public List<Notification> MarkAsRead(IEnumerable<Notification> notes) => this.MarkAsRead(notes.Select(note => note.Id));
public List<Notification> MarkAsRead(IEnumerable<Guid> ids) => this.MarkAsRead(ids.Select(id => id.ToString()));
public List<Notification> MarkAsRead(IEnumerable<string> ids) {
var req = new RestRequest("notifications/read", Method.POST);
req.AddParameter("notificationIds", ids);
return this.Client.Execute<List<Notification>>(req);
}
public List<Notification> MarkAsRead(Notification note) => this.MarkAsRead(note.Id);
public List<Notification> MarkAsRead(Guid id) => this.MarkAsRead(id.ToString());
public List<Notification> MarkAsRead(string id) {
var req = new RestRequest("notifications/{noteId}/read", Method.POST);
req.AddUrlSegment("noteId", id);
return this.Client.Execute<List<Notification>>(req);
}
public List<Notification> MarkAsSeen(IEnumerable<Notification> notes) => this.MarkAsSeen(notes.Select(note => note.Id));
public List<Notification> MarkAsSeen(IEnumerable<Guid> ids) => this.MarkAsSeen(ids.Select(id => id.ToString()));
public List<Notification> MarkAsSeen(IEnumerable<string> ids) {
var req = new RestRequest("notifications/see", Method.POST);
req.AddParameter("notificationIds", ids);
return this.Client.Execute<List<Notification>>(req);
}
public Notification MarkAsSeen(Notification note) => this.MarkAsSeen(note.Id);
public Notification MarkAsSeen(Guid id) => this.MarkAsSeen(id.ToString());
public Notification MarkAsSeen(String id) {
var req = new RestRequest("notifications/{noteId}/seen", Method.POST);
req.AddUrlSegment("noteId", id);
return this.Client.Execute<Notification>(req);
}
}
}