Skip to content
This repository was archived by the owner on Jun 25, 2023. It is now read-only.

Commit b8e755b

Browse files
author
Adomix
committed
Cleaned up some code, added CreateChatAsync and CreateSubscriptionAsync
1 parent 910332b commit b8e755b

File tree

3 files changed

+47
-7
lines changed

3 files changed

+47
-7
lines changed

PushBullet/PushBulletService.cs

+14-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ internal interface IPushBulletService
2020
Task<IEnumerable<PushBulletChat>> GetChats();
2121
Task PushNotification(NotificationPostModel request);
2222
Task CreateDevice(NewDeviceModel model);
23+
Task CreateChat(string email);
24+
Task CreateSubscription(string channeltag);
2325
}
2426

2527
internal class PushBulletService : IPushBulletService
@@ -82,6 +84,16 @@ public async Task CreateDevice(NewDeviceModel model)
8284
await Post(_token, "devices", pushRequest).ConfigureAwait(false);
8385
}
8486

87+
public async Task CreateChat(string email)
88+
{
89+
await Post(_token, "chats", $"{{\"email\": \"{email}\"}}").ConfigureAwait(false);
90+
}
91+
92+
public async Task CreateSubscription(string channeltag)
93+
{
94+
await Post(_token, "subscriptions", $"{{\"channel_tag\": \"{channeltag}\"}}").ConfigureAwait(false);
95+
}
96+
8597
private async Task<T> Get<T>(string token, string url)
8698
{
8799
_client.DefaultRequestHeaders.Add(ACCESS_TOKEN_HEADER, token);
@@ -92,7 +104,7 @@ private async Task<T> Get<T>(string token, string url)
92104
{
93105
var error = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
94106
var reason = ProcessStream<ErrorModel>(error);
95-
throw new PushBulletRequestFailedException($"GET request failed! {response.ReasonPhrase} || {reason.Cat} {reason.Message} {reason.Happy}");
107+
throw new PushBulletRequestFailedException($"GET request failed! {response.ReasonPhrase} || API Response: {reason.Cat ?? "N/A"} {reason.Message ?? "N/A"} {reason.Happy}");
96108
}
97109

98110
var content = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
@@ -113,7 +125,7 @@ private async Task Post(string token, string url, string request)
113125
{
114126
var error = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
115127
var reason = ProcessStream<ErrorModel>(error);
116-
throw new PushBulletRequestFailedException($"POST request failed! {response.ReasonPhrase} || {reason.Cat} {reason.Message} {reason.Happy}");
128+
throw new PushBulletRequestFailedException($"POST request failed! {response.ReasonPhrase} || API Response: {reason.Cat ?? "N/A"} {reason.Message ?? "N/A"} {reason.Happy}");
117129
}
118130

119131
_client.DefaultRequestHeaders.Clear();

PushBulletClient.cs

+29-1
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,28 @@ public interface IPushBulletClient
4040
Task PushAsync(string title, string content, string targetDeviceId);
4141

4242
/// <summary>
43-
/// Creates a new chat
43+
/// Creates a new device
4444
/// </summary>
4545
/// <param name="title"></param>
4646
/// <param name="content"></param>
4747
/// <returns></returns>
4848
Task CreateDeviceAsync(NewDeviceModel model);
49+
50+
/// <summary>
51+
/// Creates a new chat
52+
/// </summary>
53+
/// <param name="title"></param>
54+
/// <param name="content"></param>
55+
/// <returns></returns>
56+
Task CreateChatAsync(string email);
57+
58+
/// <summary>
59+
/// Creates a new subscription
60+
/// </summary>
61+
/// <param name="title"></param>
62+
/// <param name="content"></param>
63+
/// <returns></returns>
64+
Task CreateSubscriptionAsync(string channeltag);
4965
}
5066

5167
public class PushBulletClient : IPushBulletClient
@@ -102,5 +118,17 @@ public Task CreateDeviceAsync(NewDeviceModel model)
102118
{
103119
return _pushBulletService.CreateDevice(model);
104120
}
121+
122+
/// <inheritdoc />
123+
public Task CreateChatAsync(string email)
124+
{
125+
return _pushBulletService.CreateChat(email);
126+
}
127+
128+
/// <inheritdoc />
129+
public Task CreateSubscriptionAsync(string chantag)
130+
{
131+
return _pushBulletService.CreateSubscription(chantag);
132+
}
105133
}
106134
}

PushBulletNet.csproj

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,20 @@
66
<OutputType>Library</OutputType>
77
<StartupObject></StartupObject>
88
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
9-
<Version>0.2.7</Version>
9+
<Version>0.2.8</Version>
1010
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
1111
<Description>.NET wrapper for PushBullet.com</Description>
1212
<Copyright>MIT</Copyright>
1313
<PackageLicenseUrl>https://github.com/Adomix/PushBulletNet/blob/master/LICENSE.md</PackageLicenseUrl>
1414
<PackageProjectUrl>https://github.com/Adomix/PushBulletNet</PackageProjectUrl>
1515
<PackageIconUrl>https://i.imgur.com/Vcllmax.png</PackageIconUrl>
1616
<PackageTags>.NET Wrapper C# Push PushBullet PB</PackageTags>
17-
<AssemblyVersion>0.0.2.7</AssemblyVersion>
18-
<FileVersion>0.0.2.7</FileVersion>
17+
<AssemblyVersion>0.0.2.8</AssemblyVersion>
18+
<FileVersion>0.0.2.8</FileVersion>
1919
<RepositoryUrl>https://github.com/Adomix/PushBulletNet</RepositoryUrl>
2020
<RepositoryType>Wrapper</RepositoryType>
2121
<Authors>Mango</Authors>
22-
<PackageReleaseNotes>0.2.7: Redid exceptions</PackageReleaseNotes>
22+
<PackageReleaseNotes>0.2.8: Cleaned up some code, added CreateChatAsync and CreateSubscriptionAsync</PackageReleaseNotes>
2323
<Company>N/A</Company>
2424
<NeutralLanguage>en</NeutralLanguage>
2525
</PropertyGroup>

0 commit comments

Comments
 (0)