2018-06-26 14:09:39 +02:00
|
|
|
#include "providers/twitch/TwitchUser.hpp"
|
2018-05-12 20:34:13 +02:00
|
|
|
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "util/RapidjsonHelpers.hpp"
|
2018-05-12 20:34:13 +02:00
|
|
|
|
|
|
|
namespace chatterino {
|
|
|
|
|
|
|
|
TwitchUser TwitchUser::fromJSON(const rapidjson::Value &value)
|
|
|
|
{
|
|
|
|
TwitchUser user;
|
|
|
|
|
|
|
|
if (!value.IsObject()) {
|
|
|
|
throw std::runtime_error("JSON value is not an object");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!rj::getSafe(value, "_id", user.id)) {
|
|
|
|
throw std::runtime_error("Missing ID key");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!rj::getSafe(value, "name", user.name)) {
|
|
|
|
throw std::runtime_error("Missing name key");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!rj::getSafe(value, "display_name", user.displayName)) {
|
|
|
|
throw std::runtime_error("Missing display name key");
|
|
|
|
}
|
|
|
|
|
|
|
|
return user;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace chatterino
|