Instance: Add getters for hostname, baseuri and access_token.

This commit is contained in:
tastytea 2020-01-05 10:33:54 +01:00
parent f872707036
commit db315a3a70
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
2 changed files with 44 additions and 5 deletions

View File

@ -20,11 +20,13 @@
#include "curl_wrapper.hpp"
#include <string>
#include <string_view>
namespace mastodonpp
{
using std::string;
using std::string_view;
/*!
* @brief Holds the access data of an instance.
@ -39,15 +41,51 @@ public:
/*!
* @brief Construct a new Instance object.
*
* @param instance The hostname of the instance.
* @param hostname The hostname of the instance.
* @param access_token Your access token.
*
* @since 0.1.0
*/
explicit Instance(string instance, string access_token);
explicit Instance(string hostname, string access_token);
/*!
* @brief Returns the hostname.
*
* @since 0.1.0
*/
[[nodiscard]]
inline string_view get_hostname() const
{
return _hostname;
}
/*!
* @brief Returns the base URI.
*
* The base URI is https://” + the hostname.
*
* @since 0.1.0
*/
[[nodiscard]]
inline string_view get_baseuri() const
{
return _baseuri;
}
/*!
* @brief Returns the access token.
*
* @since 0.1.0
*/
[[nodiscard]]
inline string_view get_access_token() const
{
return _access_token;
}
private:
const string _instance;
const string _hostname;
const string _baseuri;
string _access_token;
};

View File

@ -23,8 +23,9 @@ namespace mastodonpp
using std::move;
Instance::Instance(string instance, string access_token)
: _instance{move(instance)}
Instance::Instance(string hostname, string access_token)
: _hostname{move(hostname)}
, _baseuri{"https://" + _hostname}
, _access_token{move(access_token)}
{}