Made type names more consistent.
This commit is contained in:
parent
51c9180128
commit
8a6bef8c2c
15
README.adoc
15
README.adoc
|
@ -83,8 +83,8 @@ Not included in this list are entities.
|
|||
|
||||
==== Other types
|
||||
|
||||
* `Mastodon::parameters`: Vector of `Mastodon::param`, for specifying parameters
|
||||
to an `Mastodon::API` call.
|
||||
* `Mastodon::parameters`: Vector of `Mastodon::param` with custom `find()`, for
|
||||
specifying parameters to an `Mastodon::API` call.
|
||||
* `Mastodon::http_method`: HTTP method of an `Mastodon::API` call.
|
||||
* `Mastodon::Easy::event_type`: Event types returned in streams.
|
||||
* `Mastodon::Easy::visibility_type`: Describes the visibility of a post.
|
||||
|
@ -92,13 +92,12 @@ Not included in this list are entities.
|
|||
* `Mastodon::Easy::card_type`: Describes the type of card.
|
||||
* `Mastodon::Easy::notification_type`: The type of the notification.
|
||||
* `Mastodon::Easy::context_type`: Describes the context of a filter.
|
||||
* `Mastodon::Easy::stream_event`: Type and data of an events returned in
|
||||
* `Mastodon::Easy::stream_event_type`: Type and data of an events returned in
|
||||
streams.
|
||||
* `Mastodon::Easy::alerts`: Vector of `Mastodon::Easy::alert_type`, used for
|
||||
push subscriptions.
|
||||
* `Mastodon::Easy::time`: Type for time, can be converted to `time_point` and
|
||||
`string`.
|
||||
* `Mastodon::Easy::Account::account_fields`: Type for fields in accounts.
|
||||
* `Mastodon::Easy::alert_type`, used for push subscriptions.
|
||||
* `Mastodon::Easy::time_type`: Type for time, can be converted to `time_point`
|
||||
and `string`.
|
||||
* `Mastodon::Easy::Account::account_field_type`: Type for fields in accounts.
|
||||
|
||||
=== Error codes
|
||||
|
||||
|
|
|
@ -51,11 +51,12 @@ int main(int argc, char *argv[])
|
|||
// Acquire lock for the stream variable to avoid simultaneous access.
|
||||
std::lock_guard<std::mutex> lock(ptr->get_mutex());
|
||||
// Parse event stream into a vector.
|
||||
std::vector<Easy::stream_event> events = Easy::parse_stream(stream);
|
||||
std::vector<Easy::stream_event_type> events
|
||||
= Easy::parse_stream(stream);
|
||||
// Clear the stream buffer.
|
||||
stream.clear();
|
||||
|
||||
for (const Easy::stream_event &event : events)
|
||||
for (const Easy::stream_event_type &event : events)
|
||||
{
|
||||
// Print out some information about the events.
|
||||
switch (event.type)
|
||||
|
|
|
@ -49,13 +49,13 @@ const std::vector<string> Easy::json_array_to_vector(const string &json)
|
|||
return {};
|
||||
}
|
||||
|
||||
const vector<Easy::stream_event> Easy::parse_stream(
|
||||
const vector<Easy::stream_event_type> Easy::parse_stream(
|
||||
const std::string &streamdata)
|
||||
{
|
||||
string stream = streamdata;
|
||||
std::regex reevent("event: (update|notification|delete|ERROR)\ndata: (.*)\n");
|
||||
std::smatch match;
|
||||
std::vector<stream_event> vec = {};
|
||||
std::vector<stream_event_type> vec = {};
|
||||
|
||||
while (std::regex_search(stream, match, reevent))
|
||||
{
|
||||
|
@ -79,7 +79,7 @@ const vector<Easy::stream_event> Easy::parse_stream(
|
|||
return vec;
|
||||
}
|
||||
|
||||
const Easy::time Easy::string_to_time(const string &strtime)
|
||||
const Easy::time_type Easy::string_to_time(const string &strtime)
|
||||
{
|
||||
std::stringstream sstime(strtime);
|
||||
struct std::tm tm = {};
|
||||
|
|
|
@ -112,7 +112,7 @@ namespace Easy
|
|||
*
|
||||
* @since before 0.11.0
|
||||
*/
|
||||
const std::vector<string> json_array_to_vector(const string &json);
|
||||
const vector<string> json_array_to_vector(const string &json);
|
||||
|
||||
/*!
|
||||
* @brief Split stream into a vector of events
|
||||
|
@ -123,14 +123,14 @@ namespace Easy
|
|||
*
|
||||
* @since before 0.11.0
|
||||
*/
|
||||
const std::vector<stream_event> parse_stream(const std::string &streamdata);
|
||||
const vector<stream_event_type> parse_stream(const std::string &streamdata);
|
||||
|
||||
/*!
|
||||
* @brief Convert ISO 8601 time string to Easy::time.
|
||||
*
|
||||
* @param strtime Time string as returned by Mastodon.
|
||||
*/
|
||||
const Easy::time string_to_time(const string &strtime);
|
||||
const Easy::time_type string_to_time(const string &strtime);
|
||||
|
||||
/*!
|
||||
* @brief Child of Mastodon::API with abstract methods.
|
||||
|
|
|
@ -65,7 +65,7 @@ bool Account::bot() const
|
|||
return get_bool("bot");
|
||||
}
|
||||
|
||||
const Easy::time Account::created_at() const
|
||||
const Easy::time_type Account::created_at() const
|
||||
{
|
||||
return get_time("created_at");
|
||||
}
|
||||
|
@ -93,13 +93,13 @@ const std::vector<Easy::Emoji> Account::emojis()
|
|||
return {};
|
||||
}
|
||||
|
||||
const Easy::account_fields Account::fields() const
|
||||
const vector<Easy::account_field_type> Account::fields() const
|
||||
{
|
||||
const Json::Value &node = get("fields");
|
||||
|
||||
if (node.isArray())
|
||||
{
|
||||
Easy::account_fields vec;
|
||||
vector<Easy::account_field_type> vec;
|
||||
std::transform(node.begin(), node.end(), std::back_inserter(vec),
|
||||
[](const Json::Value &value)
|
||||
{
|
||||
|
@ -221,13 +221,13 @@ bool Account::Source::valid() const
|
|||
});
|
||||
}
|
||||
|
||||
const Easy::account_fields Account::Source::fields() const
|
||||
const vector<Easy::account_field_type> Account::Source::fields() const
|
||||
{
|
||||
const Json::Value &node = get("fields");
|
||||
|
||||
if (node.isArray())
|
||||
{
|
||||
Easy::account_fields vec;
|
||||
vector<Easy::account_field_type> vec;
|
||||
std::transform(node.begin(), node.end(), std::back_inserter(vec),
|
||||
[](const Json::Value &value)
|
||||
{
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
|
||||
using std::string;
|
||||
using std::uint64_t;
|
||||
using std::vector;
|
||||
|
||||
namespace Mastodon
|
||||
{
|
||||
|
@ -88,7 +89,7 @@ namespace Easy
|
|||
*
|
||||
* @since before 0.11.0
|
||||
*/
|
||||
const Easy::time created_at() const;
|
||||
const Easy::time_type created_at() const;
|
||||
|
||||
/*!
|
||||
* @brief Returns display name.
|
||||
|
@ -109,7 +110,7 @@ namespace Easy
|
|||
*
|
||||
* @since 0.16.1
|
||||
*/
|
||||
const Easy::account_fields fields() const;
|
||||
const vector<Easy::account_field_type> fields() const;
|
||||
|
||||
/*!
|
||||
* @brief Returns number of followers.
|
||||
|
@ -206,7 +207,7 @@ namespace Easy
|
|||
*
|
||||
* @since 0.18.5
|
||||
*/
|
||||
const Easy::account_fields fields() const;
|
||||
const vector<Easy::account_field_type> fields() const;
|
||||
|
||||
/*!
|
||||
* @brief Returns the language as ISO 6391 string.
|
||||
|
|
|
@ -71,7 +71,7 @@ const vector<Easy::context_type> Filter::context() const
|
|||
return {};
|
||||
}
|
||||
|
||||
const Easy::time Filter::expires_at() const
|
||||
const Easy::time_type Filter::expires_at() const
|
||||
{
|
||||
return get_time("expires_at");
|
||||
}
|
||||
|
|
|
@ -72,7 +72,7 @@ namespace Easy
|
|||
*
|
||||
* @since 0.104.0
|
||||
*/
|
||||
const Easy::time expires_at() const;
|
||||
const Easy::time_type expires_at() const;
|
||||
|
||||
/*!
|
||||
* @brief Returns if the phrase should disappear irreversibly.
|
||||
|
|
|
@ -32,6 +32,7 @@ bool Instance::valid() const
|
|||
"email",
|
||||
"version",
|
||||
"urls",
|
||||
"stats",
|
||||
"languages"
|
||||
});
|
||||
}
|
||||
|
@ -44,7 +45,6 @@ const Easy::Account Instance::contact_account() const
|
|||
return Easy::Account(node.toStyledString());
|
||||
}
|
||||
|
||||
ttdebug << "Could not get data: contact_account\n";
|
||||
return Easy::Account();
|
||||
}
|
||||
|
||||
|
@ -83,6 +83,11 @@ const string Instance::streaming_api() const
|
|||
return get_string("urls.streaming_api");
|
||||
}
|
||||
|
||||
const string Instance::thumbnail() const
|
||||
{
|
||||
return get_string("thumbnail");
|
||||
}
|
||||
|
||||
uint64_t Instance::max_toot_chars() const
|
||||
{
|
||||
const uint64_t max_chars = get_uint64("max_toot_chars");
|
||||
|
|
|
@ -81,6 +81,13 @@ namespace Easy
|
|||
*/
|
||||
const std::vector<string> languages() const;
|
||||
|
||||
/*!
|
||||
* @brief Returns the thumbnail of the instance.
|
||||
*
|
||||
* @since 0.106.0
|
||||
*/
|
||||
const string thumbnail() const;
|
||||
|
||||
/*!
|
||||
* @brief Returns the title of the instance
|
||||
*
|
||||
|
|
|
@ -43,7 +43,7 @@ const Easy::Account Notification::account() const
|
|||
return Easy::Account();
|
||||
}
|
||||
|
||||
const Easy::time Notification::created_at() const
|
||||
const Easy::time_type Notification::created_at() const
|
||||
{
|
||||
return get_time("created_at");
|
||||
}
|
||||
|
|
|
@ -64,7 +64,7 @@ namespace Easy
|
|||
*
|
||||
* @since before 0.11.0
|
||||
*/
|
||||
const Easy::time created_at() const;
|
||||
const Easy::time_type created_at() const;
|
||||
|
||||
/*!
|
||||
* @brief Returns notification ID
|
||||
|
|
|
@ -44,9 +44,9 @@ const string PushSubscription::server_key() const
|
|||
return get_string("server_key");
|
||||
}
|
||||
|
||||
const Easy::alerts PushSubscription::alerts() const
|
||||
const vector<Easy::alert_type> PushSubscription::alerts() const
|
||||
{
|
||||
Easy::alerts alerts;
|
||||
vector<Easy::alert_type> alerts;
|
||||
const Json::Value node = get("alerts");
|
||||
for (auto it = node.begin(); it != node.end(); ++it)
|
||||
{
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#define MASTODON_CPP_EASY_PUSHSUBSCRIPTION_HPP
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <cstdint>
|
||||
#include <map>
|
||||
|
||||
|
@ -31,6 +32,7 @@
|
|||
#endif
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
namespace Mastodon
|
||||
{
|
||||
|
@ -75,7 +77,7 @@ namespace Easy
|
|||
*
|
||||
* @since 0.100.0
|
||||
*/
|
||||
const Easy::alerts alerts() const;
|
||||
const vector<Easy::alert_type> alerts() const;
|
||||
|
||||
protected:
|
||||
/*!
|
||||
|
|
|
@ -78,7 +78,7 @@ const Easy::Card Status::card() const
|
|||
return Easy::Card();
|
||||
}
|
||||
|
||||
const Easy::time Status::created_at() const
|
||||
const Easy::time_type Status::created_at() const
|
||||
{
|
||||
return get_time("created_at");
|
||||
}
|
||||
|
|
|
@ -89,7 +89,7 @@ namespace Easy
|
|||
*
|
||||
* @since before 0.11.0
|
||||
*/
|
||||
const Easy::time created_at() const;
|
||||
const Easy::time_type created_at() const;
|
||||
|
||||
/*!
|
||||
* @brief Returns content of status
|
||||
|
|
|
@ -75,7 +75,7 @@ uint64_t Tag::History::accounts()
|
|||
return stouint64(get_string("accounts"));
|
||||
}
|
||||
|
||||
const Easy::time Tag::History::day()
|
||||
const Easy::time_type Tag::History::day()
|
||||
{
|
||||
const Json::Value node = get("day");
|
||||
|
||||
|
@ -86,7 +86,7 @@ const Easy::time Tag::History::day()
|
|||
}
|
||||
|
||||
ttdebug << "Could not get data: day\n";
|
||||
return Easy::time();
|
||||
return Easy::time_type();
|
||||
}
|
||||
|
||||
uint64_t Tag::History::uses()
|
||||
|
|
|
@ -68,7 +68,7 @@ namespace Easy
|
|||
*
|
||||
* @since 0.16.0
|
||||
*/
|
||||
const Easy::time day();
|
||||
const Easy::time_type day();
|
||||
|
||||
/*!
|
||||
* @brief Returns the number of accounts using that hashtag.
|
||||
|
|
|
@ -45,7 +45,7 @@ const string Token::scope() const
|
|||
return get_string("scope");
|
||||
}
|
||||
|
||||
const Easy::time Token::created_at() const
|
||||
const Easy::time_type Token::created_at() const
|
||||
{
|
||||
return get_time("created_at");
|
||||
}
|
||||
|
|
|
@ -72,7 +72,7 @@ namespace Easy
|
|||
*
|
||||
* @since 0.103.0
|
||||
*/
|
||||
const Easy::time created_at() const;
|
||||
const Easy::time_type created_at() const;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -227,7 +227,7 @@ bool Easy::Entity::get_bool(const string &key) const
|
|||
return false;
|
||||
}
|
||||
|
||||
const Easy::time Easy::Entity::get_time(const string &key) const
|
||||
const Easy::time_type Easy::Entity::get_time(const string &key) const
|
||||
{
|
||||
const Json::Value node = get(key);
|
||||
|
||||
|
|
|
@ -203,7 +203,7 @@ namespace Easy
|
|||
*
|
||||
* Returns clocks epoch if the value does not exist or is null.
|
||||
*/
|
||||
const Easy::time get_time(const string &key) const;
|
||||
const Easy::time_type get_time(const string &key) const;
|
||||
|
||||
/*!
|
||||
* @brief Returns the value of key as vector
|
||||
|
|
|
@ -20,17 +20,17 @@ namespace Mastodon
|
|||
{
|
||||
namespace Easy
|
||||
{
|
||||
time::operator const system_clock::time_point() const
|
||||
time_type::operator const system_clock::time_point() const
|
||||
{
|
||||
return timepoint;
|
||||
}
|
||||
|
||||
time::operator const string() const
|
||||
time_type::operator const string() const
|
||||
{
|
||||
return strtime("%FT%T%z", true);
|
||||
}
|
||||
|
||||
const string time::strtime(const string &format, const bool &local) const
|
||||
const string time_type::strtime(const string &format, const bool &local) const
|
||||
{
|
||||
constexpr std::uint16_t bufsize = 1024;
|
||||
std::time_t time = system_clock::to_time_t(timepoint);
|
||||
|
@ -51,7 +51,7 @@ namespace Easy
|
|||
}
|
||||
|
||||
std::ostream &operator <<(std::ostream &out,
|
||||
const time &t)
|
||||
const time_type &t)
|
||||
{
|
||||
const string s = t; // Converts using operator const string().
|
||||
out << s;
|
||||
|
|
|
@ -20,11 +20,9 @@
|
|||
#include <string>
|
||||
#include <utility>
|
||||
#include <chrono>
|
||||
#include <vector>
|
||||
|
||||
using std::string;
|
||||
using std::chrono::system_clock;
|
||||
using std::vector;
|
||||
|
||||
namespace Mastodon
|
||||
{
|
||||
|
@ -121,11 +119,14 @@ namespace Easy
|
|||
*
|
||||
* @since 0.100.0
|
||||
*/
|
||||
typedef struct stream_event
|
||||
typedef struct stream_event_type
|
||||
{
|
||||
event_type type = event_type::Undefined;
|
||||
string data;
|
||||
} stream_event;
|
||||
} stream_event_type;
|
||||
|
||||
[[deprecated("Replaced by Mastodon::Easy::stream_event_type")]]
|
||||
typedef stream_event_type stream_event;
|
||||
|
||||
/*!
|
||||
* @brief Type of notification and 'push is requested or not'.
|
||||
|
@ -138,21 +139,12 @@ namespace Easy
|
|||
bool pushreq = false;
|
||||
} alert_type;
|
||||
|
||||
/*!
|
||||
* @brief Vector of Easy::alert_type.
|
||||
*
|
||||
* Used in PushSubscription::alerts().
|
||||
*
|
||||
* @since 0.100.0
|
||||
*/
|
||||
typedef vector<alert_type> alerts;
|
||||
|
||||
/*!
|
||||
* @brief Type for time. Converts to time_point and string.
|
||||
*
|
||||
* @since 0.100.0
|
||||
*/
|
||||
struct time
|
||||
struct time_type
|
||||
{
|
||||
system_clock::time_point timepoint = system_clock::time_point();
|
||||
|
||||
|
@ -171,7 +163,7 @@ namespace Easy
|
|||
* @since 0.100.0
|
||||
*/
|
||||
friend std::ostream &operator <<(std::ostream &out,
|
||||
const Easy::time &t);
|
||||
const Easy::time_type &t);
|
||||
|
||||
/*!
|
||||
* @brief Converts time to a string.
|
||||
|
@ -196,6 +188,9 @@ namespace Easy
|
|||
const bool &local = true) const;
|
||||
};
|
||||
|
||||
[[deprecated("Replaced by Mastodon::Easy::time_type")]]
|
||||
typedef time_type time;
|
||||
|
||||
/*!
|
||||
* @brief Describes an account-field.
|
||||
*
|
||||
|
@ -205,17 +200,18 @@ namespace Easy
|
|||
{
|
||||
const string name;
|
||||
const string value;
|
||||
Easy::time verified_at;
|
||||
Easy::time_type verified_at;
|
||||
} account_field_type;
|
||||
|
||||
/*!
|
||||
* @brief Vector of Easy::account_field_type.
|
||||
*
|
||||
* Used in Easy::Account.
|
||||
* @brief URLs returned by Instance::urls().
|
||||
*
|
||||
* @since 0.106.0
|
||||
*/
|
||||
typedef vector<account_field_type> account_fields;
|
||||
typedef struct urls_type
|
||||
{
|
||||
string streaming_api;
|
||||
} urls_type;
|
||||
}
|
||||
}
|
||||
#endif // MASTODON_CPP_EASY_TYPES_EASY_HPP
|
||||
|
|
Reference in New Issue