-
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.
- Loading branch information
Showing
13 changed files
with
284 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#pragma once | ||
#include <abyss/utils/JSON/JSONUtil.hpp> | ||
|
||
namespace abyss::Network::GitHub::Issue | ||
{ | ||
/// <summary> | ||
/// GitHub Issue | ||
/// </summary> | ||
struct Issue | ||
{ | ||
[[JSON_BIND(id)]] | ||
s3d::int32 id; | ||
|
||
[[JSON_BIND(number)]] | ||
s3d::int32 number; | ||
|
||
[[JSON_BIND(title)]] | ||
s3d::String title; | ||
|
||
[[JSON_BIND(url)]] | ||
s3d::String url; | ||
}; | ||
|
||
using IssueList = s3d::Array<Issue>; | ||
} |
13 changes: 13 additions & 0 deletions
13
Re-Abyss/app/utils/Network/GItHub__/Issue/ListRepositoryIssuesApi.cpp
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,13 @@ | ||
#include <abyss/utils/Network/GitHub/Issue/ListRepositoryIssuesApi.hpp> | ||
|
||
namespace abyss::Network::GitHub::Issue | ||
{ | ||
ApiResponse<ListRepositoryIssuesApi::Response> ListRepositoryIssuesApi::Request( | ||
const s3d::String& owner, | ||
const s3d::String& repo, | ||
const s3d::String& token | ||
) | ||
{ | ||
return BaseApi::GetTo<Response>(s3d::Fmt(Url)(owner, repo), token); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
Re-Abyss/app/utils/Network/GItHub__/Issue/ListRepositoryIssuesApi.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#pragma once | ||
#include <abyss/utils/Network/GitHub/base/BaseApi.hpp> | ||
#include <abyss/utils/Network/GitHub/Issue/Issue.hpp> | ||
|
||
namespace abyss::Network::GitHub::Issue | ||
{ | ||
class ListRepositoryIssuesApi | ||
{ | ||
public: | ||
static constexpr auto* Url = U"https://api.github.com/repos/{}/{}/issues"; | ||
using Response = IssueList; | ||
public: | ||
|
||
static ApiResponse<Response> Request( | ||
const s3d::String& owner, | ||
const s3d::String& repo, | ||
const s3d::String& token | ||
); | ||
}; | ||
} |
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,20 @@ | ||
#include <abyss/utils/Network/GitHub/GitHub.hpp> | ||
#include <abyss/utils/Network/GitHub/Issue/ListRepositoryIssuesApi.hpp> | ||
#include <abyss/utils/Network/GitHub/GraphQL/GraphQLApi.hpp> | ||
#include <Siv3D.hpp> | ||
|
||
namespace abyss::Network::GitHub | ||
{ | ||
s3d::JSON GitHub::GraphQL(const s3d::String& query, const s3d::String& token) | ||
{ | ||
return GraphQL::GraphQLApi::Request(query, token); | ||
} | ||
ApiResponse<Issue::ListRepositoryIssuesApi::Response> GitHub::ListRepositoryIssues(const s3d::String& owner, const s3d::String& repo, const s3d::String& token) | ||
{ | ||
return Issue::ListRepositoryIssuesApi::Request(owner, repo, token); | ||
} | ||
bool GitHub::OpenIssueByBrowser(const s3d::String& owner, const s3d::String& repo, const s3d::int32 number) | ||
{ | ||
return System::LaunchBrowser(U"https://github.com/{}/{}/issues/{}"_fmt(owner, repo, number)); | ||
} | ||
} |
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,37 @@ | ||
#pragma once | ||
#include <Siv3D/String.hpp> | ||
#include <abyss/utils/Network/GitHub/Issue/ListRepositoryIssuesApi.hpp> | ||
|
||
namespace abyss::Network::GitHub | ||
{ | ||
class GitHub | ||
{ | ||
public: | ||
/// <summary> | ||
/// グラフクエリをリクエスト | ||
/// </summary> | ||
/// <param name="query"></param> | ||
/// <param name="token"></param> | ||
/// <returns></returns> | ||
static s3d::JSON GraphQL(const s3d::String& query, const s3d::String& token); | ||
|
||
static ApiResponse<Issue::ListRepositoryIssuesApi::Response> ListRepositoryIssues( | ||
const s3d::String& owner, | ||
const s3d::String& repo, | ||
const s3d::String& token | ||
); | ||
|
||
/// <summary> | ||
/// ブラウザでイシューを開く | ||
/// </summary> | ||
/// <param name="owner"></param> | ||
/// <param name="repo"></param> | ||
/// <param name="number"></param> | ||
/// <returns></returns> | ||
static bool OpenIssueByBrowser( | ||
const s3d::String& owner, | ||
const s3d::String& repo, | ||
const s3d::int32 number | ||
); | ||
}; | ||
} |
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,13 @@ | ||
#include <abyss/utils/Network/GitHub/GraphQL/GraphQLApi.hpp> | ||
#include <abyss/utils/Network/GitHub/base/BaseApi.hpp> | ||
|
||
namespace abyss::Network::GitHub::GraphQL | ||
{ | ||
s3d::JSON GraphQLApi::Request(const s3d::String& query, const s3d::String& token) | ||
{ | ||
JSON request; | ||
request[U"query"] = query; | ||
return BaseApi::Post(Url, token, request).value_or(s3d::JSON::Invalid()); | ||
} | ||
} | ||
|
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,14 @@ | ||
#pragma once | ||
#include <Siv3D/JSON.hpp> | ||
|
||
namespace abyss::Network::GitHub::GraphQL | ||
{ | ||
class GraphQLApi | ||
{ | ||
public: | ||
static constexpr auto* Url = U"https://api.github.com/graphql"; | ||
public: | ||
|
||
static s3d::JSON Request(const s3d::String& query, const s3d::String& token); | ||
}; | ||
} |
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,25 @@ | ||
#pragma once | ||
#include <abyss/utils/JSON/JSONUtil.hpp> | ||
|
||
namespace abyss::Network::GitHub::Issue | ||
{ | ||
/// <summary> | ||
/// GitHub Issue | ||
/// </summary> | ||
struct Issue | ||
{ | ||
[[JSON_BIND(id)]] | ||
s3d::int32 id; | ||
|
||
[[JSON_BIND(number)]] | ||
s3d::int32 number; | ||
|
||
[[JSON_BIND(title)]] | ||
s3d::String title; | ||
|
||
[[JSON_BIND(url)]] | ||
s3d::String url; | ||
}; | ||
|
||
using IssueList = s3d::Array<Issue>; | ||
} |
13 changes: 13 additions & 0 deletions
13
Re-Abyss/app/utils/Network/GitHub_/Issue/ListRepositoryIssuesApi.cpp
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,13 @@ | ||
#include <abyss/utils/Network/GitHub/Issue/ListRepositoryIssuesApi.hpp> | ||
|
||
namespace abyss::Network::GitHub::Issue | ||
{ | ||
ApiResponse<ListRepositoryIssuesApi::Response> ListRepositoryIssuesApi::Request( | ||
const s3d::String& owner, | ||
const s3d::String& repo, | ||
const s3d::String& token | ||
) | ||
{ | ||
return BaseApi::GetTo<Response>(s3d::Fmt(Url)(owner, repo), token); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
Re-Abyss/app/utils/Network/GitHub_/Issue/ListRepositoryIssuesApi.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#pragma once | ||
#include <abyss/utils/Network/GitHub/base/BaseApi.hpp> | ||
#include <abyss/utils/Network/GitHub/Issue/Issue.hpp> | ||
|
||
namespace abyss::Network::GitHub::Issue | ||
{ | ||
class ListRepositoryIssuesApi | ||
{ | ||
public: | ||
static constexpr auto* Url = U"https://api.github.com/repos/{}/{}/issues"; | ||
using Response = IssueList; | ||
public: | ||
|
||
static ApiResponse<Response> Request( | ||
const s3d::String& owner, | ||
const s3d::String& repo, | ||
const s3d::String& token | ||
); | ||
}; | ||
} |
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,9 @@ | ||
#pragma once | ||
#include <expected> | ||
#include <Siv3D/Types.hpp> | ||
|
||
namespace abyss::Network::GitHub | ||
{ | ||
template<class T> | ||
using ApiResponse = std::expected<T, s3d::int32>; | ||
} |
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,44 @@ | ||
#include <abyss/utils/Network/GitHub/base/BaseApi.hpp> | ||
|
||
namespace abyss::Network::GitHub | ||
{ | ||
ApiResponse<s3d::JSON> BaseApi::Get(const s3d::String& url, const s3d::String& token) | ||
{ | ||
MemoryWriter writer; | ||
auto result = s3d::SimpleHTTP::Get( | ||
url, | ||
{ | ||
{U"User-Agent", U"Awesome-Octocat-App"}, | ||
{U"Accept", U"application/vnd.github+json"}, | ||
{U"Authorization", U"Bearer {}"_fmt(token)}, | ||
{U"X-GitHub-Api-Version", U"2022-11-28"} | ||
}, writer); | ||
if (result.isOK()) { | ||
return s3d::JSON::Load(MemoryReader(writer.getBlob())); | ||
} else { | ||
return std::unexpected(static_cast<s3d::int32>(result.getStatusCode())); | ||
} | ||
} | ||
ApiResponse<s3d::JSON> BaseApi::Post(const s3d::String& url, const s3d::String& token, const s3d::JSON& param) | ||
{ | ||
std::string src = Format(param).narrow(); | ||
MemoryWriter writer; | ||
auto result = s3d::SimpleHTTP::Post( | ||
url, | ||
{ | ||
{U"User-Agent", U"Awesome-Octocat-App"}, | ||
{U"Accept", U"application/vnd.github+json"}, | ||
{U"Authorization", U"Bearer {}"_fmt(token)}, | ||
{U"X-GitHub-Api-Version", U"2022-11-28"} | ||
}, | ||
src.c_str(), | ||
src.length(), | ||
writer | ||
); | ||
if (result.isOK()) { | ||
return s3d::JSON::Load(MemoryReader(writer.getBlob())); | ||
} else { | ||
return std::unexpected(static_cast<s3d::int32>(result.getStatusCode())); | ||
} | ||
} | ||
} |
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 @@ | ||
#pragma once | ||
#include <abyss/utils/Network/GitHub/base/ApiResponse.hpp> | ||
#include <abyss/utils/JSON/JSONUtil.hpp> | ||
|
||
namespace abyss::Network::GitHub | ||
{ | ||
class BaseApi | ||
{ | ||
public: | ||
static ApiResponse<s3d::JSON> Get( | ||
const s3d::String& url, | ||
const s3d::String& token | ||
); | ||
static ApiResponse<s3d::JSON> Post( | ||
const s3d::String& url, | ||
const s3d::String& token, | ||
const s3d::JSON& param | ||
); | ||
template<class T> | ||
static ApiResponse<T> GetTo( | ||
const s3d::String& url, | ||
const s3d::String& token | ||
) { | ||
auto result = Get(url, token); | ||
if (!result.has_value()) { | ||
return std::unexpected(result.error()); | ||
} | ||
return JSONUtil::FromJSON<T>(result.value()); | ||
} | ||
}; | ||
} |