/// <summary> /// Creates kotori document type Uri. /// </summary> /// <returns>The kotori document type Uri.</returns> /// <param name="documentTypeId">Document type identifier.</param> /// <param name="documentType">Document type.</param> /// <param name="projectId">Project identifier.</param> internal static Uri ToKotoriDocumentTypeUri(this string projectId, Enums.DocumentType documentType, string documentTypeId) { if (documentTypeId == null) { throw new ArgumentNullException(nameof(documentTypeId)); } if (projectId == null) { throw new ArgumentNullException(nameof(projectId)); } if (!projectId.IsValidSlug()) { throw new KotoriProjectException(projectId, $"Project slug {projectId} is not valid."); } if (!documentTypeId.IsValidSlug()) { throw new KotoriDocumentTypeException(projectId, $"Document type slug {documentTypeId} is not valid."); } return(new Uri(UriScheme + "api/projects/" + projectId + "/" + documentType.ToString().ToLower(Cultures.Invariant) + "/" + documentTypeId)); }
/// <summary> /// Initializes a new instance of the SimpleDocumentType class. /// </summary> /// <param name="identifier">Identifier.</param> /// <param name="type">Document type.</param> /// <param name="fields">Index fields.</param> public SimpleDocumentType(string identifier, Enums.DocumentType type, IEnumerable <string> fields) { Identifier = identifier; Type = type.ToString().ToLower(Cultures.Invariant); Fields = fields; }
/// <summary> /// Creates kotori document Uri. /// </summary> /// <returns>The kotori document Uri.</returns> /// <param name="documentTypeId">Document type identifier.</param> /// <param name="documentType">Document type.</param> /// <param name="projectId">Project identifier.</param> /// <param name="documentId">Document identifier.</param> /// <param name="index">Index.</param> internal static Uri ToKotoriDocumentUri(this string projectId, Enums.DocumentType documentType, string documentTypeId, string documentId, long?index) { if (documentType == Enums.DocumentType.Content && documentId == null) { throw new ArgumentNullException(nameof(documentId)); } if (documentType == Enums.DocumentType.Data && !string.IsNullOrEmpty(documentId)) { throw new ArgumentException("Document Id cannot be set for data documents.", nameof(documentId)); } if (documentTypeId == null) { throw new ArgumentNullException(nameof(documentTypeId)); } if (projectId == null) { throw new ArgumentNullException(nameof(projectId)); } if (!projectId.IsValidSlug()) { throw new KotoriProjectException(projectId, $"Project slug {projectId} is not valid."); } if (!documentTypeId.IsValidSlug()) { throw new KotoriDocumentTypeException(documentTypeId, $"Document type slug {documentTypeId} is not valid."); } if (documentType == Enums.DocumentType.Content && !documentId.IsValidSlug()) { throw new KotoriDocumentException(documentId, $"Document slug {documentId} is not valid."); } if (index.HasValue && index < 0) { throw new KotoriDocumentException(documentId, $"Index must equals or be greater than 0."); } string uri = string.Empty; if (documentType == Enums.DocumentType.Content) { uri = UriScheme + "api/projects/" + projectId + "/" + documentType.ToString().ToLower(Cultures.Invariant) + "/" + documentTypeId + "/documents/" + documentId; } else if (documentType == Enums.DocumentType.Data) { uri = UriScheme + "api/projects/" + projectId + "/" + documentType.ToString().ToLower(Cultures.Invariant) + "/" + documentTypeId + "/indices/" + index; } else { throw new KotoriException($"Uri scheme generator is not defined for document type {documentType}."); } return(new Uri(uri)); }