Dapplo.Confluence
Dapplo.Confluence copied to clipboard
Per 5.7 search
I created this code to be able to search our per 5.7 confluence service
public static class OldSearch
{
public static async Task<Result<Content>> SearchOldAsync(this IContentDomain confluenceClient, string searchValue, CancellationToken cancellationToken = default(CancellationToken))
{
confluenceClient.Behaviour.MakeCurrent();
var searchUri = confluenceClient.ConfluenceUri.AppendSegments("rest", "searchv3", "1.0", "search").ExtendQuery("queryString", searchValue);
var response = await searchUri.GetAsAsync<HttpResponse<Result<Content>, Error>>(cancellationToken).ConfigureAwait(false);
if (response.HasError)
{
throw new Exception(response.ErrorResponse.Message);
}
return response.Response;
}
}
Just thought I'd share :)
Thanks a lot, this is why the whole API was build the way it is... to be able to extend it with relatively little effort.
P.S. With recent changes, you can write it like this (the error / result handling is simplified):
public static class OldSearch
{
public static async Task<Result<Content>> SearchOldAsync(this IContentDomain confluenceClient, string searchValue, CancellationToken cancellationToken = default(CancellationToken))
{
confluenceClient.Behaviour.MakeCurrent();
var searchUri = confluenceClient.ConfluenceUri.AppendSegments("rest", "searchv3", "1.0", "search").ExtendQuery("queryString", searchValue);
var response = await searchUri.GetAsAsync<HttpResponse<Result<Content>, Error>>(cancellationToken).ConfigureAwait(false);
return response.HandleErrors();;
}
}