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