Compare commits

..

No commits in common. "master" and "0.110.0" have entirely different histories.

19 changed files with 76 additions and 371 deletions

View File

@ -25,8 +25,8 @@ steps:
MASTODON_CPP_ACCESS_TOKEN:
from_secret: mastodon_cpp_access_token
commands:
- rm -f /etc/apt/apt.conf.d/docker-clean
- rm -f /var/cache/apt/archives/lock
- rm /etc/apt/apt.conf.d/docker-clean
- rm /var/cache/apt/archives/lock
- apt-get update -q
- apt-get install -qy build-essential cmake
- apt-get install -qy libpoco-dev libjsoncpp-dev doxygen catch
@ -48,8 +48,8 @@ steps:
MASTODON_CPP_ACCESS_TOKEN:
from_secret: mastodon_cpp_access_token
commands:
- rm -f /etc/apt/apt.conf.d/docker-clean
- rm -f /var/cache/apt/archives/lock
- rm /etc/apt/apt.conf.d/docker-clean
- rm /var/cache/apt/archives/lock
- apt-get update -q
- echo "APT::Default-Release \"stretch\";" >> /etc/apt/apt.conf.d/00default_release
- echo "deb http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu xenial main" >> /etc/apt/sources.list.d/ubuntu-toolchain-r.list
@ -77,8 +77,8 @@ steps:
MASTODON_CPP_ACCESS_TOKEN:
from_secret: mastodon_cpp_access_token
commands:
- rm -f /etc/apt/apt.conf.d/docker-clean
- rm -f /var/cache/apt/archives/lock
- rm /etc/apt/apt.conf.d/docker-clean
- rm /var/cache/apt/archives/lock
- apt-get update -q
- echo "APT::Default-Release \"stretch\";" >> /etc/apt/apt.conf.d/00default_release
- echo "deb http://deb.debian.org/debian stretch-backports main" >> /etc/apt/sources.list.d/stretch.list
@ -104,8 +104,8 @@ steps:
MASTODON_CPP_ACCESS_TOKEN:
from_secret: mastodon_cpp_access_token
commands:
- rm -f /etc/apt/apt.conf.d/docker-clean
- rm -f /var/cache/apt/archives/lock
- rm /etc/apt/apt.conf.d/docker-clean
- rm /var/cache/apt/archives/lock
- apt-get update -q
- apt-get update -q
- apt-get install -qy build-essential cmake clang
@ -153,73 +153,34 @@ trigger:
- tag
steps:
- name: Debian stretch
- name: deb
image: debian:stretch-slim
pull: always
environment:
CXXFLAGS: -pipe -O2
LANG: C.utf8
commands:
- rm -f /etc/apt/apt.conf.d/docker-clean
- rm -f /var/cache/apt/archives/lock
- rm /etc/apt/apt.conf.d/docker-clean
- rm /var/cache/apt/archives/lock
- apt-get update -q
- apt-get install -qy build-essential cmake lsb-release
- apt-get install -qy libpoco-dev libjsoncpp-dev file
- apt-get install -qy build-essential cmake
- apt-get install -qy libpoco-dev libjsoncpp-dev doxygen file
- rm -rf build && mkdir -p build && cd build
- cmake -DWITH_DEB=YES -DWITH_DOC=NO ..
- cmake -DWITH_EXAMPLES=NO -DWITH_TESTS=NO ..
- make package
- cp -v libmastodon-cpp_${DRONE_TAG}-0_stretch_amd64.deb ..
- cmake -DWITH_DEB=YES ..
- make package
- cp -v mastodon-cpp-${DRONE_TAG}_x86_64.tar.gz ..
- cp -v libmastodon-cpp_${DRONE_TAG}-0_amd64.deb ..
volumes:
- name: debian-package-cache
path: /var/cache/apt/archives
- name: Debian buster
image: debian:buster-slim
pull: always
environment:
CXXFLAGS: -pipe -O2
LANG: C.utf8
commands:
- rm -f /etc/apt/apt.conf.d/docker-clean
- rm -f /var/cache/apt/archives/lock
- apt-get update -q
- apt-get install -qy build-essential cmake lsb-release
- apt-get install -qy libpoco-dev libjsoncpp-dev file
- rm -rf build && mkdir -p build && cd build
- cmake -DWITH_DEB=YES -DWITH_DOC=NO ..
- make package
- cp -v libmastodon-cpp_${DRONE_TAG}-0_buster_amd64.deb ..
volumes:
- name: debian-package-cache
path: /var/cache/apt/archives
- name: Ubuntu bionic
image: ubuntu:bionic
pull: always
environment:
CXXFLAGS: -pipe -O2
LANG: C.utf8
commands:
- rm -f /etc/apt/apt.conf.d/docker-clean
- rm -f /var/cache/apt/archives/lock
- apt-get update -q
- apt-get install -qy build-essential cmake lsb-release
- apt-get install -qy libpoco-dev libjsoncpp-dev file
- rm -rf build && mkdir -p build && cd build
- cmake -DWITH_DEB=YES -DWITH_DOC=NO ..
- make package
- cp -v libmastodon-cpp_${DRONE_TAG}-0_bionic_amd64.deb ..
volumes:
- name: debian-package-cache
path: /var/cache/apt/archives
- name: CentOS 7
- name: rpm
image: centos:7
pull: always
environment:
CXX: /opt/rh/devtoolset-6/root/usr/bin/g++
CXXFLAGS: -pipe -O2
LANG: C.utf8
commands:
- sed -i 's/keepcache=0/keepcache=1/' /etc/yum.conf
- curl -s -o /var/cache/yum/epel-release-latest-7.noarch.rpm http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
@ -230,7 +191,9 @@ steps:
- yum install -qy poco-devel openssl-devel doxygen rpm-build
- yum --enablerepo=epel install -qy cmake3 jsoncpp-devel
- rm -rf build && mkdir -p build && cd build
- cmake3 -DWITH_RPM=YES -DWITH_DOC=NO ..
- cmake3 -DWITH_EXAMPLES=NO -DWITH_TESTS=NO ..
- make package
- cmake3 -DWITH_RPM=YES ..
- make package
- cp -v libmastodon-cpp-${DRONE_TAG}-0.x86_64.rpm ..
volumes:
@ -247,9 +210,8 @@ steps:
title: ${DRONE_TAG}
prerelease: true
files:
- libmastodon-cpp_${DRONE_TAG}-0_stretch_amd64.deb
- libmastodon-cpp_${DRONE_TAG}-0_buster_amd64.deb
- libmastodon-cpp_${DRONE_TAG}-0_bionic_amd64.deb
- mastodon-cpp-${DRONE_TAG}_x86_64.tar.gz
- libmastodon-cpp_${DRONE_TAG}-0_amd64.deb
- libmastodon-cpp-${DRONE_TAG}-0.x86_64.rpm
checksum:
- sha256

View File

@ -1,20 +0,0 @@
# Configuration file for EditorConfig.
# More information is available under <https://editorconfig.org/>.
root = true
[*]
indent_style = space
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
max_line_length = 80
[*.?pp]
indent_size = 4
tab_width = 4
[{CMakeLists.txt,*.cmake}]
indent_size = 2
tab_width = 2

View File

@ -9,7 +9,7 @@ endif()
include(GNUInstallDirs)
project (mastodon-cpp
VERSION 0.111.5
VERSION 0.110.0
LANGUAGES CXX)
# DESCRIPTION was introduced in version 3.9.
@ -77,7 +77,7 @@ if(WITH_DOC)
add_dependencies(${PROJECT_NAME} doc)
install(DIRECTORY ${PROJECT_SOURCE_DIR}/doc/html
DESTINATION "${CMAKE_INSTALL_DOCDIR}/${PROJECT_NAME}")
DESTINATION "${CMAKE_INSTALL_DOCDIR}")
endif()
add_subdirectory("cmake")

View File

@ -1,49 +0,0 @@
:contact-coc: tastytea@tastytea.de
== Code of Conduct
In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, education, ethnicity, gender identity and expression, level of
experience, nationality, personal appearance, race, religion, sex
characteristics, sexual identity and orientation or socio-economic status.
=== Examples
Examples of behavior that contributes to creating a positive environment
include:
* Using welcoming and inclusive language.
* Being respectful of differing viewpoints and experiences.
* Gracefully accepting constructive criticism.
* Focusing on what is best for the community.
* Showing empathy towards other community members.
Examples of unacceptable behavior by participants include:
* The use of sexualized language or imagery and unwelcome sexual attention or
advances.
* Trolling, insulting/derogatory comments, and personal attacks.
* Public or private harassment.
* Publishing others private information, such as a physical or electronic
address, without explicit permission.
=== Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at {contact-coc}.
All complaints will be reviewed and investigated and will result in a response
that is deemed necessary and appropriate to the circumstances. The project team
is obligated to maintain confidentiality with regard to the reporter of an
incident.
=== Attribution
This Code of Conduct is adapted from the Contributor Covenant, version 1.4,
available at
https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
For answers to common questions about this code of conduct, see
https://www.contributor-covenant.org/faq

View File

@ -1,29 +0,0 @@
:project: mastodon-cpp
:uri-base: https://schlomp.space/tastytea/{project}
:uri-coc: {uri-base}/src/branch/master/CODE_OF_CONDUCT.adoc
:contact-email: tastytea@tastytea.de
:contact-xmpp: {contact-email}
:contact-fediverse: https://likeable.space/users/tastytea
== How to contribute
Read the link:{uri-coc}[Code of Conduct].
=== Reporting bugs or suggesting enhancements
Before reporting a bug, please
https://schlomp.space/tastytea/{project}/issues[perform a search] to see if the
problem has already been reported. If it has, add a comment to the existing
issue instead of opening a new one. Same for enhancements.
You can also contact me via mailto:{contact-email}[E-Mail],
link:xmpp:{contact-xmpp}[XMPP] or the {contact-fediverse}[Fediverse] if you
don't want to open an account.
=== Pull requests
Please use similar coding conventions as the rest of the project. The basic rule
to remember is to write code in the same style as the existing/surrounding code.
You can also send me your patches via mailto:{contact-email}[E-Mail], ideally
using `git format-patch` or `git send-email`.

16
CONTRIBUTING.md Normal file
View File

@ -0,0 +1,16 @@
# How to contribute
## Reporting bugs or suggesting enhancements
Before reporting a bug , please
[perform a search](https://schlomp.space/tastytea/mastodon-cpp/issues)
to see if the problem has already been reported. If it has, add a comment to the
existing issue instead of opening a new one. Same for enhancements.
You can also contact me via the Fediverse if you don't want to open an account.
My account is [@tastytea@likeable.space](https://likeable.space/users/tastytea).
## Pull requests
Please use similar coding conventions as the rest of the project. The basic rule
to remember is to write code in the same style as the existing/surrounding code.

View File

@ -1,27 +1,17 @@
= mastodon-cpp
:toc: preamble
:project: mastodon-cpp
:uri-base: https://schlomp.space/tastytea/{project}
:uri-branch-main: {uri-base}/src/branch/master
:uri-mastodonpp: https://schlomp.space/tastytea/mastodonpp
[IMPORTANT]
This project has become too complicated to maintain by myself and I can't find
the energy to add features. **You can find a complete rewrite, with cleaner and
much easier to understand code at link:{uri-mastodonpp}[mastodonpp].** I
recommend switching to it. You can still report bugs here and I will respond,
but I won't put too much work in it. If you want to take over maintainership,
get in touch.
*{project}* is a C++ wrapper for the Mastodon API. You submit an API call
and get the raw JSON that you can then transform into easy to use abstractions.
*mastodon-cpp* is a C++ wrapper for the Mastodon API. You submit an API call
and get the raw JSON or easy to use abstractions.
== Usage
The HTML reference can be generated with `build_doc.sh`, if doxygen is
installed. It is also available at
https://doc.schlomp.space/{project}/annotated.html[doc.schlomp.space/{project}/].
There are more {uri-branch-main}/examples[examples] in `examples/`.
https://doc.schlomp.space/mastodon-cpp/annotated.html[doc.schlomp.space/mastodon-cpp/].
There are more
https://schlomp.space/tastytea/mastodon-cpp/src/branch/master/examples[examples]
in `examples/`.
=== Examples
@ -86,6 +76,10 @@ Not included in this list are entities.
==== Return types
* `Mastodon::return_call`: Contains the response from `Mastodon::API` calls.
* `Mastodon::Easy::return_entity`: Contains the response from high-level
functions that return a single `Mastodon::Easy::Entity`.
* `Mastodon::Easy::return_entities_vector`: Contains the response from
high-level functions that return multiple `Mastodon::Easy::Entity`.
==== Other types
@ -138,11 +132,14 @@ If you use a debug build, you get more verbose error messages.
=== Upgrading from versions below 0.100.0
Starting with version `0.100.0`, large parts of the library have been rewritten.
Upgrading from previous versions will require extensive code changes.
Upgrading from previous versions will require extensive code changes. You can
keep using the old version, it is archived in the branch
https://schlomp.space/tastytea/mastodon-cpp/src/branch/pre-0.100.0[pre-0.100.0].
It will receive bug-fixes for a while but no new features.
=== Packages
Every https://schlomp.space/tastytea/{project}/releases[release] includes
Every https://schlomp.space/tastytea/mastodon-cpp/releases[release] includes
packages for Debian and Centos. Gentoo packages are available in my overlay.
==== Gentoo
@ -194,7 +191,7 @@ apt-get install build-essential cmake libpoco-dev libjsoncpp-dev doxygen
===== Release
Download the current release at
https://schlomp.space/tastytea/{project}/releases[schlomp.space].
https://schlomp.space/tastytea/mastodon-cpp/releases[schlomp.space].
===== Development version
@ -259,8 +256,6 @@ the filter ID with `MASTODON_CPP_FILTER_ID`. You can select the list ID with
* Have at least 1 list with at least one account in it.
* have at least 1 account muted.
include::{uri-base}/raw/branch/master/CONTRIBUTING.adoc[]
== Status of implementation
You can still use unsupported calls by using `API::get` and the others with

View File

@ -1,7 +1,7 @@
include(CMakeFindDependencyMacro)
include(GNUInstallDirs)
find_dependency(jsoncpp CONFIG REQUIRED)
find_depencency(jsoncpp CONFIG REQUIRED)
find_package(Poco COMPONENTS Foundation Net NetSSL CONFIG REQUIRED)
include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake")

View File

@ -26,11 +26,8 @@ if (WITH_DEB)
execute_process(COMMAND dpkg --print-architecture
OUTPUT_VARIABLE CPACK_DEBIAN_PACKAGE_ARCHITECTURE
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND lsb_release --codename --short
OUTPUT_VARIABLE DEBIAN_CODENAME
OUTPUT_STRIP_TRAILING_WHITESPACE)
set(CPACK_PACKAGE_FILE_NAME
"${CPACK_PACKAGE_NAME}_${CPACK_PACKAGE_VERSION}-0_${DEBIAN_CODENAME}_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}")
"${CPACK_PACKAGE_NAME}_${CPACK_PACKAGE_VERSION}-0_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}")
endif()
if (WITH_RPM)

View File

@ -7,5 +7,5 @@ endforeach()
if(WITH_DOC)
install(FILES ${sources_examples}
DESTINATION "${CMAKE_INSTALL_DOCDIR}/${PROJECT_NAME}/examples")
DESTINATION "${CMAKE_INSTALL_DOCDIR}/examples")
endif()

View File

@ -1,91 +0,0 @@
// This file is part of mastodon-cpp.
// Get 2 pages of 5 favourites each.
// Don't compile this if the Easy-interface is turned off
#ifndef WITHOUT_EASY
#include <iostream>
#include <string>
#include <vector>
#include "mastodon-cpp.hpp"
#include "easy/all.hpp"
using std::cout;
using std::cerr;
using std::endl;
using std::string;
using std::vector;
using namespace Mastodon;
void print_favs(Easy::API &masto, const string &max_id = "")
{
// Set up parameters.
Mastodon::parameters params =
{
{ "limit", { "5" } },
{ "exclude_types", { "follow", "reblog", "mention" } }
};
// Set max_id if given.
if (!max_id.empty())
{
params.push_back({ "max_id", { max_id } });
}
// Retrieve the last 5 favourites.
return_call ret = masto.get(API::v1::notifications, params);
// If no error was returned.
if (ret)
{
// Convert answer to vector of strings, loop through vector.
for (const string &str : Easy::json_array_to_vector(ret.answer))
{
// Construct Mastodon::Easy::Notification from string.
const Easy::Notification notif(str);
cout << notif.created_at().strtime("%F %T: ");
cout << notif.account().display_name() << " favourited a status.\n";
}
}
else
{
// Print error message.
cerr << ret.error_message << endl;
// Print HTTP status code, if there is one.
if (ret.http_error_code != 0)
{
cerr << "HTTP status code: "
<< std::to_string(ret.http_error_code) << endl;
}
}
}
int main(int argc, char *argv[])
{
const vector<string> args(argv, argv + argc);
if (args.size() < 3)
{
std::cerr << "usage: " << args[0] << " <instance> <auth token>\n";
return 1;
}
// Construct a Mastodon::Easy object.
Easy::API masto(args[1], args[2]);
print_favs(masto);
cout << "\nLink header is: " << masto.get_header("link") << "\n\n";
// Get the max_id for pagination.
// See <https://docs.joinmastodon.org/api/rest/notifications/#pagination>
print_favs(masto, masto.get_link().max_id());
// The same: print_favs(masto, masto.get_link().next());
return 0;
}
#else
#include <iostream>
int main()
{
std::cout << "mastodon-cpp was compiled without Easy support.\n";
return 255;
}
#endif // WITHOUT_EASY

View File

@ -1,48 +0,0 @@
// This file is part of mastodon-cpp.
// Prints shortcode + URL for each custom emoji.
// Don't compile this if the Easy-interface is turned off
#ifndef WITHOUT_EASY
#include <iostream>
#include <string>
#include <vector>
#include "mastodon-cpp.hpp"
#include "easy/all.hpp"
using std::string;
using std::vector;
using namespace Mastodon;
int main(int argc, char *argv[])
{
const vector<string> args(argv, argv + argc);
if (args.size() < 2)
{
std::cerr << "usage: " << args[0] << " <instance>\n";
return 1;
}
// Construct a Mastodon::Easy object.
Easy::API masto(args[1], "");
const return_call ret = masto.get(API::v1::custom_emojis);
// Convert JSON array into vector of strings.
for (const string &str : Easy::json_array_to_vector(ret))
{
// Construct Emoji object from string.
const Easy::Emoji emoji(str);
std::cout << ':' << emoji.shortcode() << ": <" << emoji.url() << ">\n";
}
return 0;
}
#else
#include <iostream>
int main()
{
std::cout << "mastodon-cpp was compiled without Easy support.\n";
return 255;
}
#endif // WITHOUT_EASY

View File

@ -56,7 +56,7 @@ endif()
install(TARGETS ${PROJECT_NAME}
EXPORT "${PROJECT_NAME}Targets"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}")
install(FILES mastodon-cpp.hpp return_types.hpp types.hpp

View File

@ -101,8 +101,8 @@ Easy::Link::Link(const string &link_header)
: _next()
, _prev()
{
std::regex renext("max_id=([[:alnum:]]*)");
std::regex reprev("(?:since|min)_id=([[:alnum:]]*)");
std::regex renext("max_id=([[:digit:]]*)");
std::regex reprev("since_id=([[:digit:]]*)");
std::smatch match;
if (std::regex_search(link_header, match, renext))
@ -134,8 +134,3 @@ const string Easy::Link::since_id() const
{
return _prev;
}
const string Easy::Link::min_id() const
{
return _prev;
}

View File

@ -89,13 +89,6 @@ namespace Easy
*/
const string since_id() const;
/*!
* @brief Returns min_id.
*
* @since 0.111.0
*/
const string min_id() const;
private:
string _next;
string _prev;
@ -167,7 +160,6 @@ namespace Easy
*
* @since 0.100.0
*/
[[deprecated("Will go away in 1.0.0 with no replacement.")]]
const return_entity<Easy::Status> send_post(const Status &status);
/*!
@ -175,7 +167,6 @@ namespace Easy
*
* @since 0.100.0
*/
[[deprecated("Will go away in 1.0.0 with no replacement.")]]
const return_entity<Easy::Status> send_toot(const Status &status);
/*!
@ -189,7 +180,6 @@ namespace Easy
*
* @since 0.100.0
*/
[[deprecated("Will go away in 1.0.0 with no replacement.")]]
const return_entity_vector<Easy::Notification> get_notifications(
const uint16_t limit = 20, const string since_id = "",
const string max_id = "");

View File

@ -36,9 +36,8 @@ namespace Easy
*
* @since 0.100.0
*/
template <typename T> struct
[[deprecated("Will go away in 1.0.0 with no replacement.")]]
return_entity : return_base
template <typename T>
struct return_entity : return_base
{
/*!
* @brief Mastodon::Easy::Entity
@ -108,9 +107,8 @@ namespace Easy
*
* @since 0.100.0
*/
template <typename T> struct
[[deprecated("Will go away in 1.0.0 with no replacement.")]]
return_entity_vector : return_base
template <typename T>
struct return_entity_vector : return_base
{
/*!
* @brief std::vector of Mastodon::Easy::Entity.

View File

@ -234,17 +234,13 @@ return_call API::http::request_common(const http_method &meth,
}
HTTPResponse response;
istream &body_stream = session.receiveResponse(response);
istream &rs = session.receiveResponse(response);
const uint16_t http_code = response.getStatus();
ttdebug << "Response code: " << http_code << '\n';
answer.clear();
StreamCopier::copyToString(body_stream, answer);
std::ostringstream headers_stream;
response.write(headers_stream);
_headers = headers_stream.str();
StreamCopier::copyToString(rs, answer);
switch (http_code)
{
@ -347,6 +343,7 @@ return_call API::http::request_common(const http_method &meth,
}
}
// FIXME: get_headers() doesn't work anymore.
void API::http::get_headers(string &headers) const
{
headers = _headers;

View File

@ -20,7 +20,6 @@
#include <utility>
#include <iostream>
#include <exception>
#include <algorithm>
#include <Poco/Net/FilePartSource.h>
#include <Poco/URI.h>
#include "version.hpp"
@ -266,18 +265,11 @@ return_call API::register_app2(const string &client_id,
return ret;
}
const string API::get_header(std::string header) const
const string API::get_header(const std::string &header) const
{
string headers;
string headers_lower;
_http.get_headers(headers);
headers_lower.resize(headers.size());
std::transform(headers.begin(), headers.end(),
headers_lower.begin(), ::tolower);
std::transform(header.begin(), header.end(), header.begin(), ::tolower);
size_t startpos = headers_lower.find(header + ':');
size_t startpos = headers.find(header + ':');
if (startpos != std::string::npos)
{
startpos = headers.find(':', startpos) + 2;
@ -315,7 +307,7 @@ const parameters API::delete_params(const parameters &params,
std::copy_if(params.begin(), params.end(), newparams.begin(),
[&keys](const param &p)
{
return std::all_of(keys.begin(), keys.end(),
return std::any_of(keys.begin(), keys.end(),
[&p](const string &k)
{
return (k != p.key);

View File

@ -411,7 +411,7 @@ namespace Mastodon
string &access_token);
/*!
* @brief Gets the header from the last answer. Case insensitive.
* @brief Gets the header from the last answer.
*
* @param header The header to get
*
@ -419,7 +419,7 @@ namespace Mastodon
*
* @since before 0.11.0
*/
const string get_header(string header) const;
const string get_header(const string &header) const;
/*!
* @brief Turn exceptions on or off. Defaults to off.