-
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 HttpClient; add CreateMessage; update examples
Added an HttpClient which will be used to interface with the Discord API. Multiple structures like the CreateMessage struct will be committed to model the payloads sent to the documented API routes.
- Loading branch information
Xminent
committed
Nov 1, 2023
1 parent
5d8b58b
commit 3e3c31c
Showing
8 changed files
with
290 additions
and
79 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,22 @@ | ||
#ifndef EKIZU_HTTP_CLIENT_HPP | ||
#define EKIZU_HTTP_CLIENT_HPP | ||
|
||
#include <ekizu/request/create_message.hpp> | ||
#include <ekizu/snowflake.hpp> | ||
|
||
namespace ekizu | ||
{ | ||
struct HttpClient { | ||
explicit HttpClient(std::string_view token); | ||
|
||
[[nodiscard]] CreateMessage create_message(Snowflake channel_id); | ||
|
||
private: | ||
[[nodiscard]] Result<net::HttpResponse> send(net::HttpRequest req); | ||
|
||
std::optional<net::HttpConnection> m_http; | ||
std::optional<std::string> m_token; | ||
}; | ||
} // namespace ekizu | ||
|
||
#endif // EKIZU_HTTP_CLIENT_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,31 @@ | ||
#ifndef EKIZU_REQUEST_CREATE_MESSAGE_HPP | ||
#define EKIZU_REQUEST_CREATE_MESSAGE_HPP | ||
|
||
#include <ekizu/message.hpp> | ||
#include <net/http.hpp> | ||
|
||
namespace ekizu | ||
{ | ||
struct CreateMessage { | ||
CreateMessage(std::function<Result<net::HttpResponse>(net::HttpRequest)>, | ||
Snowflake channel_id); | ||
|
||
operator net::HttpRequest() const; | ||
|
||
CreateMessage &with_content(std::string_view content) | ||
{ | ||
m_content = std::string{ content }; | ||
return *this; | ||
} | ||
|
||
[[nodiscard]] Result<net::HttpResponse> send(); | ||
|
||
private: | ||
Snowflake m_channel_id; | ||
std::optional<std::string> m_content; | ||
std::function<Result<net::HttpResponse>(net::HttpRequest)> | ||
m_make_request; | ||
}; | ||
} // namespace ekizu | ||
|
||
#endif // EKIZU_REQUEST_CREATE_MESSAGE_HPP |
Oops, something went wrong.