79 lines
2.3 KiB
Dart
79 lines
2.3 KiB
Dart
import 'dart:convert';
|
|
|
|
import 'package:dio/dio.dart';
|
|
import 'package:libac_dart/discord/structures/application.dart';
|
|
|
|
import 'endpoints.dart';
|
|
|
|
class ApplicationPacket {
|
|
static Future<Application> 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);
|
|
}
|
|
|
|
static Future<Application> 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<ApplicationIntegrationType>? integrationTypesConfig;
|
|
int? flags;
|
|
String? icon;
|
|
String? coverImage;
|
|
String? interactionEndpointURL;
|
|
List<String>? 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<String, dynamic> toJson() {
|
|
List<Map<String, dynamic>> 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
|
|
};
|
|
}
|
|
}
|