Compare commits
No commits in common. "bbc750d731c69751fe09750c105571c235f943b3" and "351144e7634983d550977a504e0983327ea06c85" have entirely different histories.
bbc750d731
...
351144e763
@ -9,9 +9,10 @@ public class Ntfy : NotificationConnector
|
||||
// ReSharper disable twice MemberCanBePrivate.Global
|
||||
public string endpoint { get; init; }
|
||||
public string auth { get; init; }
|
||||
public string topic { get; init; }
|
||||
private readonly string _topic = "tranga";
|
||||
private readonly HttpClient _client = new();
|
||||
|
||||
[JsonConstructor]
|
||||
public Ntfy(GlobalBase clone, string endpoint, string auth) : base(clone, NotificationConnectorType.Ntfy)
|
||||
{
|
||||
if (!baseUrlRex.IsMatch(endpoint))
|
||||
@ -22,29 +23,19 @@ public class Ntfy : NotificationConnector
|
||||
Log($"Error getting URI from provided endpoint-URI: {endpoint}");
|
||||
this.endpoint = match.Groups[1].Value;
|
||||
if (match.Groups[2].Success)
|
||||
topic = match.Groups[2].Value;
|
||||
else
|
||||
topic = "tranga";
|
||||
this.auth = auth;
|
||||
}
|
||||
|
||||
[JsonConstructor]
|
||||
public Ntfy(GlobalBase clone, string endpoint, string auth, string topic) : base(clone, NotificationConnectorType.Ntfy)
|
||||
{
|
||||
this.endpoint = endpoint;
|
||||
this.topic = topic.Length > 0 ? topic : "tranga";
|
||||
_topic = match.Groups[2].Value;
|
||||
this.auth = auth;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"Ntfy {endpoint} {topic}";
|
||||
return $"Ntfy {endpoint} {_topic}";
|
||||
}
|
||||
|
||||
public override void SendNotification(string title, string notificationText)
|
||||
{
|
||||
Log($"Sending notification: {title} - {notificationText}");
|
||||
MessageData message = new(title, topic, notificationText);
|
||||
MessageData message = new(title, _topic, notificationText);
|
||||
HttpRequestMessage request = new(HttpMethod.Post, $"{this.endpoint}?auth={this.auth}");
|
||||
request.Content = new StringContent(JsonConvert.SerializeObject(message, Formatting.None), Encoding.UTF8, "application/json");
|
||||
HttpResponseMessage response = _client.Send(request);
|
||||
|
Loading…
Reference in New Issue
Block a user