Alter networking to include authorization bot header, and add initial sticker calls
This commit is contained in:
parent
eae1f391de
commit
6079fa9a01
6 changed files with 95 additions and 6 deletions
|
@ -8,7 +8,7 @@ import 'endpoints.dart';
|
|||
class ApplicationPacket {
|
||||
/// This will request the current application instance.
|
||||
static Future<Application> getCurrentApplication() async {
|
||||
Dio dio = Dio();
|
||||
Dio dio = Dio(DiscordSessionSettings.getOptions);
|
||||
var reply = await dio.get(
|
||||
"${DiscordEndpoints.BaseURL}${DiscordEndpoints.Applications}${DiscordEndpoints.ME}");
|
||||
String jsonReply = reply.data as String;
|
||||
|
@ -18,7 +18,7 @@ class ApplicationPacket {
|
|||
|
||||
/// This will update the current application instance.
|
||||
static Future<Application> updateApplication(EditApplication app) async {
|
||||
Dio dio = Dio();
|
||||
Dio dio = Dio(DiscordSessionSettings.getOptions);
|
||||
var reply = await dio.patch(
|
||||
"${DiscordEndpoints.BaseURL}${DiscordEndpoints.Applications}${DiscordEndpoints.ME}",
|
||||
data: app.encode());
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import 'package:dio/dio.dart';
|
||||
|
||||
/// Contains currently supported endpoints and URLs.
|
||||
class DiscordEndpoints {
|
||||
/// Currently this is set to 10
|
||||
|
@ -8,4 +10,12 @@ class DiscordEndpoints {
|
|||
static const ME = "/@me";
|
||||
static const Applications = "/applications";
|
||||
static const Users = "/users";
|
||||
static const Stickers = "/stickers";
|
||||
}
|
||||
|
||||
class DiscordSessionSettings {
|
||||
static String BOT_TOKEN = "";
|
||||
|
||||
static BaseOptions get getOptions => BaseOptions(
|
||||
headers: {"Authorization": "Bot ${DiscordSessionSettings.BOT_TOKEN}"});
|
||||
}
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
import 'package:dio/dio.dart';
|
||||
import 'package:libac_dart/discord/networking/endpoints.dart';
|
||||
import 'package:libac_dart/structs/Snowflake.dart';
|
||||
|
||||
import '../structures/sticker.dart';
|
||||
|
||||
class StickerPackets {
|
||||
static Future<Sticker> getSticker(Snowflake id) async {
|
||||
Dio dio = Dio(DiscordSessionSettings.getOptions);
|
||||
var reply = await dio.get(
|
||||
"${DiscordEndpoints.BaseURL}${DiscordEndpoints.Stickers}/${id.toString()}");
|
||||
|
||||
return Sticker.fromJson(reply.data);
|
||||
}
|
||||
}
|
|
@ -8,7 +8,7 @@ import '../structures/user.dart';
|
|||
class UserPackets {
|
||||
/// Requests the current user from Discord's servers
|
||||
static Future<User> getCurrentUser() async {
|
||||
Dio dio = Dio();
|
||||
Dio dio = Dio(DiscordSessionSettings.getOptions);
|
||||
var reply = await dio.get(
|
||||
"${DiscordEndpoints.BaseURL}${DiscordEndpoints.Users}${DiscordEndpoints.ME}");
|
||||
|
||||
|
@ -19,7 +19,7 @@ class UserPackets {
|
|||
///
|
||||
/// [id] is expected to be a valid Discord User ID
|
||||
static Future<User> getUser(int id) async {
|
||||
Dio dio = Dio();
|
||||
Dio dio = Dio(DiscordSessionSettings.getOptions);
|
||||
var reply = await dio
|
||||
.get("${DiscordEndpoints.BaseURL}${DiscordEndpoints.Users}/${id}");
|
||||
|
||||
|
@ -30,7 +30,7 @@ class UserPackets {
|
|||
///
|
||||
/// Fires a User Update gateway event
|
||||
static Future<User> updateCurrentUser(ModifyCurrentUserPacket mcup) async {
|
||||
Dio dio = Dio();
|
||||
Dio dio = Dio(DiscordSessionSettings.getOptions);
|
||||
var reply = await dio.patch(
|
||||
"${DiscordEndpoints.BaseURL}${DiscordEndpoints.Users}${DiscordEndpoints.ME}",
|
||||
data: mcup.encode());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue