mirror of
https://github.com/servalproject/serval-dna.git
synced 2024-12-18 20:57:56 +00:00
Add Java API for managing subscriptions
This commit is contained in:
parent
d2dfe71f26
commit
a0dbe115aa
@ -25,6 +25,7 @@ import org.servalproject.servaldna.keyring.KeyringCommon;
|
||||
import org.servalproject.servaldna.keyring.KeyringIdentity;
|
||||
import org.servalproject.servaldna.keyring.KeyringIdentityList;
|
||||
import org.servalproject.servaldna.meshmb.MeshMBCommon;
|
||||
import org.servalproject.servaldna.meshmb.MeshMBSubscriptionList;
|
||||
import org.servalproject.servaldna.meshmb.MessagePlyList;
|
||||
import org.servalproject.servaldna.meshms.MeshMSCommon;
|
||||
import org.servalproject.servaldna.meshms.MeshMSConversationList;
|
||||
@ -204,14 +205,20 @@ public class ServalDClient implements ServalDHttpConnectionFactory {
|
||||
return list;
|
||||
}
|
||||
|
||||
public int meshmbFollow(SigningKey id, SigningKey peer) throws ServalDInterfaceException, IOException {
|
||||
public int meshmbFollow(Subscriber id, SigningKey peer) throws ServalDInterfaceException, IOException {
|
||||
return MeshMBCommon.follow(this, id, peer);
|
||||
}
|
||||
|
||||
public int meshmbIgnore(SigningKey id, SigningKey peer) throws ServalDInterfaceException, IOException {
|
||||
public int meshmbIgnore(Subscriber id, SigningKey peer) throws ServalDInterfaceException, IOException {
|
||||
return MeshMBCommon.ignore(this, id, peer);
|
||||
}
|
||||
|
||||
public MeshMBSubscriptionList meshmbSubscriptions(Subscriber identity) throws IOException, ServalDInterfaceException {
|
||||
MeshMBSubscriptionList list = new MeshMBSubscriptionList(this, identity);
|
||||
list.connect();
|
||||
return list;
|
||||
}
|
||||
|
||||
// interface ServalDHttpConnectionFactory
|
||||
public HttpURLConnection newServalDHttpConnection(String path) throws ServalDInterfaceException, IOException
|
||||
{
|
||||
|
@ -5,6 +5,7 @@ import org.servalproject.servaldna.ServalDClient;
|
||||
import org.servalproject.servaldna.ServalDHttpConnectionFactory;
|
||||
import org.servalproject.servaldna.ServalDInterfaceException;
|
||||
import org.servalproject.servaldna.SigningKey;
|
||||
import org.servalproject.servaldna.Subscriber;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.HttpURLConnection;
|
||||
@ -27,15 +28,15 @@ public class MeshMBCommon {
|
||||
return conn.getResponseCode();
|
||||
}
|
||||
|
||||
public static int ignore(ServalDHttpConnectionFactory connector, SigningKey id, SigningKey peer) throws ServalDInterfaceException, IOException {
|
||||
HttpURLConnection conn = connector.newServalDHttpConnection("/restful/meshmb/" + id.toHex() + "/follow/" + peer.toHex());
|
||||
public static int ignore(ServalDHttpConnectionFactory connector, Subscriber id, SigningKey peer) throws ServalDInterfaceException, IOException {
|
||||
HttpURLConnection conn = connector.newServalDHttpConnection("/restful/meshmb/" + id.signingKey.toHex() + "/follow/" + peer.toHex());
|
||||
conn.setRequestMethod("POST");
|
||||
conn.connect();
|
||||
return conn.getResponseCode();
|
||||
}
|
||||
|
||||
public static int follow(ServalDHttpConnectionFactory connector, SigningKey id, SigningKey peer) throws ServalDInterfaceException, IOException {
|
||||
HttpURLConnection conn = connector.newServalDHttpConnection("/restful/meshmb/" + id.toHex() + "/ignore/" + peer.toHex());
|
||||
public static int follow(ServalDHttpConnectionFactory connector, Subscriber id, SigningKey peer) throws ServalDInterfaceException, IOException {
|
||||
HttpURLConnection conn = connector.newServalDHttpConnection("/restful/meshmb/" + id.signingKey.toHex() + "/ignore/" + peer.toHex());
|
||||
conn.setRequestMethod("POST");
|
||||
conn.connect();
|
||||
return conn.getResponseCode();
|
||||
|
@ -0,0 +1,21 @@
|
||||
package org.servalproject.servaldna.meshmb;
|
||||
|
||||
import org.servalproject.servaldna.BundleId;
|
||||
import org.servalproject.servaldna.SigningKey;
|
||||
|
||||
/**
|
||||
* Created by jeremy on 11/01/17.
|
||||
*/
|
||||
public class MeshMBSubscription {
|
||||
public final SigningKey id;
|
||||
public final String name;
|
||||
public final long timestamp;
|
||||
public final String lastMessage;
|
||||
|
||||
public MeshMBSubscription(SigningKey id, String name, long timestamp, String lastMessage){
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.lastMessage = lastMessage;
|
||||
this.timestamp = timestamp;
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
package org.servalproject.servaldna.meshmb;
|
||||
|
||||
import org.servalproject.json.JSONTableScanner;
|
||||
import org.servalproject.servaldna.AbstractJsonList;
|
||||
import org.servalproject.servaldna.ServalDHttpConnectionFactory;
|
||||
import org.servalproject.servaldna.ServalDInterfaceException;
|
||||
import org.servalproject.servaldna.SigningKey;
|
||||
import org.servalproject.servaldna.Subscriber;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by jeremy on 11/01/17.
|
||||
*/
|
||||
|
||||
public class MeshMBSubscriptionList extends AbstractJsonList<MeshMBSubscription, IOException> {
|
||||
|
||||
public final Subscriber identity;
|
||||
|
||||
public MeshMBSubscriptionList(ServalDHttpConnectionFactory httpConnector, Subscriber identity){
|
||||
super(httpConnector, new JSONTableScanner()
|
||||
.addColumn("id", SigningKey.class)
|
||||
.addColumn("name", String.class)
|
||||
.addColumn("timestamp", Long.class)
|
||||
.addColumn("last_message", String.class)
|
||||
);
|
||||
this.identity = identity;
|
||||
}
|
||||
@Override
|
||||
protected String getUrl() {
|
||||
return "/restful/meshmb/" + identity.signingKey.toHex() + "/feedlist.json";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected MeshMBSubscription factory(Map<String, Object> row, long rowCount) throws ServalDInterfaceException {
|
||||
return new MeshMBSubscription(
|
||||
(SigningKey) row.get("id"),
|
||||
(String) row.get("name"),
|
||||
(Long) row.get("timestamp"),
|
||||
(String) row.get("last_message")
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user