Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
KubaZ2 committed Dec 16, 2022
1 parent 94dec17 commit f2f61f1
Show file tree
Hide file tree
Showing 12 changed files with 198 additions and 5 deletions.
6 changes: 1 addition & 5 deletions NetCord/Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,15 @@ public class Application : Entity, IJsonModel<JsonModels.JsonApplication>
public User? Owner { get; }
public string VerifyKey => _jsonModel.VerifyKey;
public Team? Team { get; }
/// <summary>
/// If this application is a game sold on Discord, this field will be the guild to which it has been linked.
/// </summary>
public ulong? GuildId => _jsonModel.GuildId;
public ulong? PrimarySkuId => _jsonModel.PrimarySkuId;
public string? Slug => _jsonModel.Slug;
public string? CoverImageHash => _jsonModel.CoverImageHash;
public ApplicationFlags? Flags => _jsonModel.Flags;
public IReadOnlyList<string>? Tags => _jsonModel.Tags;

public ApplicationInstallParams? InstallParams { get; }

public string? CustomInstallUrl => _jsonModel.CustomInstallUrl;
public string? RoleConnectionsVerificationUrl => _jsonModel.RoleConnectionsVerificationUrl;

public Application(JsonModels.JsonApplication jsonModel, RestClient client)
{
Expand Down
3 changes: 3 additions & 0 deletions NetCord/JsonModels/JsonApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ public partial class JsonApplication : JsonEntity
[JsonPropertyName("custom_install_url")]
public string? CustomInstallUrl { get; set; }

[JsonPropertyName("role_connections_verification_url")]
public string? RoleConnectionsVerificationUrl { get; set; }

[JsonSerializable(typeof(JsonApplication))]
public partial class JsonApplicationSerializerContext : JsonSerializerContext
{
Expand Down
21 changes: 21 additions & 0 deletions NetCord/JsonModels/JsonApplicationRoleConnection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Text.Json.Serialization;

namespace NetCord.JsonModels;

public partial class JsonApplicationRoleConnection
{
[JsonPropertyName("platform_name")]
public string? PlatformName { get; set; }

[JsonPropertyName("platform_username")]
public string? PlatformUsername { get; set; }

[JsonPropertyName("metadata")]
public IReadOnlyDictionary<string, string> Metadata { get; set; }

[JsonSerializable(typeof(JsonApplicationRoleConnection))]
public partial class JsonApplicationRoleConnectionSerializerContext : JsonSerializerContext
{
public static JsonApplicationRoleConnectionSerializerContext WithOptions { get; } = new(new(ToObjectExtensions._options));
}
}
39 changes: 39 additions & 0 deletions NetCord/JsonModels/JsonApplicationRoleConnectionMetadata.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System.Globalization;
using System.Text.Json.Serialization;

using NetCord.Rest;

namespace NetCord.JsonModels;

public partial class JsonApplicationRoleConnectionMetadata
{
[JsonPropertyName("type")]
public ApplicationRoleConnectionMetadataType Type { get; set; }

[JsonPropertyName("key")]
public string Key { get; set; }

[JsonPropertyName("name")]
public string Name { get; set; }

[JsonPropertyName("name_localizations")]
public IReadOnlyDictionary<CultureInfo, string>? NameLocalizations { get; set; }

[JsonPropertyName("description")]
public string Description { get; set; }

[JsonPropertyName("description_localizations")]
public IReadOnlyDictionary<CultureInfo, string>? DescriptionLocalizations { get; set; }

[JsonSerializable(typeof(JsonApplicationRoleConnectionMetadata))]
public partial class JsonApplicationRoleConnectionMetadataSerializerContext : JsonSerializerContext
{
public static JsonApplicationRoleConnectionMetadataSerializerContext WithOptions { get; } = new(new(ToObjectExtensions._options));
}

[JsonSerializable(typeof(IEnumerable<JsonApplicationRoleConnectionMetadata>))]
public partial class IEnumerableOfJsonApplicationRoleConnectionMetadataSerializerContext : JsonSerializerContext
{
public static IEnumerableOfJsonApplicationRoleConnectionMetadataSerializerContext WithOptions { get; } = new(new(ToObjectExtensions._options));
}
}
16 changes: 16 additions & 0 deletions NetCord/Rest/ApplicationRoleConnection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace NetCord.Rest;

public class ApplicationRoleConnection : IJsonModel<JsonModels.JsonApplicationRoleConnection>
{
JsonModels.JsonApplicationRoleConnection IJsonModel<JsonModels.JsonApplicationRoleConnection>.JsonModel => _jsonModel;
private readonly JsonModels.JsonApplicationRoleConnection _jsonModel;

public ApplicationRoleConnection(JsonModels.JsonApplicationRoleConnection jsonModel)
{
_jsonModel = jsonModel;
}

public string? PlatformName => _jsonModel.PlatformName;
public string? PlatformUsername => _jsonModel.PlatformUsername;
public IReadOnlyDictionary<string, string> Metadata => _jsonModel.Metadata;
}
21 changes: 21 additions & 0 deletions NetCord/Rest/ApplicationRoleConnectionMetadata.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Globalization;

namespace NetCord.Rest;

public class ApplicationRoleConnectionMetadata : IJsonModel<JsonModels.JsonApplicationRoleConnectionMetadata>
{
JsonModels.JsonApplicationRoleConnectionMetadata IJsonModel<JsonModels.JsonApplicationRoleConnectionMetadata>.JsonModel => _jsonModel;
private readonly JsonModels.JsonApplicationRoleConnectionMetadata _jsonModel;

public ApplicationRoleConnectionMetadata(JsonModels.JsonApplicationRoleConnectionMetadata jsonModel)
{
_jsonModel = jsonModel;
}

public ApplicationRoleConnectionMetadataType Type => _jsonModel.Type;
public string Key => _jsonModel.Key;
public string Name => _jsonModel.Name;
public IReadOnlyDictionary<CultureInfo, string>? NameLocalizations => _jsonModel.NameLocalizations;
public string Description => _jsonModel.Description;
public IReadOnlyDictionary<CultureInfo, string>? DescriptionLocalizations => _jsonModel.DescriptionLocalizations;
}
45 changes: 45 additions & 0 deletions NetCord/Rest/ApplicationRoleConnectionMetadataProperties.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System.Globalization;
using System.Text.Json.Serialization;

namespace NetCord.Rest;

public partial class ApplicationRoleConnectionMetadataProperties
{
public ApplicationRoleConnectionMetadataProperties(ApplicationRoleConnectionMetadataType type, string key, string name, string description)
{
Type = type;
Key = key;
Name = name;
Description = description;
}

[JsonPropertyName("type")]
public ApplicationRoleConnectionMetadataType Type { get; }

[JsonPropertyName("key")]
public string Key { get; }

[JsonPropertyName("name")]
public string Name { get; }

[JsonPropertyName("name_localizations")]
public IReadOnlyDictionary<CultureInfo, string>? NameLocalizations { get; set; }

[JsonPropertyName("description")]
public string Description { get; }

[JsonPropertyName("description_localizations")]
public IReadOnlyDictionary<CultureInfo, string>? DescriptionLocalizations { get; set; }

[JsonSerializable(typeof(ApplicationRoleConnectionMetadataProperties))]
public partial class ApplicationRoleConnectionMetadataPropertiesSerializerContext : JsonSerializerContext
{
public static ApplicationRoleConnectionMetadataPropertiesSerializerContext WithOptions { get; } = new(new(ToObjectExtensions._options));
}

[JsonSerializable(typeof(IEnumerable<ApplicationRoleConnectionMetadataProperties>))]
public partial class IEnumerableOfApplicationRoleConnectionMetadataPropertiesSerializerContext : JsonSerializerContext
{
public static IEnumerableOfApplicationRoleConnectionMetadataPropertiesSerializerContext WithOptions { get; } = new(new(ToObjectExtensions._options));
}
}
13 changes: 13 additions & 0 deletions NetCord/Rest/ApplicationRoleConnectionMetadataType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace NetCord.Rest;

public enum ApplicationRoleConnectionMetadataType
{
IntegerLessThanOrEqual = 1,
IntegerGreaterThanOrEqual = 2,
IntegerEqual = 3,
IntegerNotEqual = 4,
DateTimeLessThanOrEqual = 5,
DateTimeGreaterThanOrEqual = 6,
BooleanEqual = 7,
BooleanNotEqual = 8,
}
21 changes: 21 additions & 0 deletions NetCord/Rest/ApplicationRoleConnectionProperties.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Text.Json.Serialization;

namespace NetCord.Rest;

public partial class ApplicationRoleConnectionProperties
{
[JsonPropertyName("platform_name")]
public string? PlatformName { get; set; }

[JsonPropertyName("platform_username")]
public string? PlatformUsername { get; set; }

[JsonPropertyName("metadata")]
public IReadOnlyDictionary<string, string>? Metadata { get; set; }

[JsonSerializable(typeof(ApplicationRoleConnectionProperties))]
public partial class ApplicationRoleConnectionPropertiesSerializerContext : JsonSerializerContext
{
public static ApplicationRoleConnectionPropertiesSerializerContext WithOptions { get; } = new(new(ToObjectExtensions._options));
}
}
2 changes: 2 additions & 0 deletions NetCord/Rest/RateLimits/RouteParameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,6 @@ public enum RouteParameter
CreateGuildScheduledEvent,
ModifyGuildScheduledEvent,
GetGatewayBot,
GetApplicationRoleConnectionMetadataRecords,
UpdateApplicationRoleConnectionMetadataRecords,
}
10 changes: 10 additions & 0 deletions NetCord/Rest/RestClient.ApplicationRoleConnectionMetadata.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace NetCord.Rest;

public partial class RestClient
{
public async Task<IEnumerable<ApplicationRoleConnectionMetadata>> GetApplicationRoleConnectionMetadataRecordsAsync(ulong applicationId, RequestProperties? properties = null)
=> (await SendRequestAsync(HttpMethod.Get, $"/applications/{applicationId}/role-connections/metadata", new RateLimits.Route(RateLimits.RouteParameter.GetApplicationRoleConnectionMetadataRecords), properties).ConfigureAwait(false)).ToObject(JsonModels.JsonApplicationRoleConnectionMetadata.IEnumerableOfJsonApplicationRoleConnectionMetadataSerializerContext.WithOptions.IEnumerableJsonApplicationRoleConnectionMetadata).Select(m => new ApplicationRoleConnectionMetadata(m));

public async Task<IEnumerable<ApplicationRoleConnectionMetadata>> UpdateApplicationRoleConnectionMetadataRecordsAsync(ulong applicationId, IEnumerable<ApplicationRoleConnectionMetadataProperties> applicationRoleConnectionMetadataProperties, RequestProperties? properties = null)
=> (await SendRequestAsync(HttpMethod.Put, $"/applications/{applicationId}/role-connections/metadata", new(RateLimits.RouteParameter.UpdateApplicationRoleConnectionMetadataRecords), new JsonContent<IEnumerable<ApplicationRoleConnectionMetadataProperties>>(applicationRoleConnectionMetadataProperties, ApplicationRoleConnectionMetadataProperties.IEnumerableOfApplicationRoleConnectionMetadataPropertiesSerializerContext.WithOptions.IEnumerableApplicationRoleConnectionMetadataProperties), properties).ConfigureAwait(false)).ToObject(JsonModels.JsonApplicationRoleConnectionMetadata.IEnumerableOfJsonApplicationRoleConnectionMetadataSerializerContext.WithOptions.IEnumerableJsonApplicationRoleConnectionMetadata).Select(m => new ApplicationRoleConnectionMetadata(m));
}
6 changes: 6 additions & 0 deletions NetCord/Rest/RestClient.User.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,10 @@ public async Task<GroupDMChannel> CreateGroupDMChannelAsync(GroupDMChannelProper

public async Task<IReadOnlyDictionary<ulong, Connection>> GetCurrentUserConnectionsAsync(RequestProperties? properties = null)
=> (await SendRequestAsync(HttpMethod.Get, "/users/@me/connections", properties).ConfigureAwait(false)).ToObject(JsonModels.JsonConnection.JsonConnectionArraySerializerContext.WithOptions.JsonConnectionArray).ToDictionary(c => c.Id, c => new Connection(c, this));

public async Task<ApplicationRoleConnection> GetCurrentUserApplicationRoleConnectionAsync(ulong applicationId, RequestProperties? properties = null)
=> new((await SendRequestAsync(HttpMethod.Get, $"/users/@me/applications/{applicationId}/role-connection", properties).ConfigureAwait(false)).ToObject(JsonModels.JsonApplicationRoleConnection.JsonApplicationRoleConnectionSerializerContext.WithOptions.JsonApplicationRoleConnection));

public async Task<ApplicationRoleConnection> UpdateCurrentUserApplicationRoleConnectionAsync(ulong applicationId, ApplicationRoleConnectionProperties applicationRoleConnectionProperties, RequestProperties? properties = null)
=> new((await SendRequestAsync(HttpMethod.Put, $"/users/@me/applications/{applicationId}/role-connection", new JsonContent<ApplicationRoleConnectionProperties>(applicationRoleConnectionProperties, ApplicationRoleConnectionProperties.ApplicationRoleConnectionPropertiesSerializerContext.WithOptions.ApplicationRoleConnectionProperties), properties).ConfigureAwait(false)).ToObject(JsonModels.JsonApplicationRoleConnection.JsonApplicationRoleConnectionSerializerContext.WithOptions.JsonApplicationRoleConnection));
}

0 comments on commit f2f61f1

Please sign in to comment.