Use Instance and Request classes.
This commit is contained in:
parent
1d3275e429
commit
4c557aae6e
49
include/instance.hpp
Normal file
49
include/instance.hpp
Normal file
|
@ -0,0 +1,49 @@
|
|||
/* This file is part of mastodonpp.
|
||||
* Copyright © 2020 tastytea <tastytea@tastytea.de>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef MASTODONPP_INSTANCE_HPP
|
||||
#define MASTODONPP_INSTANCE_HPP
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace mastodonpp
|
||||
{
|
||||
|
||||
using std::string;
|
||||
|
||||
class Instance
|
||||
{
|
||||
public:
|
||||
/*!
|
||||
* @brief Construct a new Instance object.
|
||||
*
|
||||
* Holds the hostname and access token of the instance.
|
||||
*
|
||||
* @param instance The hostname of the instance.
|
||||
* @param access_token Your access token.
|
||||
*
|
||||
* @since 0.1.0
|
||||
*/
|
||||
explicit Instance(string instance, string access_token);
|
||||
|
||||
private:
|
||||
const string _instance;
|
||||
string _access_token;
|
||||
};
|
||||
|
||||
} // namespace mastodonpp
|
||||
|
||||
#endif // MASTODONPP_INSTANCE_HPP
|
|
@ -17,8 +17,8 @@
|
|||
#ifndef MASTODONPP_HPP
|
||||
#define MASTODONPP_HPP
|
||||
|
||||
#include "instance.hpp"
|
||||
#include "return_types.hpp"
|
||||
#include <string>
|
||||
|
||||
/*!
|
||||
* @mainpage mastodonpp Reference
|
||||
|
@ -43,44 +43,21 @@
|
|||
* @section Example
|
||||
*
|
||||
* @code
|
||||
* mastodonpp::API masto("example.com", "");
|
||||
* mastodonpp::Instance instance{"example.com", ""};
|
||||
* @endcode
|
||||
*/
|
||||
|
||||
namespace mastodonpp
|
||||
{
|
||||
|
||||
using std::string;
|
||||
|
||||
/*!
|
||||
* @brief C++ wrapper for the Mastodon API.
|
||||
*
|
||||
* All text input is expected to be UTF-8.
|
||||
*
|
||||
* @since 0.1.0
|
||||
*
|
||||
*/
|
||||
|
||||
class API
|
||||
namespace mastodonpp
|
||||
{
|
||||
public:
|
||||
/*!
|
||||
* @brief Construct a new API object.
|
||||
*
|
||||
* To register your application, leave access_token blank and call
|
||||
* API::register_app1() and API::register_app2().
|
||||
*
|
||||
* @param instance The hostname of your instance.
|
||||
* @param access_token Your access token.
|
||||
*
|
||||
* @since 0.1.0
|
||||
*/
|
||||
explicit API(string instance, string access_token);
|
||||
|
||||
private:
|
||||
const string _instance;
|
||||
const string _access_token;
|
||||
};
|
||||
|
||||
|
||||
} // namespace mastodonpp
|
||||
|
||||
|
|
36
include/request.hpp
Normal file
36
include/request.hpp
Normal file
|
@ -0,0 +1,36 @@
|
|||
/* This file is part of mastodonpp.
|
||||
* Copyright © 2020 tastytea <tastytea@tastytea.de>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef MASTODONPP_REQUEST_HPP
|
||||
#define MASTODONPP_REQUEST_HPP
|
||||
|
||||
#include "instance.hpp"
|
||||
|
||||
namespace mastodonpp
|
||||
{
|
||||
|
||||
class Request
|
||||
{
|
||||
public:
|
||||
explicit Request(Instance &instance);
|
||||
|
||||
private:
|
||||
Instance &_instance;
|
||||
};
|
||||
|
||||
} // namespace mastodonpp
|
||||
|
||||
#endif // MASTODONPP_REQUEST_HPP
|
31
src/instance.cpp
Normal file
31
src/instance.cpp
Normal file
|
@ -0,0 +1,31 @@
|
|||
/* This file is part of mastodonpp.
|
||||
* Copyright © 2020 tastytea <tastytea@tastytea.de>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "instance.hpp"
|
||||
|
||||
#include <utility>
|
||||
|
||||
namespace mastodonpp
|
||||
{
|
||||
|
||||
using std::move;
|
||||
|
||||
Instance::Instance(string instance, string access_token)
|
||||
: _instance{move(instance)}
|
||||
, _access_token{move(access_token)}
|
||||
{}
|
||||
|
||||
} // namespace mastodonpp
|
|
@ -16,16 +16,9 @@
|
|||
|
||||
#include "mastodonpp.hpp"
|
||||
|
||||
#include <utility>
|
||||
|
||||
namespace mastodonpp
|
||||
{
|
||||
|
||||
using std::move;
|
||||
|
||||
API::API(string instance, string access_token)
|
||||
: _instance{move(instance)}
|
||||
, _access_token{move(access_token)}
|
||||
{}
|
||||
|
||||
} // namespace mastodonpp
|
||||
|
|
26
src/request.cpp
Normal file
26
src/request.cpp
Normal file
|
@ -0,0 +1,26 @@
|
|||
/* This file is part of mastodonpp.
|
||||
* Copyright © 2020 tastytea <tastytea@tastytea.de>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "request.hpp"
|
||||
|
||||
namespace mastodonpp
|
||||
{
|
||||
|
||||
Request::Request(Instance &instance)
|
||||
: _instance{instance}
|
||||
{}
|
||||
|
||||
} // namespace mastodonpp
|
|
@ -14,7 +14,8 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "mastodonpp.hpp"
|
||||
#include "instance.hpp"
|
||||
#include "request.hpp"
|
||||
|
||||
#include <catch.hpp>
|
||||
|
||||
|
@ -26,15 +27,33 @@ namespace mastodonpp
|
|||
|
||||
using std::string;
|
||||
|
||||
SCENARIO ("API can be instantiated.")
|
||||
SCENARIO ("Instantiations.")
|
||||
{
|
||||
bool exception = false;
|
||||
|
||||
GIVEN ("One instanciation.")
|
||||
WHEN ("Instance is instantiated.")
|
||||
{
|
||||
try
|
||||
{
|
||||
API masto("example.com", "");
|
||||
Instance instance{"example.com", ""};
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
exception = true;
|
||||
}
|
||||
|
||||
THEN ("No exception is thrown")
|
||||
{
|
||||
REQUIRE_FALSE(exception);
|
||||
}
|
||||
}
|
||||
|
||||
WHEN ("Request is instantiated.")
|
||||
{
|
||||
try
|
||||
{
|
||||
Instance instance{"example.com", ""};
|
||||
Request request{instance};
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue
Block a user