-
Notifications
You must be signed in to change notification settings - Fork 30
/
dev-boltz-api.cpp
45 lines (41 loc) · 998 Bytes
/
dev-boltz-api.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include"Boltz/Connection.hpp"
#include"Ev/Io.hpp"
#include"Ev/start.hpp"
#include"Ev/ThreadPool.hpp"
#include"Jsmn/Object.hpp"
#include"Json/Out.hpp"
#include"Util/make_unique.hpp"
#include<iostream>
#include<sstream>
#include<string>
/* argv[1] == /api
* argv[2] == JSON
*/
int main(int argc, char** argv) {
if (argc < 2 || argc > 3) {
std::cerr << "Usage: dev-boltz-api /url json" << std::endl;
return 1;
}
auto api = std::string(argv[1]);
auto json = std::unique_ptr<Json::Out>(nullptr);
if (argc == 3) {
auto json_arg = ([argv]() {
auto is = std::istringstream(std::string(argv[2]));
auto rv = Jsmn::Object();
is >> rv;
return rv;
})();
json = Util::make_unique<Json::Out>(
Json::Out(json_arg)
);
}
Ev::ThreadPool tp;
auto cc = Boltz::Connection(tp);
auto code = Ev::lift().then([&]() {
return cc.api(api, std::move(json));
}).then([](Jsmn::Object result) {
std::cout << result << std::endl;
return Ev::lift(0);
});
return Ev::start(code);
}