about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/invapi.cpp17
-rw-r--r--src/invapi.hpp4
-rw-r--r--src/main.cpp4
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