Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:02:33

0001 #pragma once
0002 
0003 #include <iostream>
0004 #include <vector>
0005 #include <stdexcept>
0006 #include <chrono>
0007 #include <curl/curl.h>
0008 #include <nlohmann/json.hpp>
0009 
0010 #include <nopayloadclient/config.hpp>
0011 #include <nopayloadclient/exception.hpp>
0012 #include <nopayloadclient/curlwrapper.hpp>
0013 
0014 
0015 namespace nopayloadclient {
0016 
0017 using nlohmann::json;
0018 using std::string;
0019 
0020 class RealWrapper : public CurlWrapper {
0021 public:
0022     RealWrapper() {};
0023     RealWrapper(const json& config);
0024 
0025     // Reading
0026     json get(const string& url);
0027     // Writing
0028     json del(const string& url);
0029     json put(const string& url);
0030     json put(const string& url, const json& data);
0031     json post(const string& url, const json& data);
0032 
0033 
0034 private:
0035     string base_url_;
0036     int n_retries_;
0037     bool print_time_stamps_;
0038 };
0039 
0040 struct Answer {
0041   CURLcode res;
0042   string readBuffer;
0043   long httpCode = 0;
0044 };
0045 
0046 class CurlSession{
0047     public:
0048         CurlSession(const string& _url, int n_retries);
0049         void logResults();
0050         json try_execute();
0051         json execute();
0052         void prepareGet();
0053         void prepareDelete();
0054         void preparePut();
0055         void preparePost(const json& data);
0056         void preparePut(const json& data);
0057     private:
0058         Answer ans;
0059         CURL *curl;
0060         string url;
0061         struct curl_slist *slist1 = NULL;
0062         string json_str;
0063         int n_retries_;
0064 };
0065 
0066 }