public virtual HttpRequest Create(PostIndexRequest request) { Ensure.That(request, "request").IsNotNull(); return new HttpRequest(HttpMethod.Post, GenerateRelativeUrl(request)) .SetRequestTypeHeader(request.GetType()) .SetJsonContent(GenerateRequestBody(request)); }
private static void CreateIndex2(IMyCouchCloudantClient client) { var indexRequest = new PostIndexRequest(); indexRequest.Configure(q => q.DesignDocument("TestDoc") .Name("TestIndex2") .Fields(new SortableField("author.age"), new SortableField("yearsActive")) ); var response = client.Queries.PostAsync(indexRequest).Result; response.IsSuccess.Should().Be(true); }
protected virtual string GenerateRequestBody(PostIndexRequest request) { Ensure.That(request.Fields, "request.Fields").HasItems(); var sb = new StringBuilder(); sb.Append("{"); sb.AppendFormat("{0}", GenerateIndexContent(request.Fields)); if (!string.IsNullOrWhiteSpace(request.DesignDocument)) sb.AppendFormat(FormatStrings.JsonPropertyAppendFormat, KeyNames.DesignDocument, Serializer.ToJson(request.DesignDocument)); if (request.Type.HasValue) sb.AppendFormat(FormatStrings.JsonPropertyAppendFormat, KeyNames.Type, Serializer.ToJson(request.Type.Value.ToString())); if (!string.IsNullOrWhiteSpace(request.Name)) sb.AppendFormat(FormatStrings.JsonPropertyAppendFormat, KeyNames.Name, Serializer.ToJson(request.Name)); sb.Append("}"); return sb.ToString(); }
protected virtual string GenerateRelativeUrl(PostIndexRequest request) { return "/_index"; }