Dapplo.Confluence icon indicating copy to clipboard operation
Dapplo.Confluence copied to clipboard

Per 5.7 search

Open Eonasdan opened this issue 8 years ago • 1 comments

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 :)

Eonasdan avatar Jul 05 '17 21:07 Eonasdan

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();;
        }
    }

Lakritzator avatar Aug 03 '17 06:08 Lakritzator