generated from parthux1/project_preset
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
doc: add installation tutorial, split files
- Loading branch information
Showing
3 changed files
with
125 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters