CLOUD: Update BoxListDirectoryByIdRequest

It now uses special CurlJsonRequest static methods to check whether JSON
is an object, has a string or integer parameter.
This commit is contained in:
Alexander Tkachev 2016-07-22 18:27:49 +06:00
parent 43c940c985
commit cccfe7c247
3 changed files with 51 additions and 55 deletions

View file

@ -31,7 +31,7 @@
namespace Networking {
CurlJsonRequest::CurlJsonRequest(JsonCallback cb, ErrorCallback ecb, Common::String url):
CurlJsonRequest::CurlJsonRequest(JsonCallback cb, ErrorCallback ecb, Common::String url) :
CurlRequest(nullptr, ecb, url), _jsonCallback(cb), _contentsStream(DisposeAfterUse::YES),
_buffer(new byte[CURL_JSON_REQUEST_BUFFER_SIZE]) {}
@ -97,4 +97,43 @@ void CurlJsonRequest::finishJson(Common::JSONValue *json) {
else delete json;
}
bool CurlJsonRequest::jsonIsObject(Common::JSONValue *item, const char *warningPrefix) {
if (item == nullptr) {
warning("%s: passed item is NULL", warningPrefix);
return false;
}
if (item->isObject()) return true;
warning("%s: passed item is not an object!", warningPrefix);
debug(9, "%s", item->stringify(true).c_str());
return false;
}
bool CurlJsonRequest::jsonContainsString(Common::JSONObject &item, const char *key, const char *warningPrefix) {
if (!item.contains(key)) {
warning("%s: passed item misses the \"%s\" attribute!", warningPrefix, key);
return false;
}
if (item.getVal(key)->isString()) return true;
warning("%s: passed item's \"%s\" attribute is not a string!", warningPrefix, key);
debug(9, "%s", item.getVal(key)->stringify(true).c_str());
return false;
}
bool CurlJsonRequest::jsonContainsIntegerNumber(Common::JSONObject &item, const char *key, const char *warningPrefix) {
if (!item.contains(key)) {
warning("%s: passed item misses the \"%s\" attribute!", warningPrefix, key);
return false;
}
if (item.getVal(key)->isIntegerNumber()) return true;
warning("%s: passed item's \"%s\" attribute is not an integer!", warningPrefix, key);
debug(9, "%s", item.getVal(key)->stringify(true).c_str());
return false;
}
} // End of namespace Networking