Skip to content
Snippets Groups Projects
Commit d94a49d8 authored by Harpo Roeder's avatar Harpo Roeder
Browse files

update getQueryIndex and add getQueryLatest

parent 1ae73f5a
No related branches found
No related tags found
1 merge request!2Query Index Changes
......@@ -77,15 +77,15 @@ class ApiMethods {
return Protocol.Events.parseFrom(result.get())
}
fun getQueryIndex(server: String, system: Protocol.PublicKey, eventTypes: List<Long>, limit: Int? = null): Protocol.Events {
fun getQueryIndex(server: String, system: Protocol.PublicKey, contentType: Long, after: Int? = null, limit: Int? = null): Protocol.QueryIndexResponse {
val systemQuery = system.toByteArray().toBase64Url()
val eventTypesQuery = Protocol.RepeatedUInt64.newBuilder()
.addAllNumbers(eventTypes).build().toByteArray().toBase64Url()
val path = if (limit != null) {
"/query_index?system=$systemQuery&event_types=$eventTypesQuery&limit=$limit"
val path = if (after != null && limit != null) {
"/query_index?system=$systemQuery&content_type=$contentType&after=$after&limit=$limit"
} else if (limit != null) {
"/query_index?system=$systemQuery&content_type=$contentType&limit=$limit"
} else {
"/query_index?system=$systemQuery&event_types=$eventTypesQuery"
"/query_index?system=$systemQuery&content_type=$contentType"
}
val (_, response, result) = "$server$path".httpGet()
.header(Headers.CONTENT_TYPE, "application/octet-stream")
......@@ -96,6 +96,25 @@ class ApiMethods {
throw Exception(formattedMessage)
}
return Protocol.QueryIndexResponse.parseFrom(result.get())
}
fun getQueryLatest(server: String, system: Protocol.PublicKey, eventTypes: List<Long>): Protocol.Events {
val systemQuery = system.toByteArray().toBase64Url()
val eventTypesQuery = Protocol.RepeatedUInt64.newBuilder()
.addAllNumbers(eventTypes).build().toByteArray().toBase64Url()
val path = "/query_latest?system=$systemQuery&event_types=$eventTypesQuery";
val (_, response, result) = "$server$path".httpGet()
.header(Headers.CONTENT_TYPE, "application/octet-stream")
.response()
if (!response.isSuccessful) {
val formattedMessage = "getQueryLatest to $server failed with status code ${response.statusCode}. Response body: ${response.body().toByteArray().decodeToString()}"
throw Exception(formattedMessage)
}
return Protocol.Events.parseFrom(result.get())
}
......@@ -125,4 +144,4 @@ class ApiMethods {
return Protocol.QueryReferencesResponse.parseFrom(result.get())
}
}
}
\ No newline at end of file
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment