This repository has been archived by the owner on Jun 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPushBulletClient.cs
134 lines (115 loc) · 3.84 KB
/
PushBulletClient.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
using System.Collections.Generic;
using System.Threading.Tasks;
using PushBulletNet.PushBullet;
using PushBulletNet.PushBullet.Models;
using PushBulletNet.PushBullet.Models.PostModels;
namespace PushBulletNet
{
public interface IPushBulletClient
{
/// <summary>
/// Gets user data from PushBullet
/// </summary>
/// <returns></returns>
Task<PushBulletUser> GetUserDataAsync();
/// <summary>
/// Gets devices registered to PushBullet
/// </summary>
/// <returns></returns>
Task<IEnumerable<PushBulletDevice>> GetDevicesAsync();
/// <summary>
/// Gets all pushes by the client on PushBullet
/// </summary>
/// <returns></returns>
Task<IEnumerable<PushBulletPush>> GetPushesAsync();
/// <summary>
/// Gets all chats by the client on PushBullet
/// </summary>
Task<IEnumerable<PushBulletChat>> GetChatsAsync();
/// <summary>
/// Pushes a new request to the PushBullet service
/// </summary>
/// <param name="title"></param>
/// <param name="content"></param>
/// <returns></returns>
Task PushAsync(string title, string content, string targetDeviceId);
/// <summary>
/// Creates a new device
/// </summary>
/// <param name="title"></param>
/// <param name="content"></param>
/// <returns></returns>
Task CreateDeviceAsync(NewDeviceModel model);
/// <summary>
/// Creates a new chat
/// </summary>
/// <param name="title"></param>
/// <param name="content"></param>
/// <returns></returns>
Task CreateChatAsync(string email);
/// <summary>
/// Creates a new subscription
/// </summary>
/// <param name="title"></param>
/// <param name="content"></param>
/// <returns></returns>
Task CreateSubscriptionAsync(string channeltag);
}
public class PushBulletClient : IPushBulletClient
{
private readonly string _token;
private readonly IPushBulletService _pushBulletService;
public PushBulletClient(string token)
{
_pushBulletService = new PushBulletService(token);
_token = token;
}
/// <inheritdoc />
public Task<PushBulletUser> GetUserDataAsync()
{
return _pushBulletService.GetClientData();
}
/// <inheritdoc />
public Task<IEnumerable<PushBulletDevice>> GetDevicesAsync()
{
return _pushBulletService.GetDevices();
}
/// <inheritdoc />
public Task<IEnumerable<PushBulletPush>> GetPushesAsync()
{
return _pushBulletService.GetPushes();
}
/// <inheritdoc />
public Task<IEnumerable<PushBulletChat>> GetChatsAsync()
{
return _pushBulletService.GetChats();
}
/// <inheritdoc />
public Task PushAsync(string title, string content, string targetDeviceId)
{
var request = new NotificationPostModel()
{
Title = title,
Content = content,
TargetDeviceIdentity = targetDeviceId,
PushType = "note"
};
return _pushBulletService.PushNotification(request);
}
/// <inheritdoc />
public Task CreateDeviceAsync(NewDeviceModel model)
{
return _pushBulletService.CreateDevice(model);
}
/// <inheritdoc />
public Task CreateChatAsync(string email)
{
return _pushBulletService.CreateChat(email);
}
/// <inheritdoc />
public Task CreateSubscriptionAsync(string chantag)
{
return _pushBulletService.CreateSubscription(chantag);
}
}
}