mirror of
https://github.com/UltraCoderRU/telebotxx.git
synced 2026-01-28 04:05:13 +00:00
JSON-parsing functions moved to namespace telebotxx.
This commit is contained in:
parent
1c2c8384bc
commit
1e43989b77
1 changed files with 64 additions and 62 deletions
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue