Skip to content

Commit

Permalink
doc: add installation tutorial, split files
Browse files Browse the repository at this point in the history
  • Loading branch information
parthux1 committed Jul 8, 2024
1 parent 45bf551 commit 72edada
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 69 deletions.
51 changes: 51 additions & 0 deletions doc/source/markdown/examples.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Examples

Sending a message to a topic:

```C++
#include <ntfy-lib/ntfy.hpp>

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 <ntfy-lib/ntfy.hpp>
#include <ntfy-lib/YamlConfiguration.hpp>
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 <iostream>
#include <ntfy-lib/ntfy.hpp>
#include <ntfy-lib/YamlConfiguration.hpp>

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()
```
44 changes: 44 additions & 0 deletions doc/source/markdown/installation.md
Original file line number Diff line number Diff line change
@@ -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 `<proj_root>/ports/`.
2. register port dir for example by creating `<proj_root>/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(<proj> PRIVATE ntfy-lib::ntfy)
```

6. Follow [Examples](#examples)

99 changes: 30 additions & 69 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <ntfy-lib/ntfy.hpp>

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 <ntfy-lib/ntfy.hpp>
#include <ntfy-lib/YamlConfiguration.hpp>
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 <iostream>
#include <ntfy-lib/ntfy.hpp>
#include <ntfy-lib/YamlConfiguration.hpp>

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
Expand All @@ -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/`.

Expand All @@ -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).
Expand Down

0 comments on commit 72edada

Please sign in to comment.