Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add push provider api #102

Merged
merged 1 commit into from
Mar 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/Clients/AppClient.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Net;
using System.Security.Cryptography;
using System.Text;
Expand Down Expand Up @@ -49,6 +50,22 @@ public async Task<AppCheckSqsResponse> CheckSqsPushAsync(AppCheckSqsRequest chec
public async Task<ApiResponse> RevokeTokensAsync(DateTimeOffset? issuedBefore)
=> await UpdateAppSettingsAsync(new AppSettingsRequest { RevokeTokensIssuedBefore = issuedBefore });

public async Task<UpsertPushProviderResponse> UpsertPushProviderAsync(PushProviderRequest pushProviderRequest)
=> await ExecuteRequestAsync<UpsertPushProviderResponse>("push_providers",
HttpMethod.POST,
HttpStatusCode.Created,
new Dictionary<string, PushProviderRequest> { { "push_provider", pushProviderRequest } });

public async Task<ListPushProvidersResponse> ListPushProvidersAsync()
=> await ExecuteRequestAsync<ListPushProvidersResponse>("push_providers",
HttpMethod.GET,
HttpStatusCode.OK);

public async Task<ApiResponse> DeletePushProviderAsync(PushProviderType providerType, string name)
=> await ExecuteRequestAsync<ApiResponse>($"push_providers/{providerType}/{name}",
HttpMethod.DELETE,
HttpStatusCode.OK);

public bool VerifyWebhook(string requestBody, string xSignature)
{
using (var sha = new HMACSHA256(Encoding.UTF8.GetBytes(_apiSecret)))
Expand Down
6 changes: 3 additions & 3 deletions src/Clients/FlagClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ public async Task<QueryMessageFlagsResponse> QueryMessageFlags(FlagMessageQueryR

public async Task<QueryFlagReportsResponse> QueryFlagReportsAsync(QueryFlagReportsRequest request)
=> await ExecuteRequestAsync<QueryFlagReportsResponse>("moderation/reports",
HttpMethod.POST,
HttpStatusCode.Created,
request);
HttpMethod.POST,
HttpStatusCode.Created,
request);

public async Task<ReviewFlagReportResponse> ReviewFlagReportAsync(string reportId, ReviewFlagReportRequest request)
=> await ExecuteRequestAsync<ReviewFlagReportResponse>($"moderation/reports/{reportId}",
Expand Down
12 changes: 12 additions & 0 deletions src/Clients/IAppClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@ public interface IAppClient
/// <remarks>https://getstream.io/chat/docs/dotnet-csharp/push_test/?language=csharp</remarks>
Task<AppCheckSqsResponse> CheckSqsPushAsync(AppCheckSqsRequest checkSqsRequest);

/// <summary>Inserts or creates a new push provider.</summary>
/// <remarks>https://getstream.io/chat/docs/dotnet-csharp/push_introduction/?language=csharp</remarks>
Task<UpsertPushProviderResponse> UpsertPushProviderAsync(PushProviderRequest pushProviderRequest);

/// <summary>Lists all push providers.</summary>
/// <remarks>https://getstream.io/chat/docs/dotnet-csharp/push_introduction/?language=csharp</remarks>
Task<ListPushProvidersResponse> ListPushProvidersAsync();

/// <summary>Deletes a push provider.</summary>
/// <remarks>https://getstream.io/chat/docs/dotnet-csharp/push_introduction/?language=csharp</remarks>
Task<ApiResponse> DeletePushProviderAsync(PushProviderType providerType, string name);

/// <summary>Validates whether the HMAC signature is correct for the message body.</summary>
/// <param name="requestBody">The request body to validate.</param>
/// <param name="xSignature">The signature provided in X-Signature header.</param>
Expand Down
2 changes: 1 addition & 1 deletion src/Models/Device.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace StreamChat.Models
{
public static class PushProvider
public static class PushProviderNames
ferhatelmas marked this conversation as resolved.
Show resolved Hide resolved
{
public const string APN = "apn";
public const string Firebase = "firebase";
Expand Down
79 changes: 79 additions & 0 deletions src/Models/PushProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace StreamChat.Models
{
peterdeme marked this conversation as resolved.
Show resolved Hide resolved
[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<PushProvider> PushProviders { get; set; }
}
}
peterdeme marked this conversation as resolved.
Show resolved Hide resolved