summaryrefslogtreecommitdiff
path: root/src/api/OlympicsAPI.cpp
diff options
context:
space:
mode:
authorSteru <jerrydream111@gmail.com>2024-08-16 22:19:42 +0200
committerOrangerot <purple@orangerot.dev>2024-08-26 11:19:38 +0200
commitb672b4698c721fa6dfd5dff965e08059d51bddda (patch)
treed81b53ec11376d14847e129335e89901995b3d13 /src/api/OlympicsAPI.cpp
parentcd69d722717c5ae40360f7cec22e191aa735b675 (diff)
Compacted competitors into one object, deleted API class (now in sportmodel).
Diffstat (limited to 'src/api/OlympicsAPI.cpp')
-rw-r--r--src/api/OlympicsAPI.cpp140
1 files changed, 0 insertions, 140 deletions
diff --git a/src/api/OlympicsAPI.cpp b/src/api/OlympicsAPI.cpp
deleted file mode 100644
index 0334800..0000000
--- a/src/api/OlympicsAPI.cpp
+++ /dev/null
@@ -1,140 +0,0 @@
-
-#include "OlympicsAPI.h"
-#include <string>
-#include <stdexcept>
-
-// networking
-#include <QEventLoop>
-#include <QNetworkAccessManager>
-#include <QNetworkRequest>
-#include <QNetworkReply>
-#include <QUrl>
-#include <QUrlQuery>
-
-// json parsing
-#include <QFile>
-#include <QJsonValue>
-#include <QJsonDocument>
-#include <QJsonObject>
-#include <QVariantMap>
-#include <QJsonArray>
-
-
-using namespace std;
-
-/**
- * @brief OlympicsAPI::getSportData Requests the current data from the Olympics API of a certain discipline.
- * @param sport The discipline to request.
- * @return The current information provided by the API endpoint.
- */
-QJsonObject OlympicsAPI::getSportData(OlympicsAPI::Disciplines sport) {
- string shortName = this->getDisciplineShort(sport);
-
- if (USE_API_REQUEST) {
- // create custom temporary event loop on stack
- QEventLoop eventLoop;
-
- // "quit()" the event-loop, when the network request "finished()"
- QNetworkAccessManager mgr;
- QObject::connect(&mgr, SIGNAL(finished(QNetworkReply*)), &eventLoop, SLOT(quit()));
-
- QString endpoint = (API_LINK + shortName).c_str();
-
- // the HTTP request
- QNetworkRequest req( (QUrl( endpoint )) );
- QNetworkReply *reply = mgr.get(req);
- eventLoop.exec(); // blocks stack until "finished()" has been called
-
- if (reply->error() == QNetworkReply::NoError) {
- //success
-
- QString strReply = (QString)reply->readAll();
-
- //parse json
- QJsonDocument jsonResponse = QJsonDocument::fromJson(strReply.toUtf8());
-
- QJsonObject jsonObj = jsonResponse.object();
-
- delete reply;
-
- return jsonObj;
- }
- else {
- //failure
- delete reply;
-
- throw invalid_argument("API request failed.");
- }
- }
-
- // if API is not used, open locally stored data
- QString filePath = ("../../res/mock/" + shortName + ".json").c_str();
- QFile file( filePath );
-
- if(!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
- throw invalid_argument("Could not open file to read data of the given discipline.");
- } else {
- QString text = file.readAll();
- file.close();
- return (QJsonDocument::fromJson(text.toUtf8())).object();
- }
-}
-
-/**
- * @brief OlympicsAPI::getDisciplineShort Get the discipline's short name defined by the IOC (International Olympic Committee)
- * @param sport The sport you want to get the name from.
- * @return The short name as a string.
- */
-string OlympicsAPI::getDisciplineShort(OlympicsAPI::Disciplines sport) {
- switch (sport) {
- case OlympicsAPI::Disciplines::AquaticsArtisticSwimming: return "SWA";
- case OlympicsAPI::Disciplines::AquaticsDiving: return "DIV";
- case OlympicsAPI::Disciplines::AquaticsMarathonSwimming: return "OWS";
- case OlympicsAPI::Disciplines::AquaticsSwimming: return "SWM";
- case OlympicsAPI::Disciplines::AquaticsWaterPolo: return "WPO";
- case OlympicsAPI::Disciplines::Archery: return "ARC";
- case OlympicsAPI::Disciplines::Athletics: return "ATH";
- case OlympicsAPI::Disciplines::Badminton: return "BDM";
- case OlympicsAPI::Disciplines::Basketball3v3: return "BK3";
- case OlympicsAPI::Disciplines::Basketball: return "BKB";
- case OlympicsAPI::Disciplines::Boxing: return "BOX";
- case OlympicsAPI::Disciplines::Breaking: return "BKG";
- case OlympicsAPI::Disciplines::CanoeingSprint: return "CSP";
- case OlympicsAPI::Disciplines::CanoeingSlalom: return "CSL";
- case OlympicsAPI::Disciplines::CyclingBMXFreestyle: return "BMF";
- case OlympicsAPI::Disciplines::CyclingBMXRacing: return "BMX";
- case OlympicsAPI::Disciplines::CyclingMaountainBike: return "MTB";
- case OlympicsAPI::Disciplines::CyclingRoad: return "CRD";
- case OlympicsAPI::Disciplines::CyclingTrack: return "CTR";
- case OlympicsAPI::Disciplines::EquestrianDressage: return "EDR";
- case OlympicsAPI::Disciplines::EquestrianEventing: return "EVE";
- case OlympicsAPI::Disciplines::EquestrianJumping: return "EJP";
- case OlympicsAPI::Disciplines::Fencing: return "FEN";
- case OlympicsAPI::Disciplines::FieldHockey: return "HOC";
- case OlympicsAPI::Disciplines::Football: return "FBL";
- case OlympicsAPI::Disciplines::Golf: return "GLF";
- case OlympicsAPI::Disciplines::GymnasticsArtistic: return "GAR";
- case OlympicsAPI::Disciplines::GymnasticsRhythmic: return "GRY";
- case OlympicsAPI::Disciplines::GymnasticsTrampoline: return "GTR";
- case OlympicsAPI::Disciplines::HandballIndoor: return "HBL";
- case OlympicsAPI::Disciplines::Judo: return "JUD";
- case OlympicsAPI::Disciplines::ModernPentathlon: return "MPN";
- case OlympicsAPI::Disciplines::Rowing: return "ROW";
- case OlympicsAPI::Disciplines::Rugby7: return "RU7";
- case OlympicsAPI::Disciplines::Sailing: return "SAL";
- case OlympicsAPI::Disciplines::Shooting: return "SHO";
- case OlympicsAPI::Disciplines::Skateboarding: return "SKB";
- case OlympicsAPI::Disciplines::SportClimbing: return "CLB";
- case OlympicsAPI::Disciplines::Surfing: return "SRF";
- case OlympicsAPI::Disciplines::TableTennis: return "TTE";
- case OlympicsAPI::Disciplines::Taekwondo: return "TKW";
- case OlympicsAPI::Disciplines::Tennis: return "TEN";
- case OlympicsAPI::Disciplines::Triathlon: return "TRI";
- case OlympicsAPI::Disciplines::VolleyballBeach: return "VBV";
- case OlympicsAPI::Disciplines::VolleyballIndoor: return "VVO";
- case OlympicsAPI::Disciplines::Weightlifting: return "WLF";
- case OlympicsAPI::Disciplines::WrestlingFreestyle: return "WRE";
- case OlympicsAPI::Disciplines::WrestlingGrecoRoman: return "WRG";
- default: return "ARC"; // default, which should not be possible, because of enum
- }
-}