From efd8f05b287a9cd0b577b121a0407d03e323c772 Mon Sep 17 00:00:00 2001 From: ComradeCrow Date: Tue, 16 May 2023 16:42:41 -0700 Subject: session testing --- src/invapi.cpp | 17 +++++++++++++++-- src/invapi.hpp | 4 ++++ src/main.cpp | 4 ++-- 3 files changed, 21 insertions(+), 4 deletions(-) (limited to 'src') 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 InvidiousApi::getInstances() { vector 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 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 #include +#include #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 -- cgit 1.4.1-2-gfad0