Skip to content

Commit

Permalink
chore: License | example for listener
Browse files Browse the repository at this point in the history
  • Loading branch information
parthux1 committed Jul 4, 2024
1 parent 0ae20ab commit 23d6190
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 2 deletions.
22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Copyright <YEAR> <COPYRIGHT HOLDER>

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44 changes: 42 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ ntfy API for C++.
Implements partially ntfy functionality stated in https://docs.ntfy.sh/subscribe/api/

- [Examples](#examples)
- [Capabilities](#capabilities)
- [Features](#features)
- [Building with vcpk](#building-with-vcpkg)
- [Documentation](#documentation)
- [Attributions and Licence](#attributions-and-licence)

## Examples

Expand All @@ -25,6 +26,7 @@ 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");
Expand All @@ -34,7 +36,33 @@ const auto msg = ntfy::Message{.content="hello world", .title="Sent from my cpp
server.send(config.topics.at("secret-topic"), msg, config.credentials);
```

## Capabilities
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
- [x] baseauth
Expand Down Expand Up @@ -84,3 +112,15 @@ start doc/out/html/index.html
# linux
open doc/out/html/index.html
```

## Attributions and Licence

- Check out [ntfy](https://github.com/binwiederhier/ntfy).
- This project is not affiliated to ntfy in any way.

ntfy-lib
Copyright (c) 2024, parthux1
All rights reserved.

This source code is licensed under the BSD-style license found in the
LICENSE file in the root directory of this source tree.

0 comments on commit 23d6190

Please sign in to comment.