Updated Easy::Account.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Removed all setters, changed the type for account fields, added new attributes.
This commit is contained in:
parent
ea0c3c5250
commit
8448d8e720
@ -394,7 +394,7 @@ strings and you can use unsupported fields in an `Entity` by converting it to
|
||||
|
||||
==== Entities
|
||||
|
||||
* [ ] Account
|
||||
* [x] Account
|
||||
* [ ] Application
|
||||
* [ ] Attachment
|
||||
* [ ] Card
|
||||
|
@ -14,10 +14,10 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <array>
|
||||
#include <algorithm>
|
||||
#include "account.hpp"
|
||||
#include "debug.hpp"
|
||||
#include "easy/easy.hpp"
|
||||
|
||||
using namespace Mastodon;
|
||||
using Account = Easy::Account;
|
||||
@ -55,12 +55,6 @@ const string Account::avatar() const
|
||||
return get_string("avatar");
|
||||
}
|
||||
|
||||
Account Account::avatar(const string &avatar)
|
||||
{
|
||||
set("avatar", Json::Value(avatar));
|
||||
return *this;
|
||||
}
|
||||
|
||||
const string Account::avatar_static() const
|
||||
{
|
||||
return get_string("avatar_static");
|
||||
@ -81,45 +75,46 @@ const string Account::display_name() const
|
||||
return get_string("display_name");
|
||||
}
|
||||
|
||||
Account Account::display_name(const string &display_name)
|
||||
const std::vector<Easy::Emoji> Account::emojis()
|
||||
{
|
||||
set("display_name", Json::Value(display_name));
|
||||
return *this;
|
||||
}
|
||||
|
||||
const std::vector<Account::fields_pair> Account::fields() const
|
||||
{
|
||||
const Json::Value &node = get("fields");
|
||||
const Json::Value &node = get("emojis");
|
||||
|
||||
if (node.isArray())
|
||||
{
|
||||
std::vector<Account::fields_pair> vec;
|
||||
std::vector<Easy::Emoji> vec;
|
||||
std::transform(node.begin(), node.end(), std::back_inserter(vec),
|
||||
[](const Json::Value &value)
|
||||
{
|
||||
return Account::fields_pair
|
||||
(value["name"].asString(),
|
||||
value["value"].asString());
|
||||
});
|
||||
{
|
||||
return Easy::Emoji(value);
|
||||
});
|
||||
return vec;
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
Account Account::fields(std::vector<Account::fields_pair> &fields)
|
||||
const Easy::account_fields Account::fields() const
|
||||
{
|
||||
Json::Value jsonarray(Json::arrayValue);
|
||||
const Json::Value &node = get("fields");
|
||||
|
||||
for (const fields_pair &field : fields)
|
||||
if (node.isArray())
|
||||
{
|
||||
Json::Value jsonkeyval(Json::objectValue);
|
||||
jsonkeyval["name"] = field.first;
|
||||
jsonkeyval["value"] = field.second;
|
||||
jsonarray.append(jsonkeyval);
|
||||
Easy::account_fields vec;
|
||||
std::transform(node.begin(), node.end(), std::back_inserter(vec),
|
||||
[](const Json::Value &value)
|
||||
{
|
||||
return Easy::account_field_type(
|
||||
{
|
||||
value["name"].asString(),
|
||||
value["value"].asString(),
|
||||
Easy::string_to_time(
|
||||
value["verified_at"].asString())
|
||||
});
|
||||
});
|
||||
return vec;
|
||||
}
|
||||
set("fields", jsonarray);
|
||||
return *this;
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
std::uint64_t Account::followers_count() const
|
||||
@ -137,12 +132,6 @@ const string Account::header() const
|
||||
return get_string("header");
|
||||
}
|
||||
|
||||
Account Account::header(const string &header)
|
||||
{
|
||||
set("header", Json::Value(header));
|
||||
return *this;
|
||||
}
|
||||
|
||||
const string Account::header_static() const
|
||||
{
|
||||
return get_string("header_static");
|
||||
@ -158,12 +147,6 @@ bool Account::locked() const
|
||||
return get_bool("locked");
|
||||
}
|
||||
|
||||
Account Account::locked(const bool &locked)
|
||||
{
|
||||
set("locked", Json::Value(locked));
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool Account::has_moved() const
|
||||
{
|
||||
if (get("moved").isObject())
|
||||
@ -178,7 +161,7 @@ const Account Account::moved() const
|
||||
{
|
||||
if (has_moved())
|
||||
{
|
||||
return Account(get("moved").toStyledString());
|
||||
return Account(get("moved"));
|
||||
}
|
||||
|
||||
return Account();
|
||||
@ -189,22 +172,16 @@ const string Account::note() const
|
||||
return get_string("note");
|
||||
}
|
||||
|
||||
Account Account::note(const string ¬e)
|
||||
{
|
||||
set("note", Json::Value(note));
|
||||
return *this;
|
||||
}
|
||||
|
||||
Easy::visibility_type Account::privacy() const
|
||||
{
|
||||
const string strprivacy = get_string("source.privacy");
|
||||
if (strprivacy.compare("public") == 0)
|
||||
if (strprivacy == "public")
|
||||
return visibility_type::Public;
|
||||
else if (strprivacy.compare("unlisted") == 0)
|
||||
else if (strprivacy == "unlisted")
|
||||
return visibility_type::Unlisted;
|
||||
else if (strprivacy.compare("private") == 0)
|
||||
else if (strprivacy == "private")
|
||||
return visibility_type::Private;
|
||||
else if (strprivacy.compare("direct") == 0)
|
||||
else if (strprivacy == "direct")
|
||||
return visibility_type::Direct;
|
||||
|
||||
ttdebug << "Could not get data: source.privacy\n";
|
||||
@ -216,131 +193,11 @@ bool Account::sensitive() const
|
||||
return get_bool("source.sensitive");
|
||||
}
|
||||
|
||||
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;
|
||||
std::transform(node.begin(), node.end(), std::back_inserter(vec),
|
||||
[](const Json::Value &value)
|
||||
{
|
||||
return 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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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"));
|
||||
}
|
||||
|
||||
Account Account::source(const Account::Source &source)
|
||||
{
|
||||
set("source", Json::Value(source.to_object()));
|
||||
return *this;
|
||||
}
|
||||
|
||||
std::uint64_t Account::statuses_count() const
|
||||
{
|
||||
return get_uint64("statuses_count");
|
||||
@ -355,3 +212,67 @@ const string Account::username() const
|
||||
{
|
||||
return get_string("username");
|
||||
}
|
||||
|
||||
bool Account::Source::valid() const
|
||||
{
|
||||
return Entity::check_valid(
|
||||
{
|
||||
"note",
|
||||
"fields"
|
||||
});
|
||||
}
|
||||
|
||||
const Easy::account_fields Account::Source::fields() const
|
||||
{
|
||||
const Json::Value &node = get("fields");
|
||||
|
||||
if (node.isArray())
|
||||
{
|
||||
Easy::account_fields vec;
|
||||
std::transform(node.begin(), node.end(), std::back_inserter(vec),
|
||||
[](const Json::Value &value)
|
||||
{
|
||||
return Easy::account_field_type(
|
||||
{
|
||||
value["name"].asString(),
|
||||
value["value"].asString(),
|
||||
Easy::string_to_time(
|
||||
value["verified_at"].asString())
|
||||
});
|
||||
});
|
||||
return vec;
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
const string Account::Source::language() const
|
||||
{
|
||||
return get_string("language");
|
||||
}
|
||||
|
||||
const string Account::Source::note() const
|
||||
{
|
||||
return get_string("note");
|
||||
}
|
||||
|
||||
Easy::visibility_type Account::Source::privacy() const
|
||||
{
|
||||
const string strprivacy = get_string("privacy");
|
||||
if (strprivacy == "public")
|
||||
return visibility_type::Public;
|
||||
else if (strprivacy == "unlisted")
|
||||
return visibility_type::Unlisted;
|
||||
else if (strprivacy == "private")
|
||||
return visibility_type::Private;
|
||||
else if (strprivacy == "direct")
|
||||
return visibility_type::Direct;
|
||||
|
||||
ttdebug << "Could not get data: source.privacy\n";
|
||||
return visibility_type::Undefined;
|
||||
}
|
||||
|
||||
bool Account::Source::sensitive() const
|
||||
{
|
||||
return get_bool("sensitive");
|
||||
}
|
||||
|
@ -26,9 +26,11 @@
|
||||
#ifdef MASTODON_CPP
|
||||
#include "mastodon-cpp.hpp"
|
||||
#include "easy/entity.hpp"
|
||||
#include "easy/entities/emoji.hpp"
|
||||
#else
|
||||
#include <mastodon-cpp/mastodon-cpp.hpp>
|
||||
#include <mastodon-cpp/easy/entity.hpp>
|
||||
#include <mastodon-cpp/easy/entities/emoji.hpp>
|
||||
#endif
|
||||
|
||||
using std::string;
|
||||
@ -48,13 +50,6 @@ namespace Easy
|
||||
public:
|
||||
using Entity::Entity;
|
||||
|
||||
/*!
|
||||
* @brief Describes a field. Format: name, value
|
||||
*
|
||||
* @since 0.16.1
|
||||
*/
|
||||
using fields_pair = std::pair<const string, const string>;
|
||||
|
||||
virtual bool valid() const override;
|
||||
|
||||
/*!
|
||||
@ -68,127 +63,98 @@ namespace Easy
|
||||
const string acct() const;
|
||||
|
||||
/*!
|
||||
* @brief Returns URL of avatar
|
||||
* @brief Returns URL of avatar.
|
||||
*
|
||||
* @since before 0.11.0
|
||||
*/
|
||||
const string avatar() const;
|
||||
|
||||
/*!
|
||||
* @brief Sets avatar to file.
|
||||
*
|
||||
*
|
||||
* @since 0.18.5
|
||||
*/
|
||||
Account avatar(const string &avatar);
|
||||
|
||||
/*!
|
||||
* @brief Returns URL of static avatar
|
||||
* @brief Returns URL of static avatar.
|
||||
*
|
||||
* @since before 0.11.0
|
||||
*/
|
||||
const string avatar_static() const;
|
||||
|
||||
/*!
|
||||
* @brief Returns true if the account performs automated actions
|
||||
* @brief Returns true if the account performs automated actions.
|
||||
*
|
||||
* @since 0.16.0
|
||||
*/
|
||||
bool bot() const;
|
||||
|
||||
/*!
|
||||
* @brief Returns time of creation
|
||||
* @brief Returns time of creation.
|
||||
*
|
||||
* @since before 0.11.0
|
||||
*/
|
||||
const Easy::time created_at() const;
|
||||
|
||||
/*!
|
||||
* @brief Returns display name
|
||||
* @brief Returns display name.
|
||||
*
|
||||
* @since before 0.11.0
|
||||
*/
|
||||
const string display_name() const;
|
||||
|
||||
/*!
|
||||
* @brief Sets display name
|
||||
* @brief Returns emojis.
|
||||
*
|
||||
* @since 0.18.5
|
||||
* @since 0.106.0
|
||||
*/
|
||||
Account display_name(const string &display_name);
|
||||
const std::vector<Easy::Emoji> emojis();
|
||||
|
||||
/*!
|
||||
* @brief Returns metadata fields
|
||||
* @brief Returns metadata fields.
|
||||
*
|
||||
* @since 0.16.1
|
||||
*/
|
||||
const std::vector<fields_pair> fields() const;
|
||||
const Easy::account_fields 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.
|
||||
*
|
||||
* @since before 0.11.0
|
||||
*/
|
||||
uint64_t followers_count() const;
|
||||
|
||||
/*!
|
||||
* @brief Returns number of people this account follows
|
||||
* @brief Returns number of people this account follows.
|
||||
*
|
||||
* @since before 0.11.0
|
||||
*/
|
||||
uint64_t following_count() const;
|
||||
|
||||
/*!
|
||||
* @brief Returns URL of header image
|
||||
* @brief Returns URL of header image.
|
||||
*
|
||||
* @since before 0.11.0
|
||||
*/
|
||||
const string header() const;
|
||||
|
||||
/*!
|
||||
* @brief Sets header image to file.
|
||||
*
|
||||
* @since 0.18.5
|
||||
*/
|
||||
Account header(const string &header);
|
||||
|
||||
/*!
|
||||
* @brief Returns URL of static header image
|
||||
* @brief Returns URL of static header image.
|
||||
*
|
||||
* @since before 0.11.0
|
||||
*/
|
||||
const string header_static() const;
|
||||
|
||||
/*!
|
||||
* @brief Returns account-ID
|
||||
* @brief Returns account-ID.
|
||||
*
|
||||
* @since before 0.11.0
|
||||
*/
|
||||
const string id() const;
|
||||
|
||||
/*!
|
||||
* @brief Returns true if the account is locked
|
||||
* @brief Returns true if the account is locked.
|
||||
*
|
||||
* @since before 0.11.0
|
||||
*/
|
||||
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. (Deprecated)
|
||||
*
|
||||
* @since before 0.11.0
|
||||
*/
|
||||
@ -196,42 +162,35 @@ namespace Easy
|
||||
|
||||
/*!
|
||||
* @brief If the owner decided to switch accounts, new account is in
|
||||
* this attribute
|
||||
* this attribute.
|
||||
*
|
||||
* @since before 0.11.0
|
||||
*/
|
||||
const Account moved() const;
|
||||
|
||||
/*!
|
||||
* @brief Returns note
|
||||
* @brief Returns account description, or biography.
|
||||
*
|
||||
* @since before 0.11.0
|
||||
*/
|
||||
const string note() const;
|
||||
|
||||
/*!
|
||||
* @brief Sets note
|
||||
*
|
||||
* @since 0.18.5
|
||||
*/
|
||||
Account note(const string ¬e);
|
||||
|
||||
/*!
|
||||
* @brief Returns default privacy of new toots
|
||||
* @brief Returns default privacy of new toots.
|
||||
*
|
||||
* @since before 0.11.0
|
||||
*/
|
||||
visibility_type privacy() const;
|
||||
|
||||
/*!
|
||||
* @brief Returns if media is marked as sensitive by default
|
||||
* @brief Returns if media is marked as sensitive by default.
|
||||
*
|
||||
* @since before 0.11.0
|
||||
*/
|
||||
bool sensitive() const;
|
||||
|
||||
/*!
|
||||
* @brief Class to hold source attribute
|
||||
* @brief Class to hold source attribute.
|
||||
*
|
||||
* @since 0.18.5
|
||||
*/
|
||||
@ -243,60 +202,39 @@ namespace Easy
|
||||
virtual bool valid() const override;
|
||||
|
||||
/*!
|
||||
* @brief Returns metadata fields
|
||||
* @brief Returns metadata fields.
|
||||
*
|
||||
* @since 0.18.5
|
||||
*/
|
||||
const std::vector<fields_pair> fields() const;
|
||||
const Easy::account_fields fields() const;
|
||||
|
||||
/*!
|
||||
* @brief Sets metadata fields
|
||||
* @brief Returns the language as ISO 6391 string.
|
||||
*
|
||||
* @since 0.18.5
|
||||
* @since 0.106.0
|
||||
*/
|
||||
Source fields(std::vector<fields_pair> &fields);
|
||||
const string language() const;
|
||||
|
||||
/*!
|
||||
* @brief Returns note in plain text
|
||||
* @brief Returns account description 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
|
||||
* @brief Returns default privacy of new toots.
|
||||
*
|
||||
* @since 0.18.5
|
||||
*/
|
||||
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
|
||||
* @brief Returns if media is marked as sensitive by default.
|
||||
*
|
||||
* @since 0.18.5
|
||||
*/
|
||||
bool sensitive() const;
|
||||
|
||||
/*!
|
||||
* @brief Sets if media is marked as sensitive by default
|
||||
*
|
||||
* @since 0.18.5
|
||||
*/
|
||||
Source sensitive(const bool &sensitive);
|
||||
};
|
||||
|
||||
/*!
|
||||
@ -306,13 +244,6 @@ namespace Easy
|
||||
*/
|
||||
const Source source() const;
|
||||
|
||||
/*!
|
||||
* @brief Set source.
|
||||
*
|
||||
* @since before 0.100.0
|
||||
*/
|
||||
Account source(const Source &source);
|
||||
|
||||
/*!
|
||||
* @brief Returns number of statuses
|
||||
*
|
||||
|
Reference in New Issue
Block a user