Updated Easy::Account for Mastodon 2.4.0+
This commit is contained in:
parent
54493cd42e
commit
f64984f331
|
@ -1,6 +1,6 @@
|
||||||
cmake_minimum_required (VERSION 3.6)
|
cmake_minimum_required (VERSION 3.6)
|
||||||
project (mastodon-cpp
|
project (mastodon-cpp
|
||||||
VERSION 0.18.4
|
VERSION 0.18.5
|
||||||
LANGUAGES CXX
|
LANGUAGES CXX
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -63,6 +63,12 @@ const string Account::avatar() const
|
||||||
return get_string("avatar");
|
return get_string("avatar");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Account Account::avatar(const string &avatar)
|
||||||
|
{
|
||||||
|
set("avatar", Json::Value(avatar));
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
const string Account::avatar_static() const
|
const string Account::avatar_static() const
|
||||||
{
|
{
|
||||||
return get_string("avatar_static");
|
return get_string("avatar_static");
|
||||||
|
@ -83,6 +89,12 @@ const string Account::display_name() const
|
||||||
return get_string("display_name");
|
return get_string("display_name");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Account Account::display_name(const string &display_name)
|
||||||
|
{
|
||||||
|
set("display_name", Json::Value(display_name));
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
const std::vector<Account::fields_pair> Account::fields() const
|
const std::vector<Account::fields_pair> Account::fields() const
|
||||||
{
|
{
|
||||||
const Json::Value &node = get("fields");
|
const Json::Value &node = get("fields");
|
||||||
|
@ -101,6 +113,21 @@ const std::vector<Account::fields_pair> Account::fields() const
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Account Account::fields(std::vector<Account::fields_pair> &fields)
|
||||||
|
{
|
||||||
|
Json::Value jsonarray(Json::arrayValue);
|
||||||
|
|
||||||
|
for (const fields_pair &field : fields)
|
||||||
|
{
|
||||||
|
Json::Value jsonkeyval(Json::objectValue);
|
||||||
|
jsonkeyval["name"] = field.first;
|
||||||
|
jsonkeyval["value"] = field.second;
|
||||||
|
jsonarray.append(jsonkeyval);
|
||||||
|
}
|
||||||
|
set("fields", jsonarray);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
const std::uint_fast64_t Account::followers_count() const
|
const std::uint_fast64_t Account::followers_count() const
|
||||||
{
|
{
|
||||||
return get_uint64("followers_count");
|
return get_uint64("followers_count");
|
||||||
|
@ -116,6 +143,12 @@ const string Account::header() const
|
||||||
return get_string("header");
|
return get_string("header");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Account Account::header(const string &header)
|
||||||
|
{
|
||||||
|
set("header", Json::Value(header));
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
const string Account::header_static() const
|
const string Account::header_static() const
|
||||||
{
|
{
|
||||||
return get_string("header_static");
|
return get_string("header_static");
|
||||||
|
@ -131,6 +164,12 @@ const bool Account::locked() const
|
||||||
return get_bool("locked");
|
return get_bool("locked");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Account Account::locked(const bool &locked)
|
||||||
|
{
|
||||||
|
set("locked", Json::Value(locked));
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
const bool Account::has_moved() const
|
const bool Account::has_moved() const
|
||||||
{
|
{
|
||||||
if (get("moved").isObject())
|
if (get("moved").isObject())
|
||||||
|
@ -154,7 +193,13 @@ const Account Account::moved() const
|
||||||
|
|
||||||
const string Account::note() const
|
const string Account::note() const
|
||||||
{
|
{
|
||||||
return get_string("source.note");
|
return get_string("note");
|
||||||
|
}
|
||||||
|
|
||||||
|
Account Account::note(const string ¬e)
|
||||||
|
{
|
||||||
|
set("note", Json::Value(note));
|
||||||
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
const string Account::note_plain() const
|
const string Account::note_plain() const
|
||||||
|
@ -183,6 +228,137 @@ const bool Account::sensitive() const
|
||||||
return get_bool("source.sensitive");
|
return get_bool("source.sensitive");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Account::Source::Source(const string &json)
|
||||||
|
: Entity(json)
|
||||||
|
{}
|
||||||
|
|
||||||
|
Account::Source::Source()
|
||||||
|
: Entity()
|
||||||
|
{}
|
||||||
|
|
||||||
|
const bool Account::Source::valid() const
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::vector<Account::fields_pair> Account::Source::fields() const
|
||||||
|
{
|
||||||
|
const Json::Value &node = get("fields");
|
||||||
|
|
||||||
|
if (node.isArray())
|
||||||
|
{
|
||||||
|
std::vector<Account::fields_pair> vec;
|
||||||
|
for (const Json::Value &value : node)
|
||||||
|
{
|
||||||
|
vec.push_back(Account::fields_pair(value["name"].asString(),
|
||||||
|
value["value"].asString()));
|
||||||
|
}
|
||||||
|
return vec;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
Account::Source Account::Source::fields
|
||||||
|
(std::vector<Account::fields_pair> &fields)
|
||||||
|
{
|
||||||
|
Json::Value jsonarray(Json::arrayValue);
|
||||||
|
|
||||||
|
for (const fields_pair &field : fields)
|
||||||
|
{
|
||||||
|
Json::Value jsonkeyval(Json::objectValue);
|
||||||
|
jsonkeyval["name"] = field.first;
|
||||||
|
jsonkeyval["value"] = field.second;
|
||||||
|
jsonarray.append(jsonkeyval);
|
||||||
|
}
|
||||||
|
set("fields", jsonarray);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
const string Account::Source::note() const
|
||||||
|
{
|
||||||
|
return get_string("note");
|
||||||
|
}
|
||||||
|
|
||||||
|
Account::Source Account::Source::note(const string ¬e)
|
||||||
|
{
|
||||||
|
set("note", Json::Value(note));
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
const Easy::visibility_type Account::Source::privacy() const
|
||||||
|
{
|
||||||
|
const string strprivacy = get_string("privacy");
|
||||||
|
if (strprivacy.compare("public") == 0)
|
||||||
|
return visibility_type::Public;
|
||||||
|
else if (strprivacy.compare("unlisted") == 0)
|
||||||
|
return visibility_type::Unlisted;
|
||||||
|
else if (strprivacy.compare("private") == 0)
|
||||||
|
return visibility_type::Private;
|
||||||
|
else if (strprivacy.compare("direct") == 0)
|
||||||
|
return visibility_type::Direct;
|
||||||
|
|
||||||
|
ttdebug << "Could not get data: source.privacy\n";
|
||||||
|
return visibility_type::Undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
Account::Source Account::Source::privacy(const Easy::visibility_type &privacy)
|
||||||
|
{
|
||||||
|
string strprivacy = "";
|
||||||
|
switch (privacy)
|
||||||
|
{
|
||||||
|
case visibility_type::Public:
|
||||||
|
{
|
||||||
|
strprivacy = "public";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case visibility_type::Unlisted:
|
||||||
|
{
|
||||||
|
strprivacy = "unlisted";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case visibility_type::Private:
|
||||||
|
{
|
||||||
|
strprivacy = "private";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case visibility_type::Direct:
|
||||||
|
{
|
||||||
|
strprivacy = "direct";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
strprivacy = "undefined";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
set("privacy", Json::Value(strprivacy));
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
const bool Account::Source::sensitive() const
|
||||||
|
{
|
||||||
|
return get_bool("sensitive");
|
||||||
|
}
|
||||||
|
|
||||||
|
Account::Source Account::Source::sensitive(const bool &sensitive)
|
||||||
|
{
|
||||||
|
set("source", Json::Value(sensitive));
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
const Account::Source Account::source() const
|
||||||
|
{
|
||||||
|
return Account::Source(get("source").toStyledString());
|
||||||
|
}
|
||||||
|
|
||||||
|
Account Account::source(const Account::Source &source)
|
||||||
|
{
|
||||||
|
set("source", Json::Value(source.to_object()));
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
const std::uint_fast64_t Account::statuses_count() const
|
const std::uint_fast64_t Account::statuses_count() const
|
||||||
{
|
{
|
||||||
return get_uint64("statuses_count");
|
return get_uint64("statuses_count");
|
||||||
|
|
|
@ -88,6 +88,15 @@ namespace Mastodon
|
||||||
*/
|
*/
|
||||||
const string avatar() const;
|
const string avatar() const;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Sets avatar
|
||||||
|
*
|
||||||
|
* Filename or base64-encoded
|
||||||
|
*
|
||||||
|
* @since 0.18.5
|
||||||
|
*/
|
||||||
|
Account avatar(const string &avatar);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Returns URL of static avatar
|
* @brief Returns URL of static avatar
|
||||||
*
|
*
|
||||||
|
@ -116,6 +125,13 @@ namespace Mastodon
|
||||||
*/
|
*/
|
||||||
const string display_name() const;
|
const string display_name() const;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Sets display name
|
||||||
|
*
|
||||||
|
* @since 0.18.5
|
||||||
|
*/
|
||||||
|
Account display_name(const string &display_name);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Returns metadata fields
|
* @brief Returns metadata fields
|
||||||
*
|
*
|
||||||
|
@ -123,6 +139,13 @@ namespace Mastodon
|
||||||
*/
|
*/
|
||||||
const std::vector<fields_pair> fields() const;
|
const std::vector<fields_pair> fields() const;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Sets metadata fields
|
||||||
|
*
|
||||||
|
* @since 0.18.5
|
||||||
|
*/
|
||||||
|
Account fields(std::vector<fields_pair> &fields);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Returns number of followers
|
* @brief Returns number of followers
|
||||||
*
|
*
|
||||||
|
@ -144,6 +167,15 @@ namespace Mastodon
|
||||||
*/
|
*/
|
||||||
const string header() const;
|
const string header() const;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Sets header image
|
||||||
|
*
|
||||||
|
* Filename or base64-encoded.
|
||||||
|
*
|
||||||
|
* @since 0.18.5
|
||||||
|
*/
|
||||||
|
Account header(const string &header);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Returns URL of static header image
|
* @brief Returns URL of static header image
|
||||||
*
|
*
|
||||||
|
@ -165,6 +197,13 @@ namespace Mastodon
|
||||||
*/
|
*/
|
||||||
const bool locked() const;
|
const bool locked() const;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Sets locked state
|
||||||
|
*
|
||||||
|
* @since 0.18.5
|
||||||
|
*/
|
||||||
|
Account locked(const bool &locked);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Returns true if the account has been moved
|
* @brief Returns true if the account has been moved
|
||||||
*
|
*
|
||||||
|
@ -187,11 +226,19 @@ namespace Mastodon
|
||||||
*/
|
*/
|
||||||
const string note() const;
|
const string note() const;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Sets note
|
||||||
|
*
|
||||||
|
* @since 0.18.5
|
||||||
|
*/
|
||||||
|
Account note(const string ¬e);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Returns plaintext version of note
|
* @brief Returns plaintext version of note
|
||||||
*
|
*
|
||||||
* @since before 0.11.0
|
* @since before 0.11.0
|
||||||
*/
|
*/
|
||||||
|
[[deprecated("Will vanish in 1.0.0. Use source() instead.")]]
|
||||||
const string note_plain() const;
|
const string note_plain() const;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -208,6 +255,92 @@ namespace Mastodon
|
||||||
*/
|
*/
|
||||||
const bool sensitive() const;
|
const bool sensitive() const;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Class to hold source attribute
|
||||||
|
*
|
||||||
|
* @since 0.18.5
|
||||||
|
*/
|
||||||
|
class Source : public Easy::Entity
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/*!
|
||||||
|
* @brief Constructs an Account::Source object from a JSON string.
|
||||||
|
*
|
||||||
|
* @param json JSON string
|
||||||
|
*
|
||||||
|
* @since 0.18.5
|
||||||
|
*/
|
||||||
|
explicit Source(const string &json);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Constructs an empty Account::Source object.
|
||||||
|
*
|
||||||
|
* @since 0.18.5
|
||||||
|
*/
|
||||||
|
Source();
|
||||||
|
|
||||||
|
virtual const bool valid() const;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Returns metadata fields
|
||||||
|
*
|
||||||
|
* @since 0.18.5
|
||||||
|
*/
|
||||||
|
const std::vector<fields_pair> fields() const;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Sets metadata fields
|
||||||
|
*
|
||||||
|
* @since 0.18.5
|
||||||
|
*/
|
||||||
|
Source fields(std::vector<fields_pair> &fields);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Returns note in plain text
|
||||||
|
*
|
||||||
|
* @since 0.18.5
|
||||||
|
*/
|
||||||
|
const string note() const;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Sets note
|
||||||
|
*
|
||||||
|
* @since 0.18.5
|
||||||
|
*/
|
||||||
|
Source note(const string ¬e);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Returns default privacy of new toots
|
||||||
|
*
|
||||||
|
* @since 0.18.5
|
||||||
|
*/
|
||||||
|
const visibility_type privacy() const;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Sets default privacy of new toots
|
||||||
|
*
|
||||||
|
* @since 0.18.5
|
||||||
|
*/
|
||||||
|
Source privacy(const visibility_type &privacy);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Returns if media is marked as sensitive by default
|
||||||
|
*
|
||||||
|
* @since 0.18.5
|
||||||
|
*/
|
||||||
|
const bool sensitive() const;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Sets if media is marked as sensitive by default
|
||||||
|
*
|
||||||
|
* @since 0.18.5
|
||||||
|
*/
|
||||||
|
Source sensitive(const bool &sensitive);
|
||||||
|
};
|
||||||
|
|
||||||
|
const Source source() const;
|
||||||
|
Account source(const Source &source);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Returns number of statuses
|
* @brief Returns number of statuses
|
||||||
*
|
*
|
||||||
|
|
Reference in New Issue