-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ✨ add more API methods; update example; fix ActivityParty struc…
…t; refactor HttpClient
- Loading branch information
Showing
10 changed files
with
179 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#ifndef EKIZU_REQUEST_BULK_DELETE_MESSAGES_HPP | ||
#define EKIZU_REQUEST_BULK_DELETE_MESSAGES_HPP | ||
|
||
#include <ekizu/snowflake.hpp> | ||
#include <net/http.hpp> | ||
|
||
namespace ekizu | ||
{ | ||
struct BulkDeleteMessages { | ||
BulkDeleteMessages( | ||
const std::function<Result<net::HttpResponse>(net::HttpRequest)> | ||
&make_request, | ||
Snowflake channel_id, | ||
const std::vector<Snowflake> &message_ids); | ||
|
||
operator net::HttpRequest() const; | ||
|
||
[[nodiscard]] Result<net::HttpResponse> send(); | ||
|
||
private: | ||
Snowflake m_channel_id; | ||
std::vector<Snowflake> m_message_ids; | ||
std::function<Result<net::HttpResponse>(net::HttpRequest)> | ||
m_make_request; | ||
}; | ||
} // namespace ekizu | ||
|
||
#endif // EKIZU_REQUEST_BULK_DELETE_MESSAGES_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#ifndef EKIZU_REQUEST_DELETE_MESSAGE_HPP | ||
#define EKIZU_REQUEST_DELETE_MESSAGE_HPP | ||
|
||
#include <ekizu/snowflake.hpp> | ||
#include <net/http.hpp> | ||
|
||
namespace ekizu | ||
{ | ||
struct DeleteMessage { | ||
DeleteMessage( | ||
const std::function<Result<net::HttpResponse>(net::HttpRequest)> | ||
&make_request, | ||
Snowflake channel_id, Snowflake message_id); | ||
|
||
operator net::HttpRequest() const; | ||
|
||
[[nodiscard]] Result<net::HttpResponse> send(); | ||
|
||
private: | ||
Snowflake m_channel_id; | ||
Snowflake m_message_id; | ||
std::function<Result<net::HttpResponse>(net::HttpRequest)> | ||
m_make_request; | ||
}; | ||
} // namespace ekizu | ||
|
||
#endif // EKIZU_REQUEST_DELETE_MESSAGE_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#include <ekizu/request/bulk_delete_messages.hpp> | ||
#include <nlohmann/json.hpp> | ||
|
||
namespace ekizu | ||
{ | ||
BulkDeleteMessages::BulkDeleteMessages( | ||
const std::function<Result<net::HttpResponse>(net::HttpRequest)> | ||
&make_request, | ||
Snowflake channel_id, const std::vector<Snowflake> &message_ids) | ||
: m_channel_id{ channel_id } | ||
, m_message_ids{ message_ids } | ||
, m_make_request{ make_request } | ||
{ | ||
} | ||
|
||
BulkDeleteMessages::operator net::HttpRequest() const | ||
{ | ||
return { | ||
net::HttpMethod::Post, | ||
fmt::format("/channels/{}/messages/bulk-delete", m_channel_id), | ||
nlohmann::json{ { "messages", m_message_ids } }.dump(), | ||
{}, | ||
}; | ||
} | ||
|
||
Result<net::HttpResponse> BulkDeleteMessages::send() | ||
{ | ||
if (!m_make_request) { | ||
return tl::make_unexpected(std::make_error_code( | ||
std::errc::operation_not_permitted)); | ||
} | ||
|
||
return m_make_request(*this); | ||
} | ||
} // namespace ekizu |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#include <ekizu/request/delete_message.hpp> | ||
|
||
namespace ekizu | ||
{ | ||
DeleteMessage::DeleteMessage( | ||
const std::function<Result<net::HttpResponse>(net::HttpRequest)> | ||
&make_request, | ||
Snowflake channel_id, Snowflake message_id) | ||
: m_channel_id{ channel_id } | ||
, m_message_id{ message_id } | ||
, m_make_request{ make_request } | ||
{ | ||
} | ||
|
||
DeleteMessage::operator net::HttpRequest() const | ||
{ | ||
return { | ||
net::HttpMethod::Delete, | ||
fmt::format("/channels/{}/messages/{}", m_channel_id, | ||
m_message_id), | ||
{}, | ||
{}, | ||
}; | ||
} | ||
|
||
Result<net::HttpResponse> DeleteMessage::send() | ||
{ | ||
if (!m_make_request) { | ||
return tl::make_unexpected(std::make_error_code( | ||
std::errc::operation_not_permitted)); | ||
} | ||
|
||
return m_make_request(*this); | ||
} | ||
} // namespace ekizu |