示例#1
0
        /// <inheritdoc />
        public async Task <AssignUserIdResponse> AssignUserIdAsync(string userId, string clusterName,
                                                                   RequestOptions requestOptions = null, CancellationToken ct = default)
        {
            if (string.IsNullOrWhiteSpace(userId))
            {
                throw new ArgumentNullException(userId);
            }

            if (string.IsNullOrWhiteSpace(clusterName))
            {
                throw new ArgumentNullException(clusterName);
            }

            var data = new AssignUserIdRequest {
                Cluster = clusterName
            };

            var userIdHeader = new Dictionary <string, string>()
            {
                { "X-Algolia-USER-ID", userId }
            };

            requestOptions = requestOptions.AddHeaders(userIdHeader);

            AssignUserIdResponse response = await _transport
                                            .ExecuteRequestAsync <AssignUserIdResponse, AssignUserIdRequest>(HttpMethod.Post,
                                                                                                             "/1/clusters/mapping", CallType.Write, data, requestOptions, ct)
                                            .ConfigureAwait(false);

            response.UserId    = userId;
            response.GetUserId = u => GetUserId(u);
            return(response);
        }
示例#2
0
        /// <inheritdoc />
        public async Task <RemoveUserIdResponse> RemoveUserIdAsync(string userId, RequestOptions requestOptions = null,
                                                                   CancellationToken ct = default)
        {
            if (string.IsNullOrWhiteSpace(userId))
            {
                throw new ArgumentNullException(userId);
            }

            var userIdHeader = new Dictionary <string, string>()
            {
                { "X-Algolia-USER-ID", userId }
            };

            requestOptions = requestOptions.AddHeaders(userIdHeader);

            return(await _transport.ExecuteRequestAsync <RemoveUserIdResponse>(
                       HttpMethod.Delete,
                       $"/1/clusters/mapping", CallType.Write, requestOptions, ct)
                   .ConfigureAwait(false));
        }