Add NotificationManager
This commit is contained in:
parent
bf306c53e7
commit
d98548a918
|
@ -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() {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue