Start to add in some networking stuff
This commit is contained in:
parent
b820274f95
commit
15d80c1ab3
5 changed files with 93 additions and 7 deletions
1
Jenkinsfile
vendored
1
Jenkinsfile
vendored
|
@ -20,6 +20,7 @@ pipeline {
|
|||
#!/bin/bash
|
||||
unset WORKSPACE
|
||||
unset WORKSPACE_TMP
|
||||
rm -rf doc
|
||||
dart pub get
|
||||
dart doc
|
||||
tar -cvf docs.tgz doc/api/*
|
||||
|
|
|
@ -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
|
||||
};
|
||||
}
|
||||
}
|
6
lib/discord/networking/endpoints.dart
Normal file
6
lib/discord/networking/endpoints.dart
Normal 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";
|
||||
}
|
|
@ -4,7 +4,7 @@ import 'package:libac_dart/discord/structures/user.dart';
|
|||
import 'package:libac_dart/structs/Snowflake.dart';
|
||||
import 'package:libac_dart/utils/DictTools.dart';
|
||||
|
||||
class ApplicationPacket {
|
||||
class Application {
|
||||
bool botPublic;
|
||||
bool botRequiresCodeGrant;
|
||||
String? coverImage;
|
||||
|
@ -19,7 +19,7 @@ class ApplicationPacket {
|
|||
String? slug;
|
||||
String summary;
|
||||
|
||||
ApplicationPacket(
|
||||
Application(
|
||||
{required this.botPublic,
|
||||
required this.botRequiresCodeGrant,
|
||||
this.coverImage,
|
||||
|
@ -65,11 +65,11 @@ class ApplicationPacket {
|
|||
return json.encode(toJson());
|
||||
}
|
||||
|
||||
factory ApplicationPacket.fromJson(String js) {
|
||||
return ApplicationPacket.decode(json.decode(js));
|
||||
factory Application.fromJson(String js) {
|
||||
return Application.decode(json.decode(js));
|
||||
}
|
||||
|
||||
factory ApplicationPacket.decode(Map<String, dynamic> js) {
|
||||
factory Application.decode(Map<String, dynamic> js) {
|
||||
Map<String, ApplicationIntegrationType>? itc = null;
|
||||
if (js.containsKey("integration_types_config")) {
|
||||
itc = {};
|
||||
|
@ -80,7 +80,7 @@ class ApplicationPacket {
|
|||
}
|
||||
}
|
||||
|
||||
return ApplicationPacket(
|
||||
return Application(
|
||||
botPublic: js['bot_public'] as bool,
|
||||
botRequiresCodeGrant: js['bot_require_code_grant'] as bool,
|
||||
coverImage: setor(js, 'cover_image', null),
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
name: libac_dart
|
||||
description: "Aria's Creations code library"
|
||||
version: 1.2.071024+0213
|
||||
version: 1.2.071024+0246
|
||||
homepage: "https://zontreck.com"
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue