@@ -20,6 +20,8 @@ internal interface IPushBulletService
20
20
Task < IEnumerable < PushBulletChat > > GetChats ( ) ;
21
21
Task PushNotification ( NotificationPostModel request ) ;
22
22
Task CreateDevice ( NewDeviceModel model ) ;
23
+ Task CreateChat ( string email ) ;
24
+ Task CreateSubscription ( string channeltag ) ;
23
25
}
24
26
25
27
internal class PushBulletService : IPushBulletService
@@ -82,6 +84,16 @@ public async Task CreateDevice(NewDeviceModel model)
82
84
await Post ( _token , "devices" , pushRequest ) . ConfigureAwait ( false ) ;
83
85
}
84
86
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
+
85
97
private async Task < T > Get < T > ( string token , string url )
86
98
{
87
99
_client . DefaultRequestHeaders . Add ( ACCESS_TOKEN_HEADER , token ) ;
@@ -92,7 +104,7 @@ private async Task<T> Get<T>(string token, string url)
92
104
{
93
105
var error = await response . Content . ReadAsStreamAsync ( ) . ConfigureAwait ( false ) ;
94
106
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 } ") ;
96
108
}
97
109
98
110
var content = await response . Content . ReadAsStreamAsync ( ) . ConfigureAwait ( false ) ;
@@ -113,7 +125,7 @@ private async Task Post(string token, string url, string request)
113
125
{
114
126
var error = await response . Content . ReadAsStreamAsync ( ) . ConfigureAwait ( false ) ;
115
127
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 } ") ;
117
129
}
118
130
119
131
_client . DefaultRequestHeaders . Clear ( ) ;
0 commit comments