[message pusher] - standlone gin service

This commit is contained in:
zeaslity
2024-04-23 11:45:32 +08:00
parent 30d83f3c61
commit 16541183ef
41 changed files with 1481 additions and 133 deletions

View File

@@ -0,0 +1,40 @@
package io.wdd.pusher.example;
import io.wdd.pusher.NtfyClient;
import io.wdd.pusher.core.exception.NtfyException;
import io.wdd.pusher.core.model.*;
import io.wdd.pusher.core.publish.PubClient;
import java.util.ArrayList;
import java.util.List;
public class PublishExample {
public static void main(String[] args) throws NtfyException {
PubClient client = new NtfyClient(ClientType.PUB).getClient();
NtfyRequest request = new NtfyRequest();
request.setTopic("test_ntfy2");
request.setMessage("Look ma, **bold text**, *italics*, ...");
request.setTitle("This is the obj msg");
request.setPriority(PRIORITY.MAX);
request.setAttach("https://media.licdn.com/dms/image/D4E03AQEZTNXuX3kG7g/profile-displayphoto-shrink_400_400/0/1669618932666?e=1699488000&v=beta&t=q2z_UDFvwTZa02SligKZqgwk66BjuXQZxWtQF_K1Jqw");
request.setFileName("Screenshot.png");
request.setIcon("https://styles.redditmedia.com/t5_32uhe/styles/communityIcon_xnt6chtnr2j21.png");
request.setEmail("mahesh.b.pec@gmail.com");
request.setPhone("");
Action action = new Action();
action.setAction(ACTIONS.VIEW);
action.setLabel("Open github");
action.setUrl("https://github.com/MaheshBabu11/ntfy-java");
action.setClear(true);
List<Action> actions = new ArrayList<>(List.of(action));
List<String> tags = new ArrayList<>(List.of("+1", "warning"));
request.setTags(tags);
request.setMarkdown(true);
request.setActions(actions);
client.sendNotification(request);
}
}

View File

@@ -0,0 +1,27 @@
package io.wdd.pusher.example;
import io.wdd.pusher.core.exception.NtfyStreamingException;
import io.wdd.pusher.core.model.StreamRequest;
import io.wdd.pusher.core.stream.StreamingService;
public class StreamingExample {
public static void main(String[] args) throws NtfyStreamingException {
StreamRequest request = new StreamRequest();
request.setHost("ntfy.sh");
request.setTopic("test_ntfy2");
StreamingService streamingConnection = new StreamingService(request);
streamingConnection.setDataListener(data -> {
// Process the incoming data here
System.out.println("Received data: " + data);
});
// Start the streaming connection
streamingConnection.start();
// Keep the connection open and receive data indefinitely
// To stop the connection, call streamingConnection.stop()
}
}