Skip to content

Commit

Permalink
Merge pull request #134 from mineral-dart/feat-implement-http-endpoin…
Browse files Browse the repository at this point in the history
…t-repository

feat: implement http endpoint repositories
  • Loading branch information
LeadcodeDev authored Sep 12, 2023
2 parents a86ef80 + 324bd0b commit 14d9800
Show file tree
Hide file tree
Showing 16 changed files with 1,205 additions and 0 deletions.
54 changes: 54 additions & 0 deletions lib/internal/services/http/discord_endpoint_repository.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import 'package:mineral/internal/services/http/repositories/audit_log_repository.dart';
import 'package:mineral/internal/services/http/repositories/auto_moderation_repository.dart';
import 'package:mineral/internal/services/http/repositories/channel_repository.dart';
import 'package:mineral/internal/services/http/repositories/emoji_repository.dart';
import 'package:mineral/internal/services/http/repositories/guild_repository.dart';
import 'package:mineral/internal/services/http/repositories/guild_scheduled_event_repository.dart';
import 'package:mineral/internal/services/http/repositories/guild_template_repository.dart';
import 'package:mineral/internal/services/http/repositories/invite_repository.dart';
import 'package:mineral/internal/services/http/repositories/state_instance_repository.dart';
import 'package:mineral/internal/services/http/repositories/sticker_repository.dart';
import 'package:mineral/internal/services/http/repositories/user_repository.dart';
import 'package:mineral/internal/services/http/repositories/voice_repository.dart';
import 'package:mineral/internal/services/http/repositories/webhook_repository.dart';

final class DiscordEndpointRepository {
/// Get [Channel] endpoints
final ChannelRepository channels = ChannelRepository();

/// Get [Emoji] endpoints
final EmojiRepository emojis = EmojiRepository();

/// Get [AutoModeration] endpoints
final AutoModerationRepository moderation = AutoModerationRepository();

/// Get [AuditLog] endpoints
final AuditLogRepository auditLogs = AuditLogRepository();

/// Get [Guild] endpoints
final GuildRepository guilds = GuildRepository();

/// Get [ScheduledEvent] endpoints
final GuildScheduledEventRepository scheduledEvents = GuildScheduledEventRepository();

/// Get [GuildTemplate] endpoints
final GuildTemplateRepository templates = GuildTemplateRepository();

/// Get [Invite] endpoints
final InviteRepository invites = InviteRepository();

/// Get [StageInstance] endpoints
final StageInstanceRepository stageInstances = StageInstanceRepository();

/// Get [Sticker] endpoints
final StickerRepository stickers = StickerRepository();

/// Get [User] endpoints
final UserRepository users = UserRepository();

/// Get [Voice] endpoints
final VoiceRepository voice = VoiceRepository();

/// Get [Webhook] endpoints
final WebhookRepository webhooks = WebhookRepository();
}
3 changes: 3 additions & 0 deletions lib/internal/services/http/discord_http_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:mineral/internal/services/http/builders/discord_get_builder.dart
import 'package:mineral/internal/services/http/builders/discord_patch_builder.dart';
import 'package:mineral/internal/services/http/builders/discord_post_builder.dart';
import 'package:mineral/internal/services/http/builders/discord_put_builder.dart';
import 'package:mineral/internal/services/http/discord_endpoint_repository.dart';
import 'package:mineral/services/http/header_bucket.dart';
import 'package:mineral/services/http/http_client_contract.dart';
import 'package:mineral/services/http/http_request_dispatcher.dart';
Expand All @@ -18,6 +19,8 @@ class DiscordHttpClient extends Injectable implements HttpClientContract {
/// Client used to make requests
final Client _client = Client();

final DiscordEndpointRepository endpoints = DiscordEndpointRepository();

/// Dispatcher used to dispatch requests under pools
@override
late final HttpRequestDispatcher dispatcher;
Expand Down
12 changes: 12 additions & 0 deletions lib/internal/services/http/repositories/audit_log_repository.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/// [AuditLog] repository
///
/// Related to the official [Discord API documentation](https://discord.com/developers/docs/resources/audit-log)
final class AuditLogRepository {
/// Get audit log
/// Related [official documentation](https://discord.com/developers/docs/resources/audit-log#get-guild-audit-log)
/// ```dart
/// final uri = http.endpoints.auditLogs.get('1234');
/// ```
String get({ required String guildId }) =>
Uri(pathSegments: ['guilds', guildId, 'audit-logs']).path;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/// Repository for the [AutoModeration]
///
/// Related [official documentation](https://discord.com/developers/docs/resources/auto-moderation)
final class AutoModerationRepository {
/// Returns a list of [AutoModeration] objects for the given [Guild].
/// Related to the official [Discord API](https://discord.com/developers/docs/resources/auto-moderation#list-auto-moderation-rules-for-guild) documentation
/// ```dart
/// final moderation = await client.moderation.list(guildId: '1234567890');
/// ```
String list({ required String guildId }) => Uri(pathSegments: ['guilds', guildId, 'auto-moderation', 'rules']).path;

/// Returns an [AutoModeration] object for the given [Guild] and rule IDs.
/// Related to the official [Discord API](https://discord.com/developers/docs/resources/auto-moderation#get-auto-moderation-rule) documentation
/// ```dart
/// final moderation = await client.moderation.get(guildId: '1234567890', ruleId: '1234567890');
/// ```
String get({ required String guildId, required String ruleId }) =>
Uri(pathSegments: ['guilds', guildId, 'auto-moderation', 'rules', ruleId]).path;

/// Create a new [AutoModeration] for the given [Guild].
/// Related to the official [Discord API](https://discord.com/developers/docs/resources/auto-moderation#create-auto-moderation-rule) documentation
/// ```dart
/// final moderation = await client.moderation.create(guildId: '1234567890', ruleId: '1234567890');
/// ```
String create({ required String guildId }) => Uri(pathSegments: ['guilds', guildId, 'auto-moderation', 'rules']).path;

/// Modify the given [AutoModeration].
/// Related to the official [Discord API](https://discord.com/developers/docs/resources/auto-moderation#modify-auto-moderation-rule) documentation
/// ```dart
/// final moderation = await client.moderation.update(guildId: '1234567890', ruleId: '1234567890');
/// ```
String update({ required String guildId, required String ruleId }) =>
Uri(pathSegments: ['guilds', guildId, 'auto-moderation', 'rules', ruleId]).path;

/// Delete the given [AutoModeration].
/// Related to the official [Discord API](https://discord.com/developers/docs/resources/auto-moderation#delete-auto-moderation-rule) documentation
/// ```dart
/// final moderation = await client.moderation.delete(guildId: '1234567890', ruleId: '1234567890');
/// ```
String delete({ required String guildId, required String ruleId }) =>
Uri(pathSegments: ['guilds', guildId, 'auto-moderation', 'rules', ruleId]).path;
}
25 changes: 25 additions & 0 deletions lib/internal/services/http/repositories/channel_repository.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
final class ChannelRepository {
/// Get one channel from Discord API.
/// Related [official documentation](https://discord.com/developers/docs/resources/channel#get-channel)
/// ```dart
/// final uri = http.endpoints.channels.one('1234');
/// ```
String one({ required String channelId }) =>
Uri(pathSegments: ['channels', channelId]).path;

/// Update one channel from Discord API.
/// Related [official documentation](https://discord.com/developers/docs/resources/channel#modify-channel)
/// ```dart
/// final uri = http.endpoints.channels.update('1234');
/// ```
String update({ required String channelId }) =>
Uri(pathSegments: ['channels', channelId]).path;

/// Delete one channel from Discord API.
/// Related [official documentation](https://discord.com/developers/docs/resources/channel#deleteclose-channel)
/// ```dart
/// final uri = http.endpoints.channels.delete('1234');
/// ```
String delete({ required String channelId }) =>
Uri(pathSegments: ['channels', channelId]).path;
}
43 changes: 43 additions & 0 deletions lib/internal/services/http/repositories/emoji_repository.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/// Repository for the [Emoji] resource.
/// Related official documentation: https://discord.com/developers/docs/resources/emoji
final class EmojiRepository {
/// Returns a list of [Emoji] objects for the given [Guild].
/// Related to the official [Discord API](https://discord.com/developers/docs/resources/emoji#list-guild-emojis) documentation
/// ```dart
/// final emojis = await http.endpoints.emojis.list(guildId: '1234567890');
/// ```
String list({ required String guildId }) =>
Uri(pathSegments: ['guilds', guildId, 'emojis']).path;

/// Returns an [Emoji] object for the given [Guild] and emoji IDs.
/// Related to the official [Discord API](https://discord.com/developers/docs/resources/emoji#get-guild-emoji) documentation
/// ```dart
/// final emoji = await http.endpoints.emojis.get(guildId: '1234567890', emojiId: '1234567890');
/// ```
String get({ required String guildId, required String emojiId }) =>
Uri(pathSegments: ['guilds', guildId, 'emojis', emojiId]).path;

/// Create a new [Emoji] for the given [Guild].
/// Related to the official [Discord API](https://discord.com/developers/docs/resources/emoji#create-guild-emoji) documentation
/// ```dart
/// final emoji = await http.endpoints.emojis.create(guildId: '1234567890', emojiId: '1234567890');
/// ```
String create({ required String guildId }) =>
Uri(pathSegments: ['guilds', guildId, 'emojis']).path;

/// Modify the given [Emoji].
/// Related to the official [Discord API](https://discord.com/developers/docs/resources/emoji#modify-guild-emoji) documentation
/// ```dart
/// final emoji = await http.endpoints.emojis.update(guildId: '1234567890', emojiId: '1234567890');
/// ```
String update({ required String guildId, required String emojiId }) =>
Uri(pathSegments: ['guilds', guildId, 'emojis', emojiId]).path;

/// Delete the given [Emoji].
/// Related to the official [Discord API](https://discord.com/developers/docs/resources/emoji#delete-guild-emoji) documentation
/// ```dart
/// final emoji = await http.endpoints.emojis.delete(guildId: '1234567890', emojiId: '1234567890');
/// ```
String delete({ required String guildId, required String emojiId }) =>
Uri(pathSegments: ['guilds', guildId, 'emojis', emojiId]).path;
}
Loading

0 comments on commit 14d9800

Please sign in to comment.