Merge pull request #1 from tastytea/easy

This commit is contained in:
tastytea 2018-04-01 23:01:47 +00:00 committed by GitHub
commit 016f79b4d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
59 changed files with 3721 additions and 52 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
/build/
/doc/
/update_gh-pages.sh
/examples/example99*

View File

@ -16,9 +16,10 @@ before_install:
- sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-5 60
script:
- mkdir -p build && cd build
- cmake -DWITH_EXAMPLES=ON ..
- cmake -DWITH_EXAMPLES=ON -DWITH_TESTS=ON ..
- make VERBOSE=1
- make install DESTDIR=install
- ctest ..
- cd ..
before_deploy:

View File

@ -1,6 +1,6 @@
cmake_minimum_required (VERSION 3.7)
project (mastodon-cpp
VERSION 0.6.6
VERSION 0.7.22
LANGUAGES CXX
)
@ -9,6 +9,7 @@ include(GNUInstallDirs)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall")
set(CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
@ -21,21 +22,41 @@ configure_file (
"${PROJECT_BINARY_DIR}/version.hpp"
)
# Announce that we are compiling mastodon-cpp (used in easy.hpp and examples)
add_definitions(-DMASTODON_CPP=1)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
add_definitions(-DDEBUG=1)
endif()
if(WITHOUT_EASY)
add_definitions(-DWITHOUT_EASY=1)
endif()
# Library
file(GLOB sources src/*.cpp src/*.hpp src/api/*.cpp)
if(WITHOUT_EASY)
file(GLOB sources src/*.cpp src/api/*.cpp)
else()
file(GLOB sources src/*.cpp src/api/*.cpp src/easy/*.cpp)
endif()
add_library(mastodon-cpp SHARED ${sources})
set_target_properties(mastodon-cpp PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION ${mastodon-cpp_VERSION_MAJOR}
)
target_link_libraries(mastodon-cpp curlpp)
if(WITHOUT_EASY)
target_link_libraries(mastodon-cpp curlpp)
else()
target_link_libraries(mastodon-cpp curlpp jsoncpp)
endif()
install(TARGETS mastodon-cpp LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(FILES ${PROJECT_SOURCE_DIR}/src/mastodon-cpp.hpp
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(FILES src/mastodon-cpp.hpp
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/mastodon-cpp)
if(NOT WITHOUT_EASY)
file(GLOB easy_header src/easy/*.hpp)
install(FILES ${easy_header}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/mastodon-cpp/easy)
endif()
# Documentation
if(WITH_DOC)
@ -50,18 +71,18 @@ endif()
# Examples
if(WITH_EXAMPLES)
file(GLOB sources_examples src/examples/*.cpp)
file(GLOB sources_examples examples/*.cpp)
foreach(src ${sources_examples})
get_filename_component(bin ${src} NAME_WE)
add_executable(${bin} ${src})
target_link_libraries(${bin} -lpthread -ljsoncpp mastodon-cpp)
target_link_libraries(${bin} pthread jsoncpp mastodon-cpp)
endforeach()
endif()
# Tests
if(WITH_TESTS)
include(CTest)
file(GLOB sources_tests src/tests/test_*.cpp)
file(GLOB sources_tests tests/test_*.cpp)
foreach(src ${sources_tests})
get_filename_component(bin ${src} NAME_WE)
add_executable(${bin} ${src})

View File

@ -1,7 +1,7 @@
DOXYFILE_ENCODING = UTF-8
PROJECT_NAME = "mastodon-cpp"
PROJECT_NUMBER = 0.0.0
INPUT = README.md src/mastodon-cpp.hpp
INPUT = README.md src/ src/api/ src/easy/
USE_MDFILE_AS_MAINPAGE = README.md
CREATE_SUBDIRS = NO
ALLOW_UNICODE_NAMES = YES
@ -77,7 +77,7 @@ WARN_FORMAT = "$file:$line: $text"
INPUT_ENCODING = UTF-8
RECURSIVE = NO
EXCLUDE_SYMLINKS = NO
EXAMPLE_PATH = src/examples
EXAMPLE_PATH = examples
EXAMPLE_RECURSIVE = YES
FILTER_SOURCE_FILES = NO
SOURCE_BROWSER = NO

View File

@ -1,20 +1,25 @@
**mastodon-cpp** is a C++ wrapper for the Mastodon API.
The library takes care of the network stuff. You submit a query and get the raw JSON.
The library takes care of the network stuff. You submit a query and use the raw
JSON or abstract classes.
[TODO-list](https://github.com/tastytea/mastodon-cpp/milestones)
# Usage
The HTML reference can be generated with `build_doc.sh`, if doxygen is installed.
Or just look in `src/mastodon-cpp.hpp`. It is also available at [tastytea.github.io/mastodon-cpp/](https://tastytea.github.io/mastodon-cpp/docs/classMastodon_1_1API.html).
There are [examples](https://github.com/tastytea/mastodon-cpp/tree/master/src/examples) in `src/examples/`.
It is also available at [tastytea.github.io/mastodon-cpp/](https://tastytea.github.io/mastodon-cpp/docs/annotated.html).
There are [examples](https://github.com/tastytea/mastodon-cpp/tree/master/examples) in `examples/`.
## Upgrading from below 0.7.0
The header location has changed. They are now in `mastodon-cpp/`.
## Most basic example
```C++
#include <iostream>
#include <string>
#include <mastodon-cpp.hpp>
#include <mastodon-cpp/mastodon-cpp.hpp>
int main()
{
@ -25,9 +30,37 @@ int main()
}
```
## Another simple example
Using the `Easy-class`.
```C++
#include <iostream>
#include <string>
#include <vector>
#include <mastodon-cpp/mastodon-cpp.hpp>
#include <mastodon-cpp/easy/all.hpp>
using Mastodon::Easy;
int main()
{
Easy masto("social.example", "");
std::string answer;
masto.get(Mastodon::API::v1::timelines_public, answer);
for (const std::string &str : Easy::json_array_to_vector(answer))
{
Easy::Status status(str);
std::cout << " " << status.account().acct() << " wrote:\n";
std::cout << status.content() << '\n';
}
}
```
## Compiling your project
After you did a `make install`, a project consisting of one file can be compiled as follows:
A project consisting of one file can be compiled as follows:
g++ -std=c++14 -lmastodon-cpp example.cpp
@ -64,7 +97,7 @@ packages for the package managers of Gentoo, Debian and Red Hat.
### Gentoo
Put the ebuild into your [local overlay](https://wiki.gentoo.org/wiki/Custom_repository) and run `ebuild \<ebuild path\> manifest`.
Put the ebuild into your [local overlay](https://wiki.gentoo.org/wiki/Custom_repository) and run `ebuild <ebuild path> manifest`.
Install with `emerge mastodon-cpp`.
### DEB and RPM
@ -79,14 +112,14 @@ To use the DEB package on stretch, you will need [libcurlpp0](https://packages.d
### Dependencies
* Tested OS: GNU/Linux
* C++ compiler (tested: gcc 6.4/5.4, clang 5.0)
* Tested OS: Linux
* C++ compiler (tested: gcc 6.4 / 5.4, clang 5.0)
* [cmake](https://cmake.org/) (tested: 3.9.6)
* [libcurl](https://curl.haxx.se/) (tested: 7.58.0/7.35.0)
* [curlpp](http://www.curlpp.org/) (tested: 0.8.1/0.7.3)
* [libcurl](https://curl.haxx.se/) (tested: 7.58.0 / 7.35.0)
* [curlpp](http://www.curlpp.org/) (tested: 0.8.1 / 0.7.3)
* Optional
* Easy interface & Examples: [jsoncpp](https://github.com/open-source-parsers/jsoncpp) (tested: 1.8.1 / 1.7.2)
* Documentation: [doxygen](https://www.stack.nl/~dimitri/doxygen/) (tested: 1.8.13)
* Examples: [jsoncpp](https://github.com/open-source-parsers/jsoncpp) (tested: 1.8.1 / 1.7.2)
* DEB package: [dpkg](https://packages.qa.debian.org/dpkg) (tested: 1.19.0.5)
* RPM package: [rpm](http://www.rpm.org) (tested: 4.11.0.1)
@ -112,6 +145,7 @@ Download the current release at [GitHub](https://github.com/tastytea/mastodon-cp
cmake options:
* `-DCMAKE_BUILD_TYPE=Debug` for a debug build
* `-DWITHOUT_EASY=ON` to not build the Easy abstractions and to get rid of the jsoncpp-dependency (not recommended)
* `-DWITH_EXAMPLES=ON` if you want to compile the examples
* `-DWITH_TESTS=ON` if you want to compile the tests
* `-DWITH_DOC=ON` if you want to compile the HTML reference
@ -119,13 +153,13 @@ cmake options:
* `-DWITH_RPM=ON` if you want to be able to generate an rpm-package
You can run the tests with `ctest ..` inside the build directory.
To install, run `make install`
To install, run `make install`.
### Packages
#### Gentoo
Put the ebuild in `packages/gentoo` into your [local overlay](https://wiki.gentoo.org/wiki/Custom_repository) and rename it to match the desired version or use the live-ebuild (`mastodon-cpp-9999.ebuild`) to install the development version.
Put the ebuild from `packages/gentoo` into your [local overlay](https://wiki.gentoo.org/wiki/Custom_repository) and rename it to match the desired version or use the live-ebuild (`mastodon-cpp-9999.ebuild`) to install the development version.
#### DEB and RPM
@ -138,7 +172,7 @@ Run `make package` from the build directory to generate a tar.gz archive.
# Status of implementation
Feature complete as of Mastodon 2.2.0
Feature complete as of Mastodon 2.3.0
* [x] GET /api/v1/accounts/:id
* [x] GET /api/v1/accounts/verify_credentials

View File

@ -7,7 +7,11 @@
#include <vector>
#include <string>
#include <cstdint>
#include "../mastodon-cpp.hpp"
#ifdef MASTODON_CPP
#include "mastodon-cpp.hpp"
#else
#include <mastodon-cpp/mastodon-cpp.hpp>
#endif
using Mastodon::API;

View File

@ -8,7 +8,11 @@
#include <cstdint>
#include <sstream>
#include <jsoncpp/json/json.h>
#include "../mastodon-cpp.hpp"
#ifdef MASTODON_CPP
#include "mastodon-cpp.hpp"
#else
#include <mastodon-cpp/mastodon-cpp.hpp>
#endif
using Mastodon::API;
using std::cout;

View File

@ -11,7 +11,11 @@
#include <fstream>
#include <sstream>
#include <jsoncpp/json/json.h>
#include "../mastodon-cpp.hpp"
#ifdef MASTODON_CPP
#include "mastodon-cpp.hpp"
#else
#include <mastodon-cpp/mastodon-cpp.hpp>
#endif
using Mastodon::API;
using std::cout;

View File

@ -6,7 +6,11 @@
#include <vector>
#include <string>
#include <cstdint>
#include "../mastodon-cpp.hpp"
#ifdef MASTODON_CPP
#include "mastodon-cpp.hpp"
#else
#include <mastodon-cpp/mastodon-cpp.hpp>
#endif
using Mastodon::API;

View File

@ -8,7 +8,11 @@
#include <cstdint>
#include <chrono>
#include <thread>
#include "../mastodon-cpp.hpp"
#ifdef MASTODON_CPP
#include "mastodon-cpp.hpp"
#else
#include <mastodon-cpp/mastodon-cpp.hpp>
#endif
using Mastodon::API;

View File

@ -8,7 +8,11 @@
#include <cstdint>
#include <chrono>
#include <thread>
#include "../mastodon-cpp.hpp"
#ifdef MASTODON_CPP
#include "mastodon-cpp.hpp"
#else
#include <mastodon-cpp/mastodon-cpp.hpp>
#endif
using Mastodon::API;

View File

@ -7,7 +7,11 @@
#include <string>
#include <cstdint>
#include <sstream>
#include "../mastodon-cpp.hpp"
#ifdef MASTODON_CPP
#include "mastodon-cpp.hpp"
#else
#include <mastodon-cpp/mastodon-cpp.hpp>
#endif
using Mastodon::API;
@ -26,8 +30,7 @@ int main(int argc, char *argv[])
std::uint16_t ret;
std::string client_id, client_secret, url;
ret = masto.register_app1(argv[1],
"test123",
ret = masto.register_app1("test123",
"urn:ietf:wg:oauth:2.0:oob",
"read follow",
"",
@ -43,8 +46,7 @@ int main(int argc, char *argv[])
std::cin >> code;
std::string access_token;
ret = masto.register_app2(argv[1],
client_id,
ret = masto.register_app2(client_id,
client_secret,
"urn:ietf:wg:oauth:2.0:oob",
code,

View File

@ -7,7 +7,11 @@
#include <vector>
#include <string>
#include <cstdint>
#include "../mastodon-cpp.hpp"
#ifdef MASTODON_CPP
#include "mastodon-cpp.hpp"
#else
#include <mastodon-cpp/mastodon-cpp.hpp>
#endif
using Mastodon::API;

View File

@ -9,7 +9,11 @@
#include <thread>
#include <chrono>
#include <memory>
#include "../mastodon-cpp.hpp"
#ifdef MASTODON_CPP
#include "mastodon-cpp.hpp"
#else
#include <mastodon-cpp/mastodon-cpp.hpp>
#endif
using Mastodon::API;

View File

@ -6,7 +6,11 @@
#include <iostream>
#include <string>
#include <cstdint>
#include "../mastodon-cpp.hpp"
#ifdef MASTODON_CPP
#include "mastodon-cpp.hpp"
#else
#include <mastodon-cpp/mastodon-cpp.hpp>
#endif
using Mastodon::API;
@ -39,11 +43,10 @@ int main(int argc, char *argv[])
return 1;
}
std::string answer;
std::uint16_t ret = 0;
EasyToot masto(argv[1], argv[2]);
masto.toot("Test");
ret = masto.toot("Test");
if (ret != 0)
{
std::cerr << "Error: " << ret << '\n';

View File

@ -8,7 +8,11 @@
#include <cstdint>
#include <sstream>
#include <jsoncpp/json/json.h>
#include "../mastodon-cpp.hpp"
#ifdef MASTODON_CPP
#include "mastodon-cpp.hpp"
#else
#include <mastodon-cpp/mastodon-cpp.hpp>
#endif
using Mastodon::API;

View File

@ -0,0 +1,126 @@
/* This file is part of mastodon-cpp.
* Prints some information about your last status.
*/
// Don't compile this if the Easy-interface is turned off
#ifndef WITHOUT_EASY
#include <iostream>
#include <string>
#include <cstdint>
// If we are compiling mastodon-cpp, use another include path
#ifdef MASTODON_CPP
#include "mastodon-cpp.hpp"
#include "easy/all.hpp"
#else
#include <mastodon-cpp/mastodon-cpp.hpp>
// Include all headers in mastodon-cpp/easy/
#include <mastodon-cpp/easy/all.hpp>
#endif
using Mastodon::API;
using Mastodon::Easy;
using std::cout;
int main(int argc, char *argv[])
{
if (argc < 3)
{
std::cerr << "usage: " << argv[0] << " <instance> <access token>\n";
return 1;
}
Easy masto(argv[1], argv[2]);
std::string answer;
std::uint16_t ret;
// Get own account in order to obtain account ID
ret = masto.get(API::v1::accounts_verify_credentials, answer);
if (ret == 0)
{
// Construct an Account object using the JSON string from the server
Easy::Account acc(answer);
// Get last status
ret = masto.get(API::v1::accounts_id_statuses,
std::to_string(acc.id()),
{{ "limit", { "1" } }},
answer);
if (ret == 0)
{
// answer contains an array with a single object. This works because
// Easy::Status will turn that into an object, but an array with
// more than 1 object will not work.
Easy::Status status(answer);
// An Entitiy is valid if the JSON was not empty and contained no
// "error":-key
if (status.valid())
{
if (!status.language().empty())
cout << "Language: " << status.language() << '\n';
if (!status.content().empty())
cout << "Content: "
<< status.content().substr(0, 200) << "\n";
if (!status.application().name().empty())
cout << "Application used: "
<< status.application().name() << '\n';
cout << "ID: " << status.id() << '\n';
string acct;
string url;
std::vector<Easy::Attachment> attachments;
std::vector<Easy::Tag> tags;
// If the status is a reblog, print the original author
if (status.reblog().valid())
{
// status.reblog() is an Easy::Status
// status.reblog().account() is an Easy::Account
cout << "Original ID: " << status.reblog().id() << '\n';
acct = status.reblog().account().acct();
url = status.reblog().account().url();
attachments = status.reblog().media_attachments();
tags = status.reblog().tags();
}
else
{
acct = status.account().acct();
url = status.account().url();
attachments = status.media_attachments();
tags = status.tags();
}
cout << "From: " << acct << " ";
cout << "(" << url << ")\n";
// List attachments, if any
for (const Easy::Attachment &attachment : attachments)
{
cout << "Attachment: " << attachment.text_url()
<< " (" << attachment.size() << ")\n";
}
// List hashtags, if any
for (const Easy::Tag &tag : tags)
{
cout << "Hashtag: #" << tag.name()
<< " (" << tag.url() << ")\n";
}
}
return 0;
}
}
std::cout << answer << '\n';
std::cerr << "Error code: " << ret << '\n';
return ret;
}
#else
int main()
{
printf("mastodon-cpp was compiled without Easy support.\n");
return 255;
}
#endif // WITHOUT_EASY

View File

@ -0,0 +1,97 @@
/* This file is part of mastodon-cpp.
* Prints some information from the public timeline.
*/
// Don't compile this if the Easy-interface is turned off
#ifndef WITHOUT_EASY
#include <iostream>
#include <string>
#include <thread>
#include <memory>
#include <chrono>
#include <vector>
// If we are compiling mastodon-cpp, use another include path
#ifdef MASTODON_CPP
#include "mastodon-cpp.hpp"
#include "easy/all.hpp"
#else
#include <mastodon-cpp/mastodon-cpp.hpp>
// Include all headers in mastodon-cpp/easy/
#include <mastodon-cpp/easy/all.hpp>
#endif
using Mastodon::API;
using Mastodon::Easy;
using std::cout;
int main(int argc, char *argv[])
{
if (argc < 3)
{
std::cerr << "usage: " << argv[0] << " <instance> <access token>\n";
return 1;
}
cout << "I'll show you the public timeline. Press CTRL-C to abort\n";
// These have to be static in order to use them in- and outside the thread
static std::string stream;
// You can abort the stream with this pointer (ptr->abort_stream())
static std::unique_ptr<Mastodon::API::http> ptr;
// Start a new thread for the stream
std::thread pub_tl([=]
{
Easy masto(argv[1], argv[2]);
masto.get_stream(Mastodon::API::v1::streaming_public, stream, ptr);
});
while (true)
{
// Parse event stream and clear it afterwards
std::vector<Easy::stream_event> events = Easy::parse_stream(stream);
stream.clear();
// The contents of the stream are now in a vector of pairs
// { Easy::event_type, std::string }
for (const Easy::stream_event &event : events)
{
Easy::Status status;
Easy::Notification notification;
// Print out some information about the events
switch (event.first)
{
case Easy::event_type::Update:
status.from_string(event.second);
cout << "Status from: " << status.account().acct()
<< " (" << status.url() << ")\n";
break;
case Easy::event_type::Notification:
notification.from_string(event.second);
cout << "Notification involving: "
<< notification.account().acct()
<< " (" << notification.id() << ")\n";
break;
case Easy::event_type::Delete:
cout << "Deleted: " << event.second << '\n';
break;
default:
cout << "Something undefined happened. 😱\n";
}
}
std::this_thread::sleep_for(std::chrono::seconds(1));
}
pub_tl.join();
}
#else
int main()
{
printf("mastodon-cpp was compiled without Easy support.\n");
return 255;
}
#endif // WITHOUT_EASY

View File

@ -9,7 +9,7 @@ SLOT="0"
KEYWORDS=""
IUSE="doc debug examples"
RDEPEND=">=dev-cpp/curlpp-0.7.3
examples? ( >=dev-libs/boost-1.63.0 )"
>=dev-libs/jsoncpp-1.8.1"
DEPEND=">=dev-util/cmake-3.9.6
doc? ( >=app-doc/doxygen-1.8.13-r1 )
${RDEPEND}"
@ -44,7 +44,7 @@ src_install() {
if use examples; then
docinto examples
for file in src/examples/*.cpp; do
for file in examples/*.cpp; do
dodoc ${file}
done
fi

View File

@ -13,7 +13,7 @@ SLOT="0"
KEYWORDS=""
IUSE="doc debug examples"
RDEPEND=">=dev-cpp/curlpp-0.8.1
examples? ( >=dev-libs/boost-1.63.0 )"
>=dev-libs/jsoncpp-1.8.1"
DEPEND=">=dev-util/cmake-3.9.6
doc? ( >=app-doc/doxygen-1.8.13-r1 )
${RDEPEND}"
@ -52,7 +52,7 @@ src_install() {
if use examples; then
docinto examples
for file in src/examples/*.cpp; do
for file in examples/*.cpp; do
dodoc ${file}
done
fi

151
src/easy/account.cpp Normal file
View File

@ -0,0 +1,151 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "account.hpp"
#include "macros.hpp"
using namespace Mastodon;
using Account = Easy::Account;
Account::Account(const string &json)
: Entity(json)
{}
Account::Account()
: Entity()
{}
const string Account::acct() const
{
return get_string("acct");
}
const string Account::avatar() const
{
return get_string("avatar");
}
const string Account::avatar_static() const
{
return get_string("avatar_static");
}
const system_clock::time_point Account::created_at() const
{
return get_time_point("created_at");
}
const string Account::display_name() const
{
return get_string("display_name");
}
const std::uint_fast64_t Account::followers_count() const
{
return get_uint64("followers_count");
}
const std::uint_fast64_t Account::following_count() const
{
return get_uint64("following_count");
}
const string Account::header() const
{
return get_string("header");
}
const string Account::header_static() const
{
return get_string("header_static");
}
const std::uint_fast64_t Account::id() const
{
return std::stoull(get_string("id"));
}
const bool Account::locked() const
{
return get_bool("locked");
}
const bool Account::has_moved() const
{
if (get("moved").isObject())
{
return true;
}
return false;
}
const Account Account::moved() const
{
if (has_moved())
{
// TODO: Find an account with moved-node and test
return Account(get("moved").toStyledString());
}
return Account();
}
const string Account::note() const
{
return get_string("source.note");
}
const string Account::note_plain() const
{
return get_string("source.note");
}
const Easy::visibility_type Account::privacy() const
{
const string strprivacy = get_string("source.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;
}
const bool Account::sensitive() const
{
return get_bool("source.sensitive");
}
const std::uint_fast64_t Account::statuses_count() const
{
return get_uint64("statuses_count");
}
const string Account::url() const
{
return get_string("url");
}
const string Account::username() const
{
return get_string("username");
}

163
src/easy/account.hpp Normal file
View File

@ -0,0 +1,163 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MASTODON_CPP_EASY_ACCOUNT_HPP
#define MASTODON_CPP_EASY_ACCOUNT_HPP
#include <string>
#include <cstdint>
#include <chrono>
// If we are compiling mastodon-cpp, use another include path
#ifdef MASTODON_CPP
#include "mastodon-cpp.hpp"
#include "easy/easy.hpp"
#else
#include <mastodon-cpp/mastodon-cpp.hpp>
#include <mastodon-cpp/easy/easy.hpp>
#endif
using std::string;
using std::uint_fast64_t;
using std::chrono::system_clock;
namespace Mastodon
{
/*!
* @brief Class to hold accounts.
*/
class Easy::Account : public Easy::Entity
{
public:
/*!
* @brief Constructs an Account object from a JSON string.
*
* @param json JSON string
*/
explicit Account(const string &json);
/*!
* @brief Constructs an empty Account object.
*/
Account();
/*!
* @brief Returns username
*
* `username` for users on the same instance, `user@hostname`
* for users on other instances.
*/
const string acct() const;
/*!
* @brief Returns URL of avatar
*/
const string avatar() const;
/*!
* @brief Returns URL of static avatar
*/
const string avatar_static() const;
/*!
* @brief Returns time of creation
*/
const system_clock::time_point created_at() const;
/*!
* @brief Returns display name
*/
const string display_name() const;
/*!
* @brief Returns number of followers
*/
const uint_fast64_t followers_count() const;
/*!
* @brief Returns number of people this account follows
*/
const uint_fast64_t following_count() const;
/*!
* @brief Returns URL of header image
*/
const string header() const;
/*!
* @brief Returns URL of static header image
*/
const string header_static() const;
/*!
* @brief Returns account-ID
*/
const uint_fast64_t id() const;
/*!
* @brief Returns true if the account is locked
*/
const bool locked() const;
/*!
* @brief Returns true if the account has been moved
*/
const bool has_moved() const;
/*!
* @brief If the owner decided to switch accounts, new account is in
* this attribute
*/
const Account moved() const;
/*!
* @brief Returns note
*/
const string note() const;
/*!
* @brief Returns plaintext version of note
*/
const string note_plain() const;
/*!
* @brief Returns default privacy of new toots
*/
const visibility_type privacy() const;
/*!
* @brief Returns if media is marked as sensitive by default
*/
const bool sensitive() const;
/*!
* @brief Returns number of statuses
*/
const uint_fast64_t statuses_count() const;
/*!
* @brief Returns URL of the profile
*/
const string url() const;
/*!
* @brief Returns username (without @hostname)
*/
const string username() const;
};
}
#endif // MASTODON_CPP_EASY_ACCOUNT_HPP

57
src/easy/all.hpp Normal file
View File

@ -0,0 +1,57 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MASTODON_CPP_EASY_ALL_HPP
#define MASTODON_CPP_EASY_ALL_HPP
// If we are compiling mastodon-cpp, use another include path
#ifdef MASTODON_CPP
#include "easy/easy.hpp"
#include "easy/account.hpp"
#include "easy/application.hpp"
#include "easy/attachment.hpp"
#include "easy/card.hpp"
#include "easy/context.hpp"
#include "easy/emoji.hpp"
#include "easy/instance.hpp"
#include "easy/list.hpp"
#include "easy/mention.hpp"
#include "easy/notification.hpp"
#include "easy/relationship.hpp"
#include "easy/report.hpp"
#include "easy/results.hpp"
#include "easy/status.hpp"
#include "easy/tag.hpp"
#else
#include <mastodon-cpp/easy/easy.hpp>
#include <mastodon-cpp/easy/account.hpp>
#include <mastodon-cpp/easy/application.hpp>
#include <mastodon-cpp/easy/attachment.hpp>
#include <mastodon-cpp/easy/card.hpp>
#include <mastodon-cpp/easy/context.hpp>
#include <mastodon-cpp/easy/emoji.hpp>
#include <mastodon-cpp/easy/instance.hpp>
#include <mastodon-cpp/easy/list.hpp>
#include <mastodon-cpp/easy/mention.hpp>
#include <mastodon-cpp/easy/notification.hpp>
#include <mastodon-cpp/easy/relationship.hpp>
#include <mastodon-cpp/easy/report.hpp>
#include <mastodon-cpp/easy/results.hpp>
#include <mastodon-cpp/easy/status.hpp>
#include <mastodon-cpp/easy/tag.hpp>
#endif
#endif // MASTODON_CPP_EASY_ALL_HPP

38
src/easy/application.cpp Normal file
View File

@ -0,0 +1,38 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "application.hpp"
using namespace Mastodon;
using Application = Easy::Application;
Application::Application(const string &json)
: Entity(json)
{}
Application::Application()
: Entity()
{}
const string Application::name() const
{
return get_string("name");
}
const string Application::website() const
{
return get_string("website");
}

65
src/easy/application.hpp Normal file
View File

@ -0,0 +1,65 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MASTODON_CPP_EASY_APPLICATION_HPP
#define MASTODON_CPP_EASY_APPLICATION_HPP
#include <string>
// If we are compiling mastodon-cpp, use another include path
#ifdef MASTODON_CPP
#include "mastodon-cpp.hpp"
#include "easy/easy.hpp"
#else
#include <mastodon-cpp/mastodon-cpp.hpp>
#include <mastodon-cpp/easy/easy.hpp>
#endif
using std::string;
namespace Mastodon
{
/*!
* @brief Class to hold applications.
*/
class Easy::Application : public Easy::Entity
{
public:
/*!
* @brief Constructs an Application object from a JSON string.
*
* @param json JSON string
*/
explicit Application(const string &json);
/*!
* @brief Constructs an empty Application object.
*/
Application();
/*!
* @brief Returns the name of the application
*/
const string name() const;
/*!
* @brief Returns the website of the application
*/
const string website() const;
};
}
#endif // MASTODON_CPP_EASY_APPLICATION_HPP

163
src/easy/attachment.cpp Normal file
View File

@ -0,0 +1,163 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <sstream>
#include "attachment.hpp"
#include "macros.hpp"
using namespace Mastodon;
using Attachment = Easy::Attachment;
Attachment::Attachment(const string &json)
: Entity(json)
{}
Attachment::Attachment()
: Entity()
{}
const double Attachment::aspect() const
{
return get_double("meta.original.aspect");
}
const double Attachment::aspect_small() const
{
return get_double("meta.small.aspect");
}
const uint_fast64_t Attachment::bitrate() const
{
return get_uint64("meta.original.bitrate");
}
const string Attachment::description() const
{
return get_string("description");
}
const std::chrono::duration<double> Attachment::duration() const
{
const double sec = get_double("meta.original.duration");
return std::chrono::duration<double>(sec);
}
const std::array<double, 2> Attachment::focus() const
{
const Json::Value x = get("meta.focus.x");
const Json::Value y = get("meta.focus.y");
if (x.isDouble() && y.isDouble())
{
return
{{
x.asDouble(),
y.asDouble()
}};
}
return {};
}
const double Attachment::framerate() const
{
string strframes = get_string("meta.original.frame_rate");
if (!strframes.empty())
{
std::size_t pos = strframes.find('/');
if (pos != std::string::npos)
{
std::uint_fast16_t frames = std::stoul(strframes.substr(0, pos));
std::uint_fast16_t divider = std::stoul(strframes.substr(pos + 1));
return frames / divider;
}
}
return 0.0;
}
const uint_fast64_t Attachment::height() const
{
return get_uint64("meta.original.height");
}
const uint_fast64_t Attachment::height_small() const
{
return get_uint64("meta.small.height");
}
const std::uint_fast64_t Attachment::id() const
{
return std::stoull(get_string("id"));
}
const string Attachment::preview_url() const
{
return get_string("preview_url");
}
const string Attachment::remote_url() const
{
return get_string("remote_url");
}
const string Attachment::size() const
{
return get_string("meta.original.size");
}
const string Attachment::size_small() const
{
return get_string("meta.small.size");
}
const string Attachment::text_url() const
{
return get_string("text_url");
}
const Easy::attachment_type Attachment::type() const
{
const string strtype = get_string("type");
if (strtype.compare("image") == 0)
return attachment_type::Image;
else if (strtype.compare("video") == 0)
return attachment_type::Video;
else if (strtype.compare("gifv") == 0)
return attachment_type::Gifv;
else if (strtype.compare("unknown") == 0)
return attachment_type::Unknown;
ttdebug << "Could not get data: type\n";
return attachment_type::Undefined;
}
const string Attachment::url() const
{
return get_string("url");
}
const uint_fast64_t Attachment::width() const
{
return get_uint64("meta.original.width");
}
const uint_fast64_t Attachment::width_small() const
{
return get_uint64("meta.small.width");
}

157
src/easy/attachment.hpp Normal file
View File

@ -0,0 +1,157 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MASTODON_CPP_EASY_ATTACHMENT_HPP
#define MASTODON_CPP_EASY_ATTACHMENT_HPP
#include <string>
#include <cstdint>
#include <chrono>
#include <array>
// If we are compiling mastodon-cpp, use another include path
#ifdef MASTODON_CPP
#include "mastodon-cpp.hpp"
#include "easy/easy.hpp"
#else
#include <mastodon-cpp/mastodon-cpp.hpp>
#include <mastodon-cpp/easy/easy.hpp>
#endif
using std::string;
using std::uint_fast64_t;
namespace Mastodon
{
/*!
* @brief Class to hold attachments
*/
class Easy::Attachment : public Easy::Entity
{
public:
/*!
* @brief Constructs an Attachment object from a JSON string.
*
* @param json JSON string
*/
explicit Attachment(const string &json);
/*!
* @brief Constructs an empty Attachment object.
*/
Attachment();
/*!
* @brief Aspect of original image
*/
const double aspect() const;
/*!
* @brief Aspect of preview image
*/
const double aspect_small() const;
/*!
* @brief Returns the bitrate of a video
*/
const uint_fast64_t bitrate() const;
/*!
* @brief Returns the image description
*/
const string description() const;
/*!
* @brief Returns the duration of a video in seconds
*/
const std::chrono::duration<double> duration() const;
/*!
* @brief Returns the focus point (x, y)
*
* Values are between -1.0 and 1.0.
*/
const std::array<double, 2> focus() const;
/*!
* @brief Returns the framerate of a video in frames per second
*/
const double framerate() const;
/*!
* @brief Returns the height of the original image
*/
const uint_fast64_t height() const;
/*!
* @brief Returns the height of the preview image
*/
const uint_fast64_t height_small() const;
/*!
* @brief Returns the ID of the attachment
*/
const uint_fast64_t id() const;
/*!
* @brief Returns the URL of the preview image
*/
const string preview_url() const;
/*!
* @brief Returns the remote URL of the original image
*/
const string remote_url() const;
/*!
* @brief Returns the size of the original image
*/
const string size() const;
/*!
* @brief Returns the size of the preview image
*/
const string size_small() const;
/*!
* @brief Returns shorter URL for the image
*/
const string text_url() const;
/*!
* @brief Returns attachment type
*/
const attachment_type type() const;
/*!
* @brief Returns URL of the locally hosted version of the image
*/
const string url() const;
/*!
* @brief Returns the width of the original image
*/
const uint_fast64_t width() const;
/*!
* @brief Returns the width of the preview image
*/
const uint_fast64_t width_small() const;
};
}
#endif // MASTODON_CPP_EASY_ATTACHMENT_HPP

100
src/easy/card.cpp Normal file
View File

@ -0,0 +1,100 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "card.hpp"
#include "macros.hpp"
using namespace Mastodon;
using Card = Easy::Card;
Card::Card(const string &json)
: Entity(json)
{}
Card::Card()
: Entity()
{}
const string Card::author_name() const
{
return get_string("author_name");
}
const string Card::author_url() const
{
return get_string("author_url");
}
const string Card::description() const
{
return get_string("description");
}
const uint_fast64_t Card::height() const
{
return get_uint64("height");
}
const string Card::html() const
{
return get_string("html");
}
const string Card::image() const
{
return get_string("image");
}
const string Card::provider_name() const
{
return get_string("provider_name");
}
const string Card::provider_url() const
{
return get_string("provider_url");
}
const string Card::title() const
{
return get_string("title");
}
const Easy::card_type Card::type() const
{
const string strtype = get_string("type");
if (strtype.compare("link") == 0)
return card_type::Link;
else if (strtype.compare("photo") == 0)
return card_type::Photo;
else if (strtype.compare("video") == 0)
return card_type::Video;
else if (strtype.compare("rich") == 0)
return card_type::Rich;
ttdebug << "Could not get data: type\n";
return card_type::Undefined;
}
const string Card::url() const
{
return get_string("url");
}
const uint_fast64_t Card::width() const
{
return get_uint64("width");
}

117
src/easy/card.hpp Normal file
View File

@ -0,0 +1,117 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MASTODON_CPP_EASY_CARD_HPP
#define MASTODON_CPP_EASY_CARD_HPP
#include <string>
#include <cstdint>
// If we are compiling mastodon-cpp, use another include path
#ifdef MASTODON_CPP
#include "mastodon-cpp.hpp"
#include "easy/easy.hpp"
#else
#include <mastodon-cpp/mastodon-cpp.hpp>
#include <mastodon-cpp/easy/easy.hpp>
#endif
using std::string;
using std::uint_fast64_t;
namespace Mastodon
{
/*!
* @brief Class to hold cards
*/
class Easy::Card : public Easy::Entity
{
public:
/*!
* @brief Constructs a Card object from a JSON string.
*
* @param json JSON string
*/
explicit Card(const string &json);
/*!
* @brief Constructs an empty Card object.
*/
Card();
/*!
* @brief Returns the name of the author
*/
const string author_name() const;
/*!
* @brief Returns the URL of the author
*/
const string author_url() const;
/*!
* @brief Returns the description
*/
const string description() const;
/*!
* @brief Returns the height of the card
*/
const uint_fast64_t height() const;
/*!
* @brief Returns the HTML
*/
const string html() const;
/*!
* @brief Returns the URL of the image associated with the card
*/
const string image() const;
/*!
* @brief Returns the name of the provider
*/
const string provider_name() const;
/*!
* @brief Returns the URL of the provider
*/
const string provider_url() const;
/*!
* @brief Returns the title
*/
const string title() const;
/*!
* @brief Returns the type of the card
*/
const Easy::card_type type() const;
/*!
* @brief Returns the URL associated with the card
*/
const string url() const;
/*!
* @brief Returns the width of the card
*/
const uint_fast64_t width() const;
};
}
#endif // MASTODON_CPP_EASY_CARD_HPP

63
src/easy/context.cpp Normal file
View File

@ -0,0 +1,63 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "context.hpp"
#include "macros.hpp"
using namespace Mastodon;
using Context = Easy::Context;
Context::Context(const string &json)
: Entity(json)
{}
Context::Context()
: Entity()
{}
const std::vector<Easy::Status> Context::ancestors() const
{
const Json::Value node = get("ancestors");
if (node.isArray())
{
std::vector<Easy::Status> vec;
for (const Json::Value &value : node)
{
vec.push_back(Easy::Status(value.toStyledString()));
}
return vec;
}
ttdebug << "Could not get data: ancestors\n";
return {};
}
const std::vector<Easy::Status> Context::descendants() const
{
const Json::Value node = get("descendants");
if (node.isArray())
{
std::vector<Easy::Status> vec;
for (const Json::Value &value : node)
{
vec.push_back(Easy::Status(value.toStyledString()));
}
return vec;
}
ttdebug << "Could not get data: descendants\n";
return {};
}

68
src/easy/context.hpp Normal file
View File

@ -0,0 +1,68 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MASTODON_CPP_EASY_CONTEXT_HPP
#define MASTODON_CPP_EASY_CONTEXT_HPP
#include <string>
#include <vector>
// If we are compiling mastodon-cpp, use another include path
#ifdef MASTODON_CPP
#include "mastodon-cpp.hpp"
#include "easy/easy.hpp"
#include "easy/status.hpp"
#else
#include <mastodon-cpp/mastodon-cpp.hpp>
#include <mastodon-cpp/easy/easy.hpp>
#include <mastodon-cpp/easy/status.hpp>
#endif
using std::string;
namespace Mastodon
{
/*!
* @brief Class to hold contexts
*/
class Easy::Context : public Easy::Entity
{
public:
/*!
* @brief Constructs a Context object from a JSON string.
*
* @param json JSON string
*/
explicit Context(const string &json);
/*!
* @brief Constructs an empty Context object.
*/
Context();
/*!
* @brief Returns the ancestors of the Status as vector of Statuses
*/
const std::vector<Status> ancestors() const;
/*!
* @brief Returns the descendants of the Status as vector of Statuses
*/
const std::vector<Status> descendants() const;
};
}
#endif // MASTODON_CPP_EASY_CONTEXT_HPP

78
src/easy/easy.cpp Normal file
View File

@ -0,0 +1,78 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <ctime>
#include <iomanip> // get_time
#include <sstream>
#include <regex>
#include "easy.hpp"
#include "macros.hpp"
using namespace Mastodon;
using std::string;
Easy::Easy(const string &instance, const string &access_token)
: API(instance, access_token)
{}
const std::vector<string> Easy::json_array_to_vector(const string &json)
{
Json::Value json_array;
std::stringstream ss(json);
ss >> json_array;
if (json_array.isArray())
{
std::vector<string> vec;
for (const Json::Value &value : json_array)
{
vec.push_back(value.toStyledString());
}
return vec;
}
ttdebug << "ERROR: JSON string holds no array\n";
ttdebug << "String was: " << json << '\n';
return {};
}
const std::vector<Easy::stream_event>
Easy::parse_stream(const std::string &streamdata)
{
string stream = streamdata;
std::regex reevent("event: (update|notification|delete)\ndata: (.*)\n");
std::smatch match;
std::vector<stream_event> vec = {};
while (std::regex_search(stream, match, reevent))
{
const string &event = match[1].str();
const string &data = match[2].str();
event_type type = event_type::Undefined;
if (event.compare("update") == 0)
type = event_type::Update;
else if (event.compare("notification") == 0)
type = event_type::Notification;
else if (event.compare("delete") == 0)
type = event_type::Delete;
vec.push_back(stream_event(type, data));
stream = match.suffix().str();
}
return vec;
}

254
src/easy/easy.hpp Normal file
View File

@ -0,0 +1,254 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MASTODON_EASY_CPP_HPP
#define MASTODON_EASY_CPP_HPP
#include <string>
#include <cstdint>
#include <chrono>
#include <vector>
#include <utility>
#include <jsoncpp/json/json.h>
// If we are compiling mastodon-cpp, use another include path
#ifdef MASTODON_CPP
#include "mastodon-cpp.hpp"
#else
#include <mastodon-cpp/mastodon-cpp.hpp>
#endif
using std::string;
using std::uint_fast64_t;
using std::chrono::system_clock;
namespace Mastodon
{
/*!
* @brief Child of Mastodon::API with abstract methods.
*/
class Easy : public API
{
public:
/*!
* @brief Describes the event type
*/
enum class event_type
{
Update,
Notification,
Delete,
Undefined
};
/*!
* @brief Describes visibility of toots.
*/
enum class visibility_type
{
Direct,
Private,
Unlisted,
Public,
Undefined
};
/*!
* @brief Describes the attachment type
*/
enum class attachment_type
{
Image,
Video,
Gifv,
Unknown,
Undefined
};
/*!
* @brief Describes the card type
*/
enum class card_type
{
Link,
Photo,
Video,
Rich,
Undefined
};
/*!
* @brief Describes the notification type
*/
enum class notification_type
{
Mention,
Reblog,
Favourite,
Follow,
Undefined
};
typedef std::pair<event_type, string> stream_event;
/*!
* @brief Constructs a new Easy object.
*
* To register your application, leave access_token blank and call
* register_app1() and register_app2().
*
* @param instance The hostname of your instance
* @param access_token The access token
*/
explicit Easy(const string &instance, const string &access_token);
/*!
* @brief Turns a JSON array into a vector of strings
*
* @param json JSON string holding the array
*
* @return vector of strings or an empty vector on error
*/
static const std::vector<string> json_array_to_vector(const string &json);
/*!
* @brief Split stream into a vector of events
*
* @param streamdata Data from get_stream()
*
* @return vector of stream events
*/
static const std::vector<stream_event>
parse_stream(const std::string &streamdata);
/*!
* @brief Base class for all entities.
*/
class Entity
{
public:
/*!
* @brief Constructs an Entity object from a JSON string.
*
* @param json JSON string
*/
explicit Entity(const string &json);
/*!
* @brief Constructs an empty Entity object.
*/
Entity();
/*!
* @brief Replaces the Entity with a new one from a JSON string.
*
* @param json JSON string
*/
const void from_string(const string &json);
/*!
* @brief Returns the JSON object of the Entity
*
* @return JSON object
*/
const Json::Value to_object() const;
/*!
* @brief Returns true if the Entity holds valid data
*/
const bool valid() const;
/*!
* @brief Returns error string sent by the server
*/
const string error() const;
protected:
/*!
* @brief Returns the value of key as Json::Value
*
* Returns an empty object if the value does not exist or is
* null.
*/
const Json::Value get(const string &key) const;
/*!
* @brief Returns the value of key as std::string
*
* returns "" if the value does not exist or is null.
*/
const string get_string(const string &key) const;
/*!
* @brief Returns the value of key as std::uint_fast64_t
*
* Returns 0 if the value does not exist or is null.
*/
const uint_fast64_t get_uint64(const string &key) const;
/*!
* @brief Returns the value of key as double
*
* Returns 0.0 if the value does not exist or is null.
*/
const double get_double(const string &key) const;
// TODO: Maybe an enum would be better?
/*!
* @brief Returns the value of key as bool
*
* Returns false if the value does not exist or is null.
*/
const bool get_bool(const string &key) const;
/*!
* @brief Returns the value of key as time_point
*
* Returns clocks epoch if the value does not exist or is null.
*/
const system_clock::time_point get_time_point(const string &key) const;
/*!
* @brief Returns the value of key as vector
*
* Returns an empty vector if the value does not exist or is
* null.
*/
const std::vector<string> get_vector(const string &key) const;
Json::Value _tree;
bool _valid;
};
class Account;
class Application;
class Attachment;
class Card;
class Context;
class Emoji;
class Instance;
class List;
class Mention;
class Notification;
class Relationship;
class Report;
class Results;
class Status;
class Tag;
};
}
#endif // MASTODON_EASY_CPP_HPP

44
src/easy/emoji.cpp Normal file
View File

@ -0,0 +1,44 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "emoji.hpp"
#include "macros.hpp"
using namespace Mastodon;
using Emoji = Easy::Emoji;
Emoji::Emoji(const string &json)
: Entity(json)
{}
Emoji::Emoji()
: Entity()
{}
const string Emoji::shortcode() const
{
return get_string("shortcode");
}
const string Emoji::static_url() const
{
return get_string("static_url");
}
const string Emoji::url() const
{
return get_string("url");
}

70
src/easy/emoji.hpp Normal file
View File

@ -0,0 +1,70 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MASTODON_CPP_EASY_EMOJI_HPP
#define MASTODON_CPP_EASY_EMOJI_HPP
#include <string>
// If we are compiling mastodon-cpp, use another include path
#ifdef MASTODON_CPP
#include "mastodon-cpp.hpp"
#include "easy/easy.hpp"
#else
#include <mastodon-cpp/mastodon-cpp.hpp>
#include <mastodon-cpp/easy/easy.hpp>
#endif
using std::string;
namespace Mastodon
{
/*!
* @brief Class to hold emojis
*/
class Easy::Emoji : public Easy::Entity
{
public:
/*!
* @brief Constructs an Emoji object from a JSON string.
*
* @param json JSON string
*/
explicit Emoji(const string &json);
/*!
* @brief Constructs an empty Emoji object.
*/
Emoji();
/*!
* @brief Returns the shortcode of the emoji
*/
const string shortcode() const;
/*!
* @brief Returns the URL to the emoji static image
*/
const string static_url() const;
/*!
* @brief Returns the URL to the emoji image
*/
const string url() const;
};
}
#endif // MASTODON_CPP_EASY_EMOJI_HPP

203
src/easy/entity.cpp Normal file
View File

@ -0,0 +1,203 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <ctime>
#include <iomanip> // get_time
#include <sstream>
#include <chrono>
#include <regex>
#include "easy.hpp"
#include "macros.hpp"
using namespace Mastodon;
using std::string;
using std::chrono::system_clock;
Easy::Entity::Entity(const string &json)
: _tree(Json::nullValue)
, _valid(false)
{
from_string(json);
}
const void Easy::Entity::from_string(const string &json)
{
std::stringstream ss(json);
ss >> _tree;
// If the JSON is a single object encapsulated in an array,
// transform it into an object. If the JSON string is [], transform to null
if (_tree.type() == Json::ValueType::arrayValue && _tree.size() <= 1)
{
_tree = _tree[0];
}
if (_tree.isNull())
{
ttdebug << "ERROR: JSON string holds no object\n";
ttdebug << "String was: " << json << '\n';
}
else if (!_tree["error"].isNull())
{
ttdebug << "ERROR: Server returned an error\n";
ttdebug << "String was: " << json << '\n';
}
else
{
_valid = true;
}
}
const Json::Value Easy::Entity::to_object() const
{
return _tree;
}
Easy::Entity::Entity()
: _valid(false)
{}
const bool Easy::Entity::valid() const
{
return _valid;
}
const string Easy::Entity::error() const
{
return get_string("error");
}
const Json::Value Easy::Entity::get(const string &key) const
{
const Json::Value *node;
if (key.find('.') == std::string::npos)
{
node = &_tree[key];
}
else
{
// If dots in key, we have to walk through the tree
std::size_t pos = 0;
string current_key = key;
node = &_tree;
while ((pos = current_key.find('.')) != std::string::npos)
{
try
{
node = &(*node)[current_key.substr(0, pos)];
current_key = current_key.substr(pos + 1);
}
catch (const Json::LogicError &e)
{
ttdebug << e.what() << '\n';
goto error;
}
}
node = &(*node)[current_key];
}
if (!node->isNull())
{
return *node;
}
error:
ttdebug << "Could not get data: " << key << '\n';
return Json::Value();
}
const string Easy::Entity::get_string(const string &key) const
{
const Json::Value node = get(key);
if (node.isString())
{
return node.asString();
}
return "";
}
const uint_fast64_t Easy::Entity::get_uint64(const string &key) const
{
const Json::Value node = get(key);
if (node.isUInt64())
{
return node.asUInt64();
}
return 0;
}
const double Easy::Entity::get_double(const string &key) const
{
const Json::Value node = get(key);
if (node.isDouble())
{
return node.asDouble();
}
return 0.0;
}
const bool Easy::Entity::get_bool(const string &key) const
{
const Json::Value node = get(key);
if (node.isBool())
{
return node.asBool();
}
return false;
}
const system_clock::time_point
Easy::Entity::get_time_point(const string &key) const
{
const Json::Value node = get(key);
if (node.isString())
{
std::stringstream sstime(node.asString());
struct std::tm tm = {0};
sstime >> std::get_time(&tm, "%Y-%m-%dT%T");
std::time_t time = timegm(&tm);
return system_clock::from_time_t(time);
}
// Return clocks epoch
return system_clock::time_point();
}
const std::vector<string> Easy::Entity::get_vector(const string &key) const
{
const Json::Value node = get(key);
if (node.isArray())
{
std::vector<string> vec;
for (const Json::Value &value : node)
{
vec.push_back(value.asString());
}
return vec;
}
return {};
}

78
src/easy/instance.cpp Normal file
View File

@ -0,0 +1,78 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <jsoncpp/json/json.h>
#include "instance.hpp"
#include "account.hpp"
#include "macros.hpp"
using namespace Mastodon;
using Instance = Easy::Instance;
Instance::Instance(const string &json)
: Entity(json)
{}
Instance::Instance()
: Entity()
{}
const Easy::Account Instance::contact_account() const
{
const Json::Value node = get("contact_account");
if (node.isObject())
{
return Easy::Account(node.toStyledString());
}
ttdebug << "Could not get data: contact_account\n";
return Easy::Account();
}
const string Instance::description() const
{
return get_string("description");
}
const string Instance::email() const
{
return get_string("email");
}
const std::vector<string> Instance::languages() const
{
return get_vector("languages");
}
const string Instance::title() const
{
return get_string("title");
}
const string Instance::uri() const
{
return get_string("uri");
}
const string Instance::version() const
{
return get_string("version");
}
const string Instance::streaming_api() const
{
return get_string("urls.streaming_api");
}

100
src/easy/instance.hpp Normal file
View File

@ -0,0 +1,100 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MASTODON_CPP_EASY_INSTANCE_HPP
#define MASTODON_CPP_EASY_INSTANCE_HPP
#include <string>
#include <vector>
// If we are compiling mastodon-cpp, use another include path
#ifdef MASTODON_CPP
#include "mastodon-cpp.hpp"
#include "easy/easy.hpp"
#include "easy/account.hpp"
#else
#include <mastodon-cpp/mastodon-cpp.hpp>
#include <mastodon-cpp/easy/easy.hpp>
#include <mastodon-cpp/easy/account.hpp>
#endif
using std::string;
namespace Mastodon
{
/*!
* @brief Class to hold instances
*/
class Easy::Instance : public Easy::Entity
{
public:
/*!
* @brief Constructs an Instance object from a JSON string.
*
* @param json JSON string
*/
explicit Instance(const string &json);
/*!
* @brief Constructs an empty Instance object.
*/
Instance();
/*!
* @brief Returns the Account of the admin or another contact person
*/
const Account contact_account() const;
/*!
* @brief Returns the description of the instance
*/
const string description() const;
/*!
* @brief Returns the email address which can be used to contact the
* instance administrator
*/
const string email() const;
/*!
* @brief Returns a vector of ISO 6391 language codes the instance has
* chosen to advertise
*/
const std::vector<string> languages() const;
/*!
* @brief Returns the title of the instance
*/
const string title() const;
/*!
* @brief Returns the URI of the instance
*/
const string uri() const;
/*!
* @brief Returns the version used by the instance
*/
const string version() const;
/*!
* @brief Returns the URL for the streaming API
*/
const string streaming_api() const;
};
}
#endif // MASTODON_CPP_EASY_INSTANCE_HPP

40
src/easy/list.cpp Normal file
View File

@ -0,0 +1,40 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "list.hpp"
using namespace Mastodon;
using List = Easy::List;
using std::string;
using std::uint_fast64_t;
List::List(const string &json)
: Entity(json)
{}
List::List()
: Entity()
{}
const uint_fast64_t List::id() const
{
return std::stoull(get_string("id"));
}
const string List::title() const
{
return get_string("title");
}

68
src/easy/list.hpp Normal file
View File

@ -0,0 +1,68 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MASTODON_CPP_EASY_LIST_HPP
#define MASTODON_CPP_EASY_LIST_HPP
#include <string>
#include <vector>
#include <cstdint>
// If we are compiling mastodon-cpp, use another include path
#ifdef MASTODON_CPP
#include "mastodon-cpp.hpp"
#include "easy/easy.hpp"
#else
#include <mastodon-cpp/mastodon-cpp.hpp>
#include <mastodon-cpp/easy/easy.hpp>
#endif
using std::string;
using std::uint_fast64_t;
namespace Mastodon
{
/*!
* @brief Class to hold lists
*/
class Easy::List : public Easy::Entity
{
public:
/*!
* @brief Constructs a List object from a JSON string.
*
* @param json JSON string
*/
explicit List(const string &json);
/*!
* @brief Constructs an empty List object.
*/
List();
/*!
* @brief Returns list-ID
*/
const uint_fast64_t id() const;
/*!
* @brief Returns title
*/
const string title() const;
};
}
#endif // MASTODON_CPP_EASY_LIST_HPP

48
src/easy/mention.cpp Normal file
View File

@ -0,0 +1,48 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "mention.hpp"
using namespace Mastodon;
using Mention = Easy::Mention;
Mention::Mention(const string &json)
: Entity(json)
{}
Mention::Mention()
: Entity()
{}
const string Mention::acct() const
{
return get_string("acct");
}
const uint_fast64_t Mention::id() const
{
return std::stoull(get_string("id"));
}
const string Mention::url() const
{
return get_string("url");
}
const string Mention::username() const
{
return get_string("username");
}

78
src/easy/mention.hpp Normal file
View File

@ -0,0 +1,78 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MASTODON_CPP_EASY_MENTION_HPP
#define MASTODON_CPP_EASY_MENTION_HPP
#include <string>
#include <cstdint>
// If we are compiling mastodon-cpp, use another include path
#ifdef MASTODON_CPP
#include "mastodon-cpp.hpp"
#include "easy/easy.hpp"
#else
#include <mastodon-cpp/mastodon-cpp.hpp>
#include <mastodon-cpp/easy/easy.hpp>
#endif
using std::string;
using std::uint_fast64_t;
using std::chrono::system_clock;
namespace Mastodon
{
/*!
* @brief Class to hold mentions
*/
class Easy::Mention : public Easy::Entity
{
public:
/*!
* @brief Constructs a Mention object from a JSON string.
*
* @param json JSON string
*/
explicit Mention(const string &json);
/*!
* @brief Constructs an empty Mention object.
*/
Mention();
/*!
* @brief Returns acct
*/
const string acct() const;
/*!
* @brief Returns account ID
*/
const uint_fast64_t id() const;
/*!
* @brief Returns the URL of user's profile
*/
const string url() const;
/*!
* @brief Returns the username of the account
*/
const string username() const;
};
}
#endif // MASTODON_CPP_EASY_MENTION_HPP

78
src/easy/notification.cpp Normal file
View File

@ -0,0 +1,78 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "notification.hpp"
#include "macros.hpp"
using namespace Mastodon;
using Notification = Easy::Notification;
Notification::Notification(const string &json)
: Entity(json)
{}
Notification::Notification()
: Entity()
{}
const Easy::Account Notification::account() const
{
const Json::Value node = _tree["account"];
if (node.isObject())
{
return Easy::Account(node.toStyledString());
}
ttdebug << "Could not get data: account\n";
return Easy::Account();
}
const system_clock::time_point Notification::created_at() const
{
return get_time_point("created_at");
}
const uint_fast64_t Notification::id() const
{
return std::stoull(get_string("id"));
}
const Easy::Status Notification::status() const
{
const Json::Value node = get("restatusblog");
if (node.isObject())
{
return Easy::Status(node.toStyledString());
}
ttdebug << "Could not get data: status\n";
return Easy::Status();
}
const Easy::notification_type Notification::type() const
{
const string strtype = get_string("type");
if (strtype.compare("mention") == 0)
return notification_type::Mention;
else if (strtype.compare("reblog") == 0)
return notification_type::Reblog;
else if (strtype.compare("favourite") == 0)
return notification_type::Favourite;
else if (strtype.compare("follow") == 0)
return notification_type::Follow;
return notification_type::Undefined;
}

89
src/easy/notification.hpp Normal file
View File

@ -0,0 +1,89 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MASTODON_CPP_EASY_NOTIFICATION_HPP
#define MASTODON_CPP_EASY_NOTIFICATION_HPP
#include <string>
#include <cstdint>
#include <chrono>
// If we are compiling mastodon-cpp, use another include path
#ifdef MASTODON_CPP
#include "mastodon-cpp.hpp"
#include "easy/easy.hpp"
#include "easy/account.hpp"
#include "easy/status.hpp"
#else
#include <mastodon-cpp/mastodon-cpp.hpp>
#include <mastodon-cpp/easy/easy.hpp>
#include <mastodon-cpp/easy/account.hpp>
#include <mastodon-cpp/easy/status.hpp>
#endif
using std::string;
using std::uint_fast64_t;
using std::chrono::system_clock;
namespace Mastodon
{
/*!
* @brief Class to hold notifications
*/
class Easy::Notification : public Easy::Entity
{
public:
/*!
* @brief Constructs a Notification object from a JSON string.
*
* @param json JSON string
*/
explicit Notification(const string &json);
/*!
* @brief Constructs an empty Notification object.
*/
Notification();
/*!
* @brief Returns the Account sending the notification to the user
*/
const Account account() const;
/*!
* @brief Returns time of creation
*/
const system_clock::time_point created_at() const;
/*!
* @brief Returns notification ID
*/
const uint_fast64_t id() const;
/*!
* @brief Returns the Status associated with the notification, if
* applicable
*/
const Status status() const;
/*!
* @brief Returns notification type
*/
const Easy::notification_type type() const;
};
}
#endif // MASTODON_CPP_EASY_NOTIFICATION_HPP

68
src/easy/relationship.cpp Normal file
View File

@ -0,0 +1,68 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "relationship.hpp"
using namespace Mastodon;
using Relationship = Easy::Relationship;
Relationship::Relationship(const string &json)
: Entity(json)
{}
Relationship::Relationship()
: Entity()
{}
const bool Relationship::blocking() const
{
return get_bool("blocking");
}
const bool Relationship::domain_blocking() const
{
return get_bool("domain_blocking");
}
const bool Relationship::followed_by() const
{
return get_bool("followed_by");
}
const bool Relationship::following() const
{
return get_bool("following");
}
const uint_fast64_t Relationship::id() const
{
return std::stoull(get_string("id"));
}
const bool Relationship::muting() const
{
return get_bool("muting");
}
const bool Relationship::muting_notifications() const
{
return get_bool("muting_notifications");
}
const bool Relationship::requested() const
{
return get_bool("requested");
}

97
src/easy/relationship.hpp Normal file
View File

@ -0,0 +1,97 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MASTODON_CPP_EASY_RELATIONSHIP_HPP
#define MASTODON_CPP_EASY_RELATIONSHIP_HPP
#include <string>
#include <cstdint>
// If we are compiling mastodon-cpp, use another include path
#ifdef MASTODON_CPP
#include "mastodon-cpp.hpp"
#include "easy/easy.hpp"
#else
#include <mastodon-cpp/mastodon-cpp.hpp>
#include <mastodon-cpp/easy/easy.hpp>
#endif
using std::string;
using std::uint_fast64_t;
namespace Mastodon
{
/*!
* @brief Class to hold relationships
*/
class Easy::Relationship : public Easy::Entity
{
public:
/*!
* @brief Constructs a Relationship object from a JSON string.
*
* @param json JSON string
*/
explicit Relationship(const string &json);
/*!
* @brief Constructs an empty Relationship object.
*/
Relationship();
/*!
* @brief Returns true if the user is blocking the account
*/
const bool blocking() const;
/*!
* @brief Returns true if the user is blocking the account's domain
*/
const bool domain_blocking() const;
/*!
* @brief Returns true if the user is being followed by the account
*/
const bool followed_by() const;
/*!
* @brief Returns true if the user is being following the account
*/
const bool following() const;
/*!
* @brief Returns the target account ID
*/
const uint_fast64_t id() const;
/*!
* @brief Returns true if the user is muting the account
*/
const bool muting() const;
/*!
* @brief Returns true if the user is also muting notifications
*/
const bool muting_notifications() const;
/*!
* @brief Returns true if the user has requested to follow the account
*/
const bool requested() const;
};
}
#endif // MASTODON_CPP_EASY_RELATIONSHIP_HPP

39
src/easy/report.cpp Normal file
View File

@ -0,0 +1,39 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "report.hpp"
using namespace Mastodon;
using Report = Easy::Report;
Report::Report(const string &json)
: Entity(json)
{}
Report::Report()
: Entity()
{}
const bool Report::action_taken() const
{
return get_bool("action_taken");
}
const uint_fast64_t Report::id() const
{
return std::stoull(get_string("id"));
}

68
src/easy/report.hpp Normal file
View File

@ -0,0 +1,68 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MASTODON_CPP_EASY_REPORT_HPP
#define MASTODON_CPP_EASY_REPORT_HPP
#include <string>
#include <cstdint>
// If we are compiling mastodon-cpp, use another include path
#ifdef MASTODON_CPP
#include "mastodon-cpp.hpp"
#include "easy/easy.hpp"
#else
#include <mastodon-cpp/mastodon-cpp.hpp>
#include <mastodon-cpp/easy/easy.hpp>
#endif
using std::string;
using std::uint_fast64_t;
namespace Mastodon
{
/*!
* @brief Class to hold reports
*/
class Easy::Report : public Easy::Entity
{
public:
/*!
* @brief Constructs a Report object from a JSON string.
*
* @param json JSON string
*/
explicit Report(const string &json);
/*!
* @brief Constructs an empty Report object.
*/
Report();
/*!
* @brief Returns true if an action was taken in response to the
* report
*/
const bool action_taken() const;
/*!
* @brief Returns the ID of the report
*/
const uint_fast64_t id() const;
};
}
#endif // MASTODON_CPP_EASY_REPORT_HPP

69
src/easy/results.cpp Normal file
View File

@ -0,0 +1,69 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <jsoncpp/json/json.h>
#include "results.hpp"
#include "macros.hpp"
using namespace Mastodon;
using Results = Easy::Results;
Results::Results(const string &json)
: Entity(json)
{}
Results::Results()
: Entity()
{}
const std::vector<Easy::Account> Results::accounts() const
{
const Json::Value node = get("accounts");
if (node.isArray())
{
std::vector<Easy::Account> vec;
for (const Json::Value &value : node)
{
vec.push_back(Easy::Account(value.toStyledString()));
}
return vec;
}
ttdebug << "Could not get data: accounts\n";
return {};
}
const std::vector<Easy::Status> Results::statuses() const
{
const Json::Value node = get("statuses");
if (node.isArray())
{
std::vector<Easy::Status> vec;
for (const Json::Value &value : node)
{
vec.push_back(Easy::Status(value.toStyledString()));
}
return vec;
}
ttdebug << "Could not get data: statuses\n";
return {};
}
const std::vector<string> Results::hashtags() const
{
return get_vector("hashtags");
}

75
src/easy/results.hpp Normal file
View File

@ -0,0 +1,75 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MASTODON_CPP_EASY_RESULTS_HPP
#define MASTODON_CPP_EASY_RESULTS_HPP
#include <string>
#include <vector>
// If we are compiling mastodon-cpp, use another include path
#ifdef MASTODON_CPP
#include "mastodon-cpp.hpp"
#include "easy/easy.hpp"
#include "easy/account.hpp"
#include "easy/status.hpp"
#else
#include <mastodon-cpp/mastodon-cpp.hpp>
#include <mastodon-cpp/easy/easy.hpp>
#include <mastodon-cpp/easy/account.hpp>
#include <mastodon-cpp/easy/status.hpp>
#endif
using std::string;
namespace Mastodon
{
/*!
* @brief Class to hold results
*/
class Easy::Results : public Easy::Entity
{
public:
/*!
* @brief Constructs a Results object from a JSON string.
*
* @param json JSON string
*/
explicit Results(const string &json);
/*!
* @brief Constructs an empty Results object.
*/
Results();
/*!
* @brief Returns an array of matched Accounts
*/
const std::vector<Account> accounts() const;
/*!
* @brief Returns an array of matched Statuses
*/
const std::vector<Status> statuses() const;
/*!
* @brief Returns an array of matched hashtags
*/
const std::vector<string> hashtags() const;
};
}
#endif // MASTODON_CPP_EASY_RESULTS_HPP

230
src/easy/status.cpp Normal file
View File

@ -0,0 +1,230 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <jsoncpp/json/json.h>
#include "status.hpp"
#include "macros.hpp"
using namespace Mastodon;
using Status = Easy::Status;
Status::Status(const string &json)
: Entity(json)
{}
Status::Status()
: Entity()
{}
const Easy::Account Status::account() const
{
const Json::Value node = get("account");
if (node.isObject())
{
return Easy::Account(node.toStyledString());
}
ttdebug << "Could not get data: account\n";
return Easy::Account();
}
const Easy::Application Status::application() const
{
const Json::Value node = get("application");
if (node.isObject())
{
return Easy::Application(node.toStyledString());
}
ttdebug << "Could not get data: application\n";
return Easy::Application();
}
const system_clock::time_point Status::created_at() const
{
return get_time_point("created_at");
}
const string Status::content() const
{
return get_string("content");
}
const std::vector<Easy::Emoji> Status::emojis() const
{
const Json::Value node = get("emojis");
if (node.isArray())
{
std::vector<Easy::Emoji> vec;
for (const Json::Value &value : node)
{
vec.push_back(Easy::Emoji(value.toStyledString()));
}
return vec;
}
ttdebug << "Could not get data: emojis\n";
return {};
}
const bool Status::favourited() const
{
return get_bool("favourited");
}
const uint_fast64_t Status::favourites_count() const
{
return get_uint64("favourites_count");
}
const uint_fast64_t Status::id() const
{
return std::stoull(get_string("id"));
}
const uint_fast64_t Status::in_reply_to_id() const
{
return get_uint64("in_reply_to_id");
}
const uint_fast64_t Status::in_reply_to_account_id() const
{
return get_uint64("in_reply_to_account_id");
}
const string Status::language() const
{
return get_string("language");
}
const std::vector<Easy::Attachment> Status::media_attachments() const
{
const Json::Value node = get("media_attachments");
if (node.isArray())
{
std::vector<Easy::Attachment> vec;
for (const Json::Value &value : node)
{
vec.push_back(Easy::Attachment(value.toStyledString()));
}
return vec;
}
ttdebug << "Could not get data: media_attachments\n";
return {};
}
const std::vector<Easy::Mention> Status::mentions() const
{
const Json::Value node = get("mentions");
if (node.isArray())
{
std::vector<Easy::Mention> vec;
for (const Json::Value &value : node)
{
vec.push_back(Easy::Mention(value.toStyledString()));
}
return vec;
}
ttdebug << "Could not get data: mentions\n";
return {};
}
const bool Status::muted() const
{
return get_bool("muted");
}
const bool Status::pinned() const
{
return get_bool("pinned");
}
const Easy::Status Status::reblog() const
{
const Json::Value node = get("reblog");
if (node.isObject())
{
return Easy::Status(node.toStyledString());
}
ttdebug << "Could not get data: reblog\n";
return Easy::Status();
}
const bool Status::reblogged() const
{
return get_bool("reblogged");
}
const uint_fast64_t Status::reblogs_count() const
{
return get_uint64("reblogs_count");
}
const bool Status::sensitive() const
{
return get_bool("sensitive");
}
const string Status::spoiler_text() const
{
return get_string("spoiler_text");
}
const std::vector<Easy::Tag> Status::tags() const
{
const Json::Value node = get("tags");
if (node.isArray())
{
std::vector<Easy::Tag> vec;
for (const Json::Value &value : node)
{
vec.push_back(Easy::Tag(value.toStyledString()));
}
return vec;
}
ttdebug << "Could not get data: tags\n";
return {};
}
const string Status::uri() const
{
return get_string("uri");
}
const string Status::url() const
{
return get_string("url");
}
const Easy::visibility_type Status::visibility() const
{
const string strvisibility = get_string("visibility");
if (strvisibility.compare("public") == 0)
return visibility_type::Public;
else if (strvisibility.compare("unlisted") == 0)
return visibility_type::Unlisted;
else if (strvisibility.compare("private") == 0)
return visibility_type::Private;
else if (strvisibility.compare("direct") == 0)
return visibility_type::Direct;
ttdebug << "Could not get data: visibility\n";
return visibility_type::Undefined;
}

197
src/easy/status.hpp Normal file
View File

@ -0,0 +1,197 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MASTODON_CPP_EASY_STATUS_HPP
#define MASTODON_CPP_EASY_STATUS_HPP
#include <string>
#include <cstdint>
#include <chrono>
#include <vector>
// If we are compiling mastodon-cpp, use another include path
#ifdef MASTODON_CPP
#include "mastodon-cpp.hpp"
#include "easy/easy.hpp"
#include "easy/account.hpp"
#include "easy/emoji.hpp"
#include "easy/attachment.hpp"
#include "easy/mention.hpp"
#include "easy/tag.hpp"
#include "easy/application.hpp"
#else
#include <mastodon-cpp/mastodon-cpp.hpp>
#include <mastodon-cpp/easy/easy.hpp>
#include <mastodon-cpp/easy/account.hpp>
#include <mastodon-cpp/easy/emoji.hpp>
#include <mastodon-cpp/easy/attachment.hpp>
#include <mastodon-cpp/easy/mention.hpp>
#include <mastodon-cpp/easy/tag.hpp>
#include <mastodon-cpp/easy/application.hpp>
#endif
using std::string;
using std::uint_fast64_t;
using std::chrono::system_clock;
namespace Mastodon
{
/*!
* @brief Class to hold statuses
*/
class Easy::Status : public Easy::Entity
{
public:
/*!
* @brief Constructs a Status object from a JSON string.
*
* @param json JSON string
*/
explicit Status(const string &json);
/*!
* @brief Constructs an empty Status object.
*/
Status();
/*!
* @brief Returns an array of matched accounts
*/
const Account account() const;
/*!
* @brief Returns application from which the status was posted
*/
const Application application() const;
/*!
* @brief Returns time of creation
*/
const system_clock::time_point created_at() const;
/*!
* @brief Returns content of status
*/
const string content() const;
/*!
* @brief Returns an array of emojis
*/
const std::vector<Emoji> emojis() const;
/*!
* @brief Returns true if the user has favourited the status
*/
const bool favourited() const;
/*!
* @brief Returns the number of favourites
*/
const uint_fast64_t favourites_count() const;
/*!
* @brief Returns the ID of the status
*/
const uint_fast64_t id() const;
/*!
* @brief Returns the ID of the status it replies to
*/
const uint_fast64_t in_reply_to_id() const;
/*!
* @brief Returns the ID of the account it replies to
*/
const uint_fast64_t in_reply_to_account_id() const;
/*!
* @brief Returns the language of the status
*/
const string language() const;
/*!
* @brief Returns the attachments
*/
const std::vector<Attachment> media_attachments() const;
/*!
* @brief Returns the mentions
*/
const std::vector<Mention> mentions() const;
/*!
* @brief Returns true if the user muted the conversation
*/
const bool muted() const;
/*!
* @brief Returns true if the status is pinned
*/
const bool pinned() const;
/*!
* @brief Returns the reblogged Status
*/
const Status reblog() const;
/*!
* @brief Returns true if the user has reblogged the status
*/
const bool reblogged() const;
/*!
* @brief Returns the number of reblogs for the status
*/
const uint_fast64_t reblogs_count() const;
/*!
* @brief Returns true if the attachments should be hidden by default
*/
const bool sensitive() const;
/*!
* @brief Returns the spoiler text
*/
const string spoiler_text() const;
/*!
* @brief Returns the tags
*/
const std::vector<Tag> tags() const;
/*!
* @brief Returns the Fediverse-unique resource ID
*/
const string uri() const;
/*!
* @brief Returns the URL to the status page
*/
const string url() const;
/*!
* @brief Returns the visibility of the status
*/
const visibility_type visibility() const;
/*!
* @brief Returns the
*/
};
}
#endif // MASTODON_CPP_EASY_STATUS_HPP

38
src/easy/tag.cpp Normal file
View File

@ -0,0 +1,38 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "tag.hpp"
using namespace Mastodon;
using Tag = Easy::Tag;
Tag::Tag(const string &json)
: Entity(json)
{}
Tag::Tag()
: Entity()
{}
const string Tag::name() const
{
return get_string("name");
}
const string Tag::url() const
{
return get_string("url");
}

65
src/easy/tag.hpp Normal file
View File

@ -0,0 +1,65 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MASTODON_CPP_EASY_TAG_HPP
#define MASTODON_CPP_EASY_TAG_HPP
#include <string>
// If we are compiling mastodon-cpp, use another include path
#ifdef MASTODON_CPP
#include "mastodon-cpp.hpp"
#include "easy/easy.hpp"
#else
#include <mastodon-cpp/mastodon-cpp.hpp>
#include <mastodon-cpp/easy/easy.hpp>
#endif
using std::string;
namespace Mastodon
{
/*!
* @brief Class to hold tags.
*/
class Easy::Tag : public Easy::Entity
{
public:
/*!
* @brief Constructs an Tag object from a JSON string.
*
* @param json JSON string
*/
explicit Tag(const string &json);
/*!
* @brief Constructs an empty Tag object.
*/
Tag();
/*!
* @brief Returns the name of the application
*/
const string name() const;
/*!
* @brief Returns the URL of the application
*/
const string url() const;
};
}
#endif // MASTODON_CPP_EASY_TAG_HPP

View File

@ -17,6 +17,7 @@
#ifndef MACROS_HPP
#define MACROS_HPP
#include <iostream>
#ifdef DEBUG
#define ttdebug std::cerr << "[" << __FILE__ << ":" << __LINE__ << "] DEBUG: "
@ -24,5 +25,4 @@
#define ttdebug false && std::cerr
#endif
#endif // MACROS_HPP

View File

@ -37,14 +37,19 @@
* @example example09_streaming_api.cpp
* @example example10_simplify.cpp
* @example example11_post_media.cpp
* @example example12_easy_laststatus.cpp
* @example example13_easy_stream.cpp
*/
namespace Mastodon
{
/*!
* @brief Class for the Mastodon API. All input is expected to be UTF-8.
* Binary data must be base64-encoded or a filename.
*
* @brief Class for the Mastodon API.
*
* All input is expected to be UTF-8. Binary data must be
* base64-encoded or a filename.
* It appears that media attachements can not be base64 encoded.
*
* @section error Error codes
* mastodon-cpp will never use error codes below 11, except 0.
* | Code | Explanation |

View File

@ -1,7 +1,7 @@
/* This file is part of mastodon-cpp.
*/
#include "../mastodon-cpp.hpp"
#include "mastodon-cpp.hpp"
int main(int argc, char *argv[])
{

View File

@ -3,7 +3,7 @@
#include <iostream>
#include <cstdint>
#include "../mastodon-cpp.hpp"
#include "mastodon-cpp.hpp"
int main(int argc, char *argv[])
{

View File

@ -0,0 +1,27 @@
/* This file is part of mastodon-cpp.
*/
#include <iostream>
#include <cstdint>
#include "mastodon-cpp.hpp"
#include "easy/easy.hpp"
#include "easy/status.hpp"
int main(int argc, char *argv[])
{
Mastodon::Easy test("botsin.space", "");
std::string answer;
std::uint16_t ret = test.get(Mastodon::API::v1::timelines_public,
{ { "limit", { "1" } } }, answer);
if (ret == 0)
{
Mastodon::Easy::Status status(answer);
if (status.valid())
{
return 0;
}
}
std::cout << ret << ": " << answer << '\n';
return 1;
}