JSON-parsing functions moved to namespace telebotxx.

This commit is contained in:
Kirill Kirilenko 2016-09-30 00:46:33 +03:00
parent 1c2c8384bc
commit 1e43989b77

View file

@ -13,10 +13,10 @@
#include <boost/log/trivial.hpp> #include <boost/log/trivial.hpp>
using namespace telebotxx; namespace telebotxx
const rapidjson::Value& parseResponse(const rapidjson::Document& doc)
{ {
const rapidjson::Value& parseResponse(const rapidjson::Document& doc)
{
using namespace rapidjson; using namespace rapidjson;
if (!doc.IsObject()) if (!doc.IsObject())
throw ParseError("Object expected"); throw ParseError("Object expected");
@ -31,8 +31,7 @@ const rapidjson::Value& parseResponse(const rapidjson::Document& doc)
if (!doc.HasMember("result") || !doc["result"].IsObject()) if (!doc.HasMember("result") || !doc["result"].IsObject())
throw ParseError("Field 'result' not found or has invalid type"); throw ParseError("Field 'result' not found or has invalid type");
return doc["result"]; return doc["result"];
} } else
else
{ {
if (!doc.HasMember("error_code") || !doc["error_code"].IsInt()) if (!doc.HasMember("error_code") || !doc["error_code"].IsInt())
throw ParseError("Field 'error_code' not found or has invalid type"); throw ParseError("Field 'error_code' not found or has invalid type");
@ -44,10 +43,10 @@ const rapidjson::Value& parseResponse(const rapidjson::Document& doc)
throw ApiError(code, description); throw ApiError(code, description);
} }
} }
User parseUser(const rapidjson::Value& obj) User parseUser(const rapidjson::Value& obj)
{ {
if (!obj.HasMember("id") || !obj["id"].IsInt()) if (!obj.HasMember("id") || !obj["id"].IsInt())
throw ParseError("Field 'id' not found or has invalid type"); throw ParseError("Field 'id' not found or has invalid type");
int id = obj["id"].GetInt(); int id = obj["id"].GetInt();
@ -75,8 +74,11 @@ User parseUser(const rapidjson::Value& obj)
} }
return User(id, firstName, lastName, username); return User(id, firstName, lastName, username);
}
} }
using namespace telebotxx;
class BotApi::Impl class BotApi::Impl
{ {
public: public: