-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api): Improvements to how API requests are made (#432)
* Display hold entry time based on proximity * Navaids by id and time strings * Event handler for aircraft entering holds * Event handler for aircraft exiting holds * Include continuables * Lots of classes * Try more things * Bootstrap it in the plugin * It works... wow * A load of changes I dont wanna lose * More tweaking * More tweak * Getting closer * Way more tweaking * It works * Updater and loader compile * Load hold data * Locking * Updated todos * Tracking status of api requests * Utils tests at least building * fix(initialaltitude): Dont allow initial altitude recycle on aircraft out of range (#430) * fix(initialaltitude): Dont allow initial altitude recycle on aircraft out of range * More changes * fix(initialheading): Dont allow initial heading recycle on aircraft out of range (#431) * fix(initialheading): Dont allow initial heading recycle on aircraft out of range Fix #429 * Format * chore(release): 4.2.1 [skip ci] ## [4.2.1](4.2.0...4.2.1) (2022-02-12) ### Bug Fixes * **initialaltitude:** Dont allow initial altitude recycle on aircraft out of range ([#430](#430)) ([cd3fd0e](cd3fd0e)) * **initialheading:** Dont allow initial heading recycle on aircraft out of range ([#431](#431)) ([e4fd211](e4fd211)), closes [#429](#429) * Finish SettingRepositoryTest * Test for api bootstrap * Curl request factory test * Api factory test * Header applicator test * Api request test, the big one * ApiRequestData test * Exception test * Request factory test * ApiSettings Test * Settings factory test * Url builder test * Settings provider test * Curl performer test * Curl performer factory test * Response test * Curl request test * Http method test * Status code test * Json setting file test * String trimming functions * Configuration menu item test and base test case * Api bootstrap tests * Api testing framework * Style things * Timeout on api request waiting Co-authored-by: semantic-release-bot <semantic-release-bot@martynus.net>
- Loading branch information
1 parent
676bea3
commit 0b4527f
Showing
149 changed files
with
4,287 additions
and
1,268 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 |
---|---|---|
@@ -1,3 +1,9 @@ | ||
[submodule "third_party/googletest"] | ||
path = third_party/googletest | ||
url = git@github.com:google/googletest.git | ||
[submodule "third_party/continuable"] | ||
path = third_party/continuable | ||
url = git@github.com:Naios/continuable.git | ||
[submodule "third_party/function2"] | ||
path = third_party/function2 | ||
url = https://github.com/Naios/function2.git |
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
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,38 @@ | ||
#include "ApiConfigurationMenuItem.h" | ||
#include "BootstrapApi.h" | ||
#include "api/ApiBootstrap.h" | ||
#include "api/ApiFactory.h" | ||
#include "bootstrap/PersistenceContainer.h" | ||
#include "euroscope/CallbackFunction.h" | ||
#include "plugin/FunctionCallEventHandler.h" | ||
#include "radarscreen/ConfigurableDisplayCollection.h" | ||
|
||
using UKControllerPlugin::Bootstrap::PersistenceContainer; | ||
using UKControllerPlugin::Euroscope::CallbackFunction; | ||
|
||
namespace UKControllerPlugin::Api { | ||
void BootstrapApi(PersistenceContainer& container) | ||
{ | ||
container.apiFactory = | ||
UKControllerPluginUtils::Api::Bootstrap(*container.settingsRepository, *container.windows); | ||
container.api = UKControllerPluginUtils::Api::BootstrapLegacy(*container.apiFactory, *container.curl); | ||
} | ||
|
||
void BootstrapConfigurationMenuItem( | ||
const PersistenceContainer& container, RadarScreen::ConfigurableDisplayCollection& configurableDisplays) | ||
{ | ||
unsigned int callbackId = container.pluginFunctionHandlers->ReserveNextDynamicFunctionId(); | ||
std::shared_ptr<ApiConfigurationMenuItem> menuItem = std::make_shared<ApiConfigurationMenuItem>( | ||
*container.apiFactory->SettingsProvider(), *container.windows, callbackId); | ||
|
||
CallbackFunction menuItemSelectedCallback( | ||
callbackId, // NOLINT | ||
"API Configuration Menu Item Selected", | ||
[menuItem](int functionId, std::string subject, RECT screenObjectArea) { | ||
menuItem->Configure(functionId, std::move(subject), screenObjectArea); | ||
}); | ||
|
||
container.pluginFunctionHandlers->RegisterFunctionCall(menuItemSelectedCallback); | ||
configurableDisplays.RegisterDisplay(menuItem); | ||
} | ||
} // namespace UKControllerPlugin::Api |
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,17 @@ | ||
#pragma once | ||
|
||
namespace UKControllerPlugin { | ||
namespace Bootstrap { | ||
struct PersistenceContainer; | ||
} // namespace Bootstrap | ||
namespace RadarScreen { | ||
class ConfigurableDisplayCollection; | ||
} // namespace RadarScreen | ||
} // namespace UKControllerPlugin | ||
|
||
namespace UKControllerPlugin::Api { | ||
void BootstrapApi(Bootstrap::PersistenceContainer& container); | ||
void BootstrapConfigurationMenuItem( | ||
const Bootstrap::PersistenceContainer& container, | ||
RadarScreen::ConfigurableDisplayCollection& configurableDisplays); | ||
} // namespace UKControllerPlugin::Api |
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,53 @@ | ||
#include "FirstTimeApiAuthorisationChecker.h" | ||
#include "api/ApiRequestFactory.h" | ||
#include "api/ApiRequestException.h" | ||
#include "api/ApiSettingsProviderInterface.h" | ||
#include "windows/WinApiInterface.h" | ||
|
||
using UKControllerPluginUtils::Api::ApiRequestException; | ||
|
||
namespace UKControllerPlugin::Api { | ||
|
||
void FirstTimeApiAuthorisationCheck( | ||
UKControllerPluginUtils::Api::ApiSettingsProviderInterface& settingsProviderInterface, | ||
Windows::WinApiInterface& windows) | ||
{ | ||
ApiRequest() | ||
.Get("authorise") | ||
.Then([]() { LogInfo("Api authorisation check was successful."); }) | ||
.Catch([&windows, &settingsProviderInterface](const ApiRequestException& exception) { | ||
LogWarning( | ||
"Api authorisation check failed, status code was " + | ||
std::to_string(static_cast<uint64_t>(exception.StatusCode()))); | ||
|
||
if (UKControllerPluginUtils::Http::IsServerError(exception.StatusCode())) { | ||
windows.OpenMessageBox( | ||
L"Server error whilst checking API authentication, some functionality may not work as " | ||
"expected. If your configuration is otherwise correct, functionality will resume when the " | ||
"service is online again.", | ||
L"UKCP API Server Error", | ||
MB_OK | MB_ICONWARNING); | ||
return; | ||
} | ||
|
||
auto messageResponse = windows.OpenMessageBox( | ||
L"API authentication failed. Please re-download your credentails from the VATSIM UK website " | ||
"and click OK to try again. If this problem persists, please contact the Web Services Department.", | ||
L"UKCP API Config Invalid", | ||
MB_OKCANCEL | MB_ICONWARNING); | ||
|
||
if (messageResponse == IDCANCEL || !settingsProviderInterface.Reload()) { | ||
LogInfo("User elected not to set API key after authentication failure"); | ||
windows.OpenMessageBox( | ||
L"You have elected not to complete API setup at this time. Some functionality of the plugin " | ||
"may not work as expected.", | ||
L"UKCP API Config Not Updated", | ||
MB_OK | MB_ICONWARNING); | ||
return; | ||
} | ||
|
||
FirstTimeApiAuthorisationCheck(settingsProviderInterface, windows); | ||
}) | ||
.Await(); | ||
} | ||
} // namespace UKControllerPlugin::Api |
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 | ||
|
||
namespace UKControllerPluginUtils::Api { | ||
class ApiSettingsProviderInterface; | ||
} // namespace UKControllerPluginUtils::Api | ||
|
||
namespace UKControllerPlugin::Windows { | ||
class WinApiInterface; | ||
} // namespace UKControllerPlugin::Windows | ||
namespace UKControllerPlugin::Api { | ||
void FirstTimeApiAuthorisationCheck( | ||
UKControllerPluginUtils::Api::ApiSettingsProviderInterface& settingsProviderInterface, | ||
Windows::WinApiInterface& windows); | ||
} // namespace UKControllerPlugin::Api |
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,21 @@ | ||
#include "FirstTimeApiConfigLoader.h" | ||
#include "api/ApiSettingsProviderInterface.h" | ||
|
||
namespace UKControllerPlugin::Api { | ||
|
||
auto LocateConfig(UKControllerPluginUtils::Api::ApiSettingsProviderInterface& settingsProvider) -> bool | ||
{ | ||
if (settingsProvider.Has()) { | ||
LogInfo("Api configuration successfully loaded"); | ||
return true; | ||
} | ||
|
||
if (!settingsProvider.Reload()) { | ||
LogInfo("First time api config load, user elected not to load config"); | ||
return false; | ||
} | ||
|
||
LogInfo("First time api config load completed"); | ||
return true; | ||
} | ||
} // namespace UKControllerPlugin::Api |
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 | ||
|
||
namespace UKControllerPluginUtils::Api { | ||
class ApiSettingsProviderInterface; | ||
} // namespace UKControllerPluginUtils::Api | ||
|
||
namespace UKControllerPlugin::Api { | ||
auto LocateConfig(UKControllerPluginUtils::Api::ApiSettingsProviderInterface& settingsProvider) -> bool; | ||
} // namespace UKControllerPlugin::Api |
Oops, something went wrong.