Put requester into namespace sc
This commit is contained in:
parent
c1638ec24d
commit
b798539502
@ -4,6 +4,8 @@
|
|||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
|
using namespace sc;
|
||||||
|
|
||||||
size_t requester::write_data(char *buf, size_t sz, size_t nmemb, void *user_data) {
|
size_t requester::write_data(char *buf, size_t sz, size_t nmemb, void *user_data) {
|
||||||
size_t realsize = sz * nmemb;
|
size_t realsize = sz * nmemb;
|
||||||
requester* req {reinterpret_cast<requester*>(user_data)};
|
requester* req {reinterpret_cast<requester*>(user_data)};
|
||||||
|
@ -6,34 +6,37 @@
|
|||||||
#include <curl/curl.h>
|
#include <curl/curl.h>
|
||||||
#include <libsclogging.hpp>
|
#include <libsclogging.hpp>
|
||||||
|
|
||||||
class requester {
|
namespace sc {
|
||||||
public:
|
|
||||||
// callback for data receiving
|
|
||||||
static size_t write_data(char* buf, size_t sz, size_t nmemb, void* user_data);
|
|
||||||
|
|
||||||
// this class is a RAII class for a curl handle
|
class requester {
|
||||||
requester();
|
public:
|
||||||
~requester();
|
// callback for data receiving
|
||||||
|
static size_t write_data(char* buf, size_t sz, size_t nmemb, void* user_data);
|
||||||
|
|
||||||
// forbid copying and moving
|
// this class is a RAII class for a curl handle
|
||||||
requester(const requester&) = delete;
|
requester();
|
||||||
requester& operator=(const requester&) = delete;
|
~requester();
|
||||||
requester(requester&&) = delete;
|
|
||||||
requester& operator=(requester&&) = delete;
|
|
||||||
|
|
||||||
// optional logger
|
// forbid copying and moving
|
||||||
void logger(sc::logger* logger) { _logger = logger; }
|
requester(const requester&) = delete;
|
||||||
|
requester& operator=(const requester&) = delete;
|
||||||
|
requester(requester&&) = delete;
|
||||||
|
requester& operator=(requester&&) = delete;
|
||||||
|
|
||||||
// perform a http get request
|
// optional logger
|
||||||
std::string get(const std::string& url);
|
void logger(sc::logger* logger) { _logger = logger; }
|
||||||
|
|
||||||
// perform a http post request
|
// perform a http get request
|
||||||
std::string post(const std::string& url, const std::string& json);
|
std::string get(const std::string& url);
|
||||||
|
|
||||||
private:
|
// perform a http post request
|
||||||
std::unique_ptr<CURL, void(*)(CURL*)> _h {nullptr, curl_easy_cleanup};
|
std::string post(const std::string& url, const std::string& json);
|
||||||
sc::logger* _logger {nullptr};
|
|
||||||
std::string _text;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::unique_ptr<CURL, void(*)(CURL*)> _h {nullptr, curl_easy_cleanup};
|
||||||
|
sc::logger* _logger {nullptr};
|
||||||
|
std::string _text;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
#endif // _requester_H_
|
#endif // _requester_H_
|
||||||
|
Loading…
x
Reference in New Issue
Block a user