public async Task UpsertUserAsync(User user, UpsertUserOptions?options = null) { options ??= UpsertUserOptions.Default; var uri = GetUsersUri(options.DomainNameValue, user.Username); _logger.LogInformation($"Attempting to create user with username {user.Username} - {uri}"); try { // upsert user var content = new FormUrlEncodedContent(GetUserFormValues(user)); var result = await _client.PutAsync(uri, content, options.TokenValue).ConfigureAwait(false); result.EnsureSuccessStatusCode(); } catch (Exception exception) { _logger.LogError(exception, $"Error trying to upsert user - {uri}"); throw; } }
public async Task UpsertDesignDocumentAsync(DesignDocument designDocument, DesignDocumentNamespace @namespace, UpsertDesignDocumentOptions?options = null) { options ??= UpsertDesignDocumentOptions.Default; var json = JsonConvert.SerializeObject(designDocument); var uri = GetUri(designDocument.Name, @namespace); _logger.LogInformation($"Attempting to upsert design document {_bucketName}/{designDocument.Name} - {uri}"); _logger.LogDebug(json); try { var content = new StringContent(json, Encoding.UTF8, MediaType.Json); var result = await _client.PutAsync(uri, content, options.TokenValue).ConfigureAwait(false); result.EnsureSuccessStatusCode(); } catch (Exception exception) { _logger.LogError(exception, $"Failed to upsert design document {_bucketName}/{designDocument.Name} - {uri} - {json}"); throw; } }
public async Task UpsertIndexAsync(SearchIndex indexDefinition, UpsertSearchIndexOptions?options = null) { options ??= UpsertSearchIndexOptions.Default; var baseUri = GetIndexUri(indexDefinition.Name); _logger.LogInformation($"Trying to upsert index with name {indexDefinition.Name} - {baseUri}"); try { var json = JsonConvert.SerializeObject(indexDefinition, Formatting.None); var content = new StringContent(json, Encoding.UTF8, MediaType.Json); var result = await _client.PutAsync(baseUri, content, options.TokenValue).ConfigureAwait(false); result.EnsureSuccessStatusCode(); } catch (Exception exception) { _logger.LogError(exception, $"Failed to upsert index with name {indexDefinition.Name} - {baseUri}"); throw; } }
public async Task ReplaceLinkAsync(AnalyticsLink link, ReplaceAnalyticsLinkOptions?options = null) { link.ValidateForRequest(); options ??= new(); try { var builder = new UriBuilder(_serviceUriProvider.GetRandomAnalyticsUri()); builder.Path = link.ManagementPath; var uri = builder.Uri; var formContent = new FormUrlEncodedContent(link.FormData); var result = await _couchbaseHttpClient.PutAsync(uri, formContent, options.CancellationToken).ConfigureAwait(false); var responseBody = await result.Content.ReadAsStringAsync().ConfigureAwait(false); await HandleLinkManagementResultErrors(result, link); } catch (Exception exception) { _logger.LogError(exception, "Failed to replace link."); throw; } }