orotool/main.cpp

66 lines
1.6 KiB
C++

#define HAS_UNCAUGHT_EXCEPTIONS 1
#include <restc-cpp/restc-cpp.h>
#include <restc-cpp/RequestBuilder.h>
#include <boost/date_time/local_time/local_time.hpp>
#include <string>
//#include <boost/lexical_cast.hpp>
#include <boost/fusion/adapted.hpp>
#include <iostream>
#include "date/date.h"
namespace rc = restc_cpp;
namespace lt = boost::local_time;
namespace oro {
typedef date::sys_time<std::chrono::microseconds> timestamp_t;
struct Timestamp {
Timestamp& operator= (const std::string& str) {
std::istringstream iss(str);
date::from_stream(iss, "%FT%T%Ez", ts);
return *this;
}
timestamp_t ts;
};
struct Ping {
Timestamp generation_timestamp;
std::string message;
int version;
};
} //namespace oro
BOOST_FUSION_ADAPT_STRUCT(
oro::Ping,
(oro::Timestamp, generation_timestamp)
(std::string, message)
(int, version)
)
int main() {
using date::operator<<;
auto rest_client = rc::RestClient::Create();
oro::Ping ping = rest_client->ProcessWithPromiseT<oro::Ping>([&](rc::Context& ctx) {
oro::Ping ping;
std::unique_ptr<rc::Reply> reply = rc::RequestBuilder(ctx)
.Get("https://api.originsro.org/api/v1/ping")
.Header("X-Client", "RESTC_CPP")
.Header("X-Client-Purpose", "Testing")
.Execute();
std::cout << "I got X-RateLimit-Limit: " << *reply->GetHeader("X-RateLimit-Limit") << '\n';
rc::SerializeFromJson(ping, std::move(reply));
return ping;
}).get();
std::cout << "Response received:\n\ttimestamp: " << ping.generation_timestamp.ts;
std::cout << "\n\tmessage: " << ping.message;
std::cout << "\n\tversion: " << ping.version;
std::cout << std::endl;
return 0;
}