diff options
author | ComradeCrow <comradecrow@vivaldi.net> | 2023-05-16 16:42:41 -0700 |
---|---|---|
committer | ComradeCrow <comradecrow@vivaldi.net> | 2023-05-16 16:42:41 -0700 |
commit | efd8f05b287a9cd0b577b121a0407d03e323c772 (patch) | |
tree | 86b5f9b18db58e2f7cc81ac01ce89f425f53b840 | |
parent | ef43068ce29233115cff2bdac11fc882a71ed107 (diff) | |
download | ytcpp-efd8f05b287a9cd0b577b121a0407d03e323c772.tar.gz |
session testing
-rw-r--r-- | src/invapi.cpp | 17 | ||||
-rw-r--r-- | src/invapi.hpp | 4 | ||||
-rw-r--r-- | src/main.cpp | 4 |
3 files changed, 21 insertions, 4 deletions
diff --git a/src/invapi.cpp b/src/invapi.cpp index 3fd6632..59e91bf 100644 --- a/src/invapi.cpp +++ b/src/invapi.cpp @@ -15,13 +15,15 @@ using json = nlohmann::json; InvidiousApi::InvidiousApi(const string& url) { instanceUrl = url; + } vector<string> InvidiousApi::getInstances() { vector<string> result; cpr::Response r = cpr::Get(cpr::Url{"https://api.invidious.io/instances.json"}, - cpr::Parameters{{"sort_by", "health"}, {"fields", "uri,api"}}); + cpr::Parameters{{"sort_by", "health"}, {"fields", "uri,api"}}, + cpr::Timeout{5000}); if (r.status_code > 299) { @@ -42,7 +44,8 @@ vector<string> InvidiousApi::getInstances() { void InvidiousApi::saveInstancesToDb(SqliteInterface& sqldb) { cpr::Response r = cpr::Get(cpr::Url{"https://api.invidious.io/instances.json"}, - cpr::Parameters{{"sort_by", "health"}, {"fields", "uri,api,health,location"}}); + cpr::Parameters{{"sort_by", "health"}, {"fields", "uri,api,health,location"}}, + cpr::Timeout{5000}); if (r.status_code > 299) { @@ -59,6 +62,16 @@ void InvidiousApi::saveInstancesToDb(SqliteInterface& sqldb) { } } +void InvidiousApi::test() { + + session.SetUrl(cpr::Url{instanceUrl}); + session.SetParameters(cpr::Parameters{{"hello", "world"}}); + cpr::Response new_r = session.Get(); + + cout << new_r.url << endl; + cout << new_r.text << endl; +} + std::string InvidiousApi::getInstance() { return instanceUrl; diff --git a/src/invapi.hpp b/src/invapi.hpp index 3f07436..3fb4c05 100644 --- a/src/invapi.hpp +++ b/src/invapi.hpp @@ -2,6 +2,7 @@ #define INVAPI_H #include <string> #include <vector> +#include <cpr/cpr.h> #include "sqliteinterface.hpp" @@ -14,9 +15,12 @@ class InvidiousApi { static void saveInstancesToDb(SqliteInterface& sqldb); std::string getInstance(); void setInstance(const std::string& newUrl); + + void test(); private: std::string instanceUrl; + cpr::Session session; }; diff --git a/src/main.cpp b/src/main.cpp index 4bbd6db..d42c891 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -134,6 +134,6 @@ int main(int argc, char **argv) { parseSysArgs(argc, argv); SqliteInterface sqldb; - InvidiousApi::saveInstancesToDb(sqldb); - + InvidiousApi invapi("https://httpbin.org/get"); + invapi.test(); } \ No newline at end of file |