import 'dart:convert'; import 'package:dio/dio.dart'; import 'package:libac_dart/discord/structures/application.dart'; import 'endpoints.dart'; class ApplicationPacket { /// This will request the current application instance. static Future getCurrentApplication() async { Dio dio = Dio(); var reply = await dio.get( "${DiscordEndpoints.BaseURL}${DiscordEndpoints.Applications}${DiscordEndpoints.ME}"); String jsonReply = reply.data as String; return Application.fromJson(jsonReply); } /// This will update the current application instance. static Future updateApplication(EditApplication app) async { Dio dio = Dio(); var reply = await dio.patch( "${DiscordEndpoints.BaseURL}${DiscordEndpoints.Applications}${DiscordEndpoints.ME}", data: app.encode()); String jsonReply = reply.data as String; return Application.fromJson(jsonReply); } } class EditApplication { String? customInstallUrl; String? description; String? roleConnectionsVerifyUrl; OAuth2InstallParams? installParams; List? integrationTypesConfig; int? flags; String? icon; String? coverImage; String? interactionEndpointURL; List? tags; EditApplication( {this.customInstallUrl, this.description, this.roleConnectionsVerifyUrl, this.installParams, this.integrationTypesConfig, this.flags, this.icon, this.coverImage, this.interactionEndpointURL, this.tags}); String encode() { return json.encode(toJson()); } Map toJson() { List> AIT = []; if (integrationTypesConfig != null) { for (var entry in integrationTypesConfig!) { AIT.add(entry.toJson()); } } return { if (customInstallUrl != null) "custom_install_url": customInstallUrl, if (description != null) "description": description, if (roleConnectionsVerifyUrl != null) "role_connections_verification_url": roleConnectionsVerifyUrl, if (installParams != null) "install_params": installParams!.toJson(), if (integrationTypesConfig != null) "integration_types_config": AIT, if (flags != null) "flags": flags, if (icon != null) "icon": icon, if (coverImage != null) "cover_image": coverImage, if (interactionEndpointURL != null) "interaction_endpoint_url": interactionEndpointURL, if (tags != null) "tags": tags }; } }