diff --git a/doc/source/markdown/examples.md b/doc/source/markdown/examples.md new file mode 100644 index 0000000..5c5c2d6 --- /dev/null +++ b/doc/source/markdown/examples.md @@ -0,0 +1,51 @@ +# Examples + +Sending a message to a topic: + +```C++ +#include + +auto server = ntfy::Server{"https://example-url.com"}; +const auto msg = ntfy::Message{.content="hello world", .title="Sent from my cpp program"}; + +server.send("mytopic", msg); +``` + +Load an external configuration to hide information + +```C++ +#include +#include + +const auto config = ntfy::YamlConfiguration::from_file("example.ntfy.config"); + +auto server = ntfy::Server{config.server_url}; +const auto msg = ntfy::Message{.content="hello world", .title="Sent from my cpp program"}; + +server.send(config.topics.at("secret-topic"), msg, config.credentials); +``` + +Listen for messages in a topic + +```C++ +#include +#include +#include + +const auto config = ntfy::YamlConfiguration::from_file("example.ntfy.config"); +auto server = ntfy::Server{config.server_url}; + +auto listener = server.listen_to(config.topics.at("test"), config.credentials); +listener.add_handler("print_msg", + [](const ntfy::Message m) { + std::cout << m.str() << std::endl; + }); +listener.start(); +// block main thread so listener is not destroyed +std::string input{}; +while (input != "stop") { + std::cout << "> "; + std::cin >> input; +} +listener.stop() +``` \ No newline at end of file diff --git a/doc/source/markdown/installation.md b/doc/source/markdown/installation.md new file mode 100644 index 0000000..edfc78e --- /dev/null +++ b/doc/source/markdown/installation.md @@ -0,0 +1,44 @@ +# Installation + +## using vcpkg + +Currently only installation using custom a GitHub repo port ist implemented: See for relevant files. +You may need to update `SHA512` in [`portfile.cmake`](./port/portfile.cmake). + +### Tutorial for manifest mode + +1. Save files in [`port/`](./port) to your local disk, for example `/ports/`. +2. register port dir for example by creating `/vcpkg-configuration.json`: + +```json +{ + "overlay-ports": [ + "./ports" + ] +} +``` + +3. include this project in your `vcpkg.json`: + +```json +{ + "name": "ntfy-lib", + "version>=": "1.0.0" +} +``` + +4. install using + +```bash +vcpkg install +``` + +5. include lib in your `CmakeLists.txt` + +```cmake +find_package(ntfy-lib) +target_link_libraries( PRIVATE ntfy-lib::ntfy) +``` + +6. Follow [Examples](#examples) + diff --git a/readme.md b/readme.md index becb1cb..98c699c 100644 --- a/readme.md +++ b/readme.md @@ -3,65 +3,13 @@ Third party ntfy API for C++. Partial implementation of ntfy functionality as stated in https://docs.ntfy.sh/subscribe/api/ -- [Examples](#examples) - [Features](#features) -- [Building with vcpk](#building-with-vcpkg) +- [Examples](#examples) +- [Installation](#installation) - [Documentation](#documentation) +- [Development](#development) - [Attributions and Licence](#attributions-and-licence) -## Examples - -Sending a message to a topic: - -```C++ -#include - -auto server = ntfy::Server{"https://example-url.com"}; -const auto msg = ntfy::Message{.content="hello world", .title="Sent from my cpp program"}; - -server.send("mytopic", msg); -``` - -Load an external configuration to hide information - -```C++ -#include -#include - -const auto config = ntfy::YamlConfiguration::from_file("example.ntfy.config"); - -auto server = ntfy::Server{config.server_url}; -const auto msg = ntfy::Message{.content="hello world", .title="Sent from my cpp program"}; - -server.send(config.topics.at("secret-topic"), msg, config.credentials); -``` - -Listen for messages in a topic - -```C++ -#include -#include -#include - -const auto config = ntfy::YamlConfiguration::from_file("example.ntfy.config"); -auto server = ntfy::Server{config.server_url}; - -auto listener = server.listen_to(config.topics.at("test"), config.credentials); -listener.add_handler("print_msg", - [](const ntfy::Message m) { - std::cout << m.str() << std::endl; - }); -listener.start(); -// block main thread so listener is not destroyed -std::string input{}; -while (input != "stop") { - std::cout << "> "; - std::cin >> input; -} -listener.stop() - -``` - ## Features - login to ntfy server @@ -79,26 +27,18 @@ listener.stop() - [ ] UTF8 support - [ ] scheduled delivery -## Building with vcpkg +## Examples -- clone with submodules to get vcpkg -- run bootstrap and install dependencies +Code snippets can be found in [this markdown](doc/source/markdown/examples.md). -```bash -# run in project root or install dependecies by yourself from vcpkg.json -sh ./scripts/vcpkg_setup.sh -``` +## Installation -Toolchain-File of Vcpkg is included in the CMakeLists.txt. -Build the library by running cmake or by running: - -```bash -# run in project root -sh ./scripts/build.sh -``` +See [this markdown](doc/source/markdown/installation.md). ## Documentation +Statically included markdown files can be found in [`doc/source/markdown`](doc/source/markdown). + You can generate a documentation by using doxygen. Documentation will be written to `doc/out/`. @@ -113,6 +53,27 @@ start doc/out/html/index.html open doc/out/html/index.html ``` +## Development + +### Building with vcpkg + +- clone with submodules to get vcpkg +- run bootstrap and install dependencies + +```bash +# run in project root or install dependecies by yourself from vcpkg.json +sh ./scripts/vcpkg_setup.sh +``` + +Toolchain-File of vcpkg is included in the CMakeLists.txt. If you don`t want to install vcpkg within this repository +adjust the path accordingly. +Build the library by running cmake or by running: + +```bash +# run in project root +sh ./scripts/build.sh +``` + ## Attributions and Licence - Check out [ntfy](https://github.com/binwiederhier/ntfy).