18 #include <immer/map.hpp>
19 #include <immer/array.hpp>
20 #include <immer/box.hpp>
28 using Header = immer::box<std::map<std::string, std::string>>;
34 using Body = std::variant<EmptyBody, JsonBody, BytesBody, FileBody>;
41 return std::holds_alternative<JsonBody>(body);
63 std::string
dataStr(
const std::string &key)
const;
64 std::string
jobId()
const;
83 using Method = std::variant<Get, Post, Put, Delete>;
90 class Query :
public std::vector<std::pair<std::string, std::string>>
92 using BaseT = std::vector<std::pair<std::string, std::string>>;
95 void add(std::string k, std::string v) {
113 std::string requestUrl,
116 std::string token = {},
129 std::string
url()
const;
142 static bool contentTypeMatches(immer::array<std::string> expected, std::string actual);
153 std::string
dataStr(
const std::string &key)
const;
154 std::string
jobId()
const;
155 std::optional<std::string>
queueId()
const;
166 std::unique_ptr<Private> m_d;
184 q.
add(name, std::to_string(std::forward<U>(arg)));
189 struct AddToQueryT<
std::string>
193 q.
add(name, std::forward<U>(arg));
198 struct AddToQueryT<bool>
202 q.
add(name, std::forward<U>(arg) ?
"true"s :
"false"s);
207 struct AddToQueryT<immer::array<T>>
211 for (
auto v : std::forward<U>(arg)) {
218 struct AddToQueryT<
json>
223 for (
auto [k, v] : arg.items()) {
233 detail::AddToQueryT<std::decay_t<T>>::call(q, name, std::forward<T>(arg));
239 struct AddToQueryIfNeededT
242 static void call(BaseJob::Query &q, std::string name, U &&arg) {
243 using ArgT = std::decay_t<U>;
255 struct AddToQueryIfNeededT<
std::optional<T>>
258 static void call(BaseJob::Query &q, std::string name, U &&arg) {
259 if (arg.has_value()) {
260 addToQuery(q, name, std::forward<U>(arg).value());
269 detail::AddToQueryIfNeededT<std::decay_t<T>>::call(q, name, std::forward<T>(arg));
Definition: basejob.hpp:91
void add(std::string k, std::string v)
Definition: basejob.hpp:95
Definition: basejob.hpp:77
static bool contentTypeMatches(immer::array< std::string > expected, std::string actual)
Definition: basejob.cpp:160
BaseJob(std::string serverUrl, std::string requestUrl, Method method, std::string jobId, std::string token={}, ReturnType returnType=ReturnType::Json, Body body=EmptyBody{}, Query query={}, Header header={}, std::optional< FileDesc > responseFile=std::nullopt)
Definition: basejob.cpp:85
std::optional< std::string > queueId() const
Definition: basejob.cpp:238
static Post POST
Definition: basejob.hpp:86
Method requestMethod() const
Definition: basejob.cpp:134
std::variant< Get, Post, Put, Delete > Method
Definition: basejob.hpp:83
json dataJson(const std::string &key) const
Definition: basejob.cpp:223
BaseJob withData(JsonWrap j) &&
Definition: basejob.cpp:193
std::string url() const
Definition: basejob.cpp:109
friend bool operator==(BaseJob a, BaseJob b)
Definition: basejob.cpp:280
Header requestHeader() const
Definition: basejob.cpp:119
std::optional< FileDesc > responseFile() const
Definition: basejob.cpp:248
void attachData(JsonWrap data)
Definition: basejob.cpp:188
JobQueuePolicy queuePolicy() const
Definition: basejob.cpp:243
BaseJob withQueue(std::string id, JobQueuePolicy policy=AlwaysContinue) &&
Definition: basejob.cpp:207
static Delete DELETE
Definition: basejob.hpp:88
::Kazv::BytesBody BytesBody
Definition: basejob.hpp:101
std::string jobId() const
Definition: basejob.cpp:233
::Kazv::Header Header
Definition: basejob.hpp:104
::Kazv::EmptyBody EmptyBody
Definition: basejob.hpp:103
Body requestBody() const
Definition: basejob.cpp:114
bool shouldReturnJson() const
Definition: basejob.cpp:104
Query requestQuery() const
returns the non-encoded query as an array of pairs
Definition: basejob.cpp:129
static Put PUT
Definition: basejob.hpp:87
::Kazv::Body Body
Definition: basejob.hpp:100
static Get GET
Definition: basejob.hpp:85
ReturnType
Definition: basejob.hpp:107
@ Json
Definition: basejob.hpp:108
@ File
Definition: basejob.hpp:109
Response genResponse(Response r) const
Definition: basejob.cpp:180
ReturnType returnType() const
Definition: basejob.cpp:124
std::string dataStr(const std::string &key) const
Definition: basejob.cpp:228
Definition: file-desc.hpp:225
Definition: jsonwrap.hpp:23
#define KAZV_DECLARE_COPYABLE(typeName)
Definition: copy-helper.hpp:10
constexpr auto hasEmptyMethod
Definition: types.hpp:37
Definition: location.hpp:10
Bytes BytesBody
Definition: basejob.hpp:30
bool operator!=(BaseJob a, BaseJob b)
Definition: basejob.cpp:292
void addToQueryIfNeeded(BaseJob::Query &q, std::string name, T &&arg)
Definition: basejob.hpp:267
std::variant< EmptyBody, JsonBody, BytesBody, FileBody > Body
Definition: basejob.hpp:34
bool isBodyJson(Body body)
Definition: basejob.hpp:40
nlohmann::json json
Definition: jsonwrap.hpp:20
std::string Bytes
Definition: types.hpp:27
JobQueuePolicy
Definition: basejob.hpp:45
@ CancelFutureIfFailed
Definition: basejob.hpp:47
@ AlwaysContinue
Definition: basejob.hpp:46
void addToQuery(BaseJob::Query &q, std::string name, T &&arg)
Definition: basejob.hpp:231
bool operator==(BaseJob a, BaseJob b)
Definition: basejob.cpp:280
JsonWrap JsonBody
Definition: basejob.hpp:31
immer::box< std::map< std::string, std::string > > Header
Definition: basejob.hpp:28
Definition: clientutil.hpp:217
Definition: basejob.hpp:82
Definition: basejob.hpp:79
Definition: basejob.hpp:80
Definition: basejob.cpp:24
Definition: basejob.hpp:81
Definition: basejob.hpp:33
Definition: basejob.hpp:50
Header header
Definition: basejob.hpp:54
std::string errorCode() const
Definition: basejob.cpp:253
std::string jobId() const
Definition: basejob.cpp:154
JsonWrap extraData
Definition: basejob.hpp:55
int StatusCode
Definition: basejob.hpp:51
constexpr bool success() const
Definition: basejob.hpp:59
JsonWrap jsonBody() const
Definition: basejob.cpp:139
std::string dataStr(const std::string &key) const
Definition: basejob.cpp:149
StatusCode statusCode
Definition: basejob.hpp:52
Body body
Definition: basejob.hpp:53
json dataJson(const std::string &key) const
Definition: basejob.cpp:144
std::string errorMessage() const
Definition: basejob.cpp:268