diff --git a/src/Clients/AppClient.cs b/src/Clients/AppClient.cs index f5756f1..5f0c139 100644 --- a/src/Clients/AppClient.cs +++ b/src/Clients/AppClient.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Net; using System.Security.Cryptography; using System.Text; @@ -49,6 +50,22 @@ public async Task CheckSqsPushAsync(AppCheckSqsRequest chec public async Task RevokeTokensAsync(DateTimeOffset? issuedBefore) => await UpdateAppSettingsAsync(new AppSettingsRequest { RevokeTokensIssuedBefore = issuedBefore }); + public async Task UpsertPushProviderAsync(PushProviderRequest pushProviderRequest) + => await ExecuteRequestAsync("push_providers", + HttpMethod.POST, + HttpStatusCode.Created, + new Dictionary { { "push_provider", pushProviderRequest } }); + + public async Task ListPushProvidersAsync() + => await ExecuteRequestAsync("push_providers", + HttpMethod.GET, + HttpStatusCode.OK); + + public async Task DeletePushProviderAsync(PushProviderType providerType, string name) + => await ExecuteRequestAsync($"push_providers/{providerType}/{name}", + HttpMethod.DELETE, + HttpStatusCode.OK); + public bool VerifyWebhook(string requestBody, string xSignature) { using (var sha = new HMACSHA256(Encoding.UTF8.GetBytes(_apiSecret))) diff --git a/src/Clients/FlagClient.cs b/src/Clients/FlagClient.cs index 866ee80..4faa047 100644 --- a/src/Clients/FlagClient.cs +++ b/src/Clients/FlagClient.cs @@ -38,9 +38,9 @@ public async Task QueryMessageFlags(FlagMessageQueryR public async Task QueryFlagReportsAsync(QueryFlagReportsRequest request) => await ExecuteRequestAsync("moderation/reports", - HttpMethod.POST, - HttpStatusCode.Created, - request); + HttpMethod.POST, + HttpStatusCode.Created, + request); public async Task ReviewFlagReportAsync(string reportId, ReviewFlagReportRequest request) => await ExecuteRequestAsync($"moderation/reports/{reportId}", diff --git a/src/Clients/IAppClient.cs b/src/Clients/IAppClient.cs index 7ced3eb..018639b 100644 --- a/src/Clients/IAppClient.cs +++ b/src/Clients/IAppClient.cs @@ -48,6 +48,18 @@ public interface IAppClient /// https://getstream.io/chat/docs/dotnet-csharp/push_test/?language=csharp Task CheckSqsPushAsync(AppCheckSqsRequest checkSqsRequest); + /// Inserts or creates a new push provider. + /// https://getstream.io/chat/docs/dotnet-csharp/push_introduction/?language=csharp + Task UpsertPushProviderAsync(PushProviderRequest pushProviderRequest); + + /// Lists all push providers. + /// https://getstream.io/chat/docs/dotnet-csharp/push_introduction/?language=csharp + Task ListPushProvidersAsync(); + + /// Deletes a push provider. + /// https://getstream.io/chat/docs/dotnet-csharp/push_introduction/?language=csharp + Task DeletePushProviderAsync(PushProviderType providerType, string name); + /// Validates whether the HMAC signature is correct for the message body. /// The request body to validate. /// The signature provided in X-Signature header. diff --git a/src/Models/Device.cs b/src/Models/Device.cs index 3417785..8b08f27 100644 --- a/src/Models/Device.cs +++ b/src/Models/Device.cs @@ -4,7 +4,7 @@ namespace StreamChat.Models { - public static class PushProvider + public static class PushProviderNames { public const string APN = "apn"; public const string Firebase = "firebase"; diff --git a/src/Models/PushProvider.cs b/src/Models/PushProvider.cs new file mode 100644 index 0000000..94d9aa7 --- /dev/null +++ b/src/Models/PushProvider.cs @@ -0,0 +1,79 @@ +using System; +using System.Collections.Generic; +using System.Runtime.Serialization; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; + +namespace StreamChat.Models +{ + [JsonConverter(typeof(StringEnumConverter))] + public enum PushProviderType + { + None, + + [EnumMember(Value = "firebase")] + Firebase, + + [EnumMember(Value = "apn")] + Apn, + + [EnumMember(Value = "huawei")] + Huawei, + + [EnumMember(Value = "xiaomi")] + Xiaomi, + } + + public class PushProviderRequest + { + public PushProviderType Type { get; set; } + public string Name { get; set; } + public string Description { get; set; } + [JsonProperty("disabled_at")] + public DateTimeOffset DisabledAt { get; set; } + [JsonProperty("disabled_reason")] + public string DisabledReason { get; set; } + + [JsonProperty("apn_auth_key")] + public string ApnAuthKey { get; set; } + [JsonProperty("apn_key_id")] + public string ApnKeyId { get; set; } + [JsonProperty("apn_team_id")] + public string ApnTeamId { get; set; } + [JsonProperty("apn_topic")] + public string ApnTopic { get; set; } + + [JsonProperty("firebase_credentials")] + public string FirebaseCredentials { get; set; } + + [JsonProperty("huawei_app_id")] + public string HuaweiAppId { get; set; } + [JsonProperty("huawei_app_secret")] + public string HuaweiAppSecret { get; set; } + + [JsonProperty("xiaomi_package_name")] + public string XiaomiPackageName { get; set; } + [JsonProperty("xiaomi_app_secret")] + public string XiaomiAppSecret { get; set; } + } + + public class PushProvider : PushProviderRequest + { + [JsonProperty("created_at")] + public DateTimeOffset CreatedAt { get; set; } + [JsonProperty("updated_at")] + public DateTimeOffset UpdatedAt { get; set; } + } + + public class UpsertPushProviderResponse : ApiResponse + { + [JsonProperty("push_provider")] + public PushProvider PushProvider { get; set; } + } + + public class ListPushProvidersResponse : ApiResponse + { + [JsonProperty("push_providers")] + public List PushProviders { get; set; } + } +} \ No newline at end of file