Start to add in some networking stuff

This commit is contained in:
zontreck 2024-07-10 02:46:33 -07:00
parent b820274f95
commit 15d80c1ab3
5 changed files with 93 additions and 7 deletions

View file

@ -0,0 +1,79 @@
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
};
}
}

View file

@ -0,0 +1,6 @@
class DiscordEndpoints {
static const APIVersion = 10;
static const BaseURL = "https://discord.com/api/v${APIVersion}";
static const ME = "/@me";
static const Applications = "/applications";
}