diff options
| author | 2017-07-12 21:31:12 -0400 | |
|---|---|---|
| committer | 2017-07-12 21:31:12 -0400 | |
| commit | 9cf261ba8ba4fd9929d275cc793d48d13df624f3 (patch) | |
| tree | 2eb47ab96bde081a84c5dd7c8107a21cb8a3511c /src/web_service/web_backend.cpp | |
| parent | Merge pull request #2815 from mailwl/bossp (diff) | |
| parent | web_backend: Specify api-version on JSON post. (diff) | |
| download | yuzu-9cf261ba8ba4fd9929d275cc793d48d13df624f3.tar.gz yuzu-9cf261ba8ba4fd9929d275cc793d48d13df624f3.tar.xz yuzu-9cf261ba8ba4fd9929d275cc793d48d13df624f3.zip | |
Merge pull request #2819 from bunnei/telemetry-submit
Telemetry: Submit logged data to the Citra service
Diffstat (limited to 'src/web_service/web_backend.cpp')
| -rw-r--r-- | src/web_service/web_backend.cpp | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/web_service/web_backend.cpp b/src/web_service/web_backend.cpp new file mode 100644 index 000000000..13e4555ac --- /dev/null +++ b/src/web_service/web_backend.cpp | |||
| @@ -0,0 +1,52 @@ | |||
| 1 | // Copyright 2017 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <cpr/cpr.h> | ||
| 6 | #include <stdlib.h> | ||
| 7 | #include "common/logging/log.h" | ||
| 8 | #include "web_service/web_backend.h" | ||
| 9 | |||
| 10 | namespace WebService { | ||
| 11 | |||
| 12 | static constexpr char API_VERSION[]{"1"}; | ||
| 13 | static constexpr char ENV_VAR_USERNAME[]{"CITRA_WEB_SERVICES_USERNAME"}; | ||
| 14 | static constexpr char ENV_VAR_TOKEN[]{"CITRA_WEB_SERVICES_TOKEN"}; | ||
| 15 | |||
| 16 | static std::string GetEnvironmentVariable(const char* name) { | ||
| 17 | const char* value{getenv(name)}; | ||
| 18 | if (value) { | ||
| 19 | return value; | ||
| 20 | } | ||
| 21 | return {}; | ||
| 22 | } | ||
| 23 | |||
| 24 | const std::string& GetUsername() { | ||
| 25 | static const std::string username{GetEnvironmentVariable(ENV_VAR_USERNAME)}; | ||
| 26 | return username; | ||
| 27 | } | ||
| 28 | |||
| 29 | const std::string& GetToken() { | ||
| 30 | static const std::string token{GetEnvironmentVariable(ENV_VAR_TOKEN)}; | ||
| 31 | return token; | ||
| 32 | } | ||
| 33 | |||
| 34 | void PostJson(const std::string& url, const std::string& data) { | ||
| 35 | if (url.empty()) { | ||
| 36 | LOG_ERROR(WebService, "URL is invalid"); | ||
| 37 | return; | ||
| 38 | } | ||
| 39 | |||
| 40 | if (GetUsername().empty() || GetToken().empty()) { | ||
| 41 | LOG_ERROR(WebService, "Environment variables %s and %s must be set to POST JSON", | ||
| 42 | ENV_VAR_USERNAME, ENV_VAR_TOKEN); | ||
| 43 | return; | ||
| 44 | } | ||
| 45 | |||
| 46 | cpr::PostAsync(cpr::Url{url}, cpr::Body{data}, cpr::Header{{"Content-Type", "application/json"}, | ||
| 47 | {"x-username", GetUsername()}, | ||
| 48 | {"x-token", GetToken()}, | ||
| 49 | {"api-version", API_VERSION}}); | ||
| 50 | } | ||
| 51 | |||
| 52 | } // namespace WebService | ||