/// <summary> /// The ChangeUsers /// </summary> /// <param name="method">The <see cref="RestSharp.Method"/></param> /// <param name="client">The <see cref="RestClient"/></param> /// <param name="groupId">The <see cref="string"/></param> /// <param name="userId">The <see cref="string"/></param> private static void ChangeUsers(RestSharp.Method method, RestClient client, string groupId, string userId) { var uri = string.Format("/groups/{0}/users/{1}", groupId, userId); var request = new RestRequest(uri, method); Rest.Execute <BasicResponse>(client, request); }
/// <summary> /// Updates an existing <see cref="Document"/> on the server /// </summary> /// <param name="client">the <see cref="RestClient"/> to use</param> /// <param name="document">the <see cref="Document"/> to update</param> /// <returns>the id of the updated document</returns> internal static void Update(RestClient client, Document document) { var uri = string.Format("documents/{0}", document.Id); var request = new RestRequest(uri, Method.PUT); Rest.Execute <UpdateDocumentResponse>(client, request, new { content = document.Content }); }
/// <summary> /// Reads a specified Application /// </summary> /// <param name="client">The <see cref="RestClient"/> to use for communication</param> /// <param name="applicationId">The <see cref="ChinoApplication.Id"/> to identify the application</param> /// <returns>a new instance of the <see cref="ChinoApplication"/> class</returns> public static ChinoApplication Read(RestClient client, string applicationId) { var request = new RestRequest("/auth/applications/" + applicationId, Method.GET); var response = Rest.Execute <ReadApplicationResponse>(client, request); return(response.Data.Application); }
/// <summary> /// The Create /// </summary> /// <param name="client">The <see cref="RestClient"/></param> /// <param name="description">The <see cref="string"/></param> /// <returns>The <see cref="Repository"/></returns> public static Repository Create(RestClient client, string description) { var request = new RestRequest("/repositories", Method.POST); var result = Rest.Execute <RepositoryDefaultResponse>(client, request, new { description = description }); return(result.Data.Repository); }
/// <summary> /// The Get /// </summary> /// <param name="client">The <see cref="RestClient"/></param> /// <param name="id">The <see cref="string"/></param> /// <returns>The <see cref="Repository"/></returns> public static Repository Get(RestClient client, string id) { var request = new RestRequest("/repositories/" + id, Method.GET); var result = Rest.Execute <RepositoryDefaultResponse>(client, request); return(result.Data.Repository); }
/// <summary> /// The Current /// </summary> /// <param name="client">The <see cref="RestClient"/></param> /// <returns>The <see cref="User"/></returns> public static User Current(RestClient client) { var uri = "/users/me"; var result = Rest.Execute <UserResponse>(client, new RestRequest(uri, Method.GET)); return(result.Data.User); }
/// <summary> /// Delete a document from a collection /// </summary> /// <param name="client">The <see cref="RestClient"/> to use for communication</param> /// <param name="collectionId">The id of the collection to delete the document from</param> /// <param name="documentId">The id of the document to delete</param> public static void DeleteDocument(RestClient client, string collectionId, string documentId) { var uri = string.Format("/collections/{0}/documents/{1}", collectionId, documentId); var request = new RestRequest(uri, Method.DELETE); Rest.Execute <BasicResponse>(client, request); }
/// <summary> /// performs a search with the current settings on the api server /// </summary> /// <param name="schemaId">the Id of the Schema</param> /// <param name="offset">from which starting record should the result be returned</param> /// <param name="limit">indicates how many records should be returned</param> /// <returns>a new instance of the <see cref="SearchData"/> class</returns> public SearchData SearchDocuments(string schemaId, int offset, int limit) { if (!Filters.Any()) { throw new ChinoApiException("No Filters have been defined for the search."); } if (!Sortings.Any()) { Sortings.Add(new SearchSort { Field = Filters.First().Field }); } var body = new { result_type = ResultType.ToString(), filter_type = FilterType.ToString(), sort = Sortings, filter = Filters }; var jSon = Utils.SerializeObject(body); var uriString = string.Format("/search/documents/{0}", schemaId); var searchUri = new Uri(uriString, UriKind.Relative); RestRequest request = new RestRequest(searchUri, Method.POST); request.AddQueryParameter("offset", offset.ToString()); request.AddQueryParameter("limit", limit.ToString()); var result = Rest.Execute <SearchResult>(client, request, body); return(result.Data); }
/// <summary> /// The Get /// </summary> /// <param name="client">The <see cref="RestClient"/></param> /// <param name="schemaId">The <see cref="string"/></param> /// <returns>The <see cref="Schema"/></returns> public static Schema Get(RestClient client, string schemaId) { var uri = string.Format("/schemas/{0}", schemaId); var request = new RestRequest(uri, Method.GET); var result = Rest.Execute <SchemaResponse>(client, request); return(result.Data.Schema); }
/// <summary> /// The Get /// </summary> /// <param name="client">The <see cref="RestClient"/></param> /// <param name="userId">The <see cref="string"/></param> /// <returns>The <see cref="User"/></returns> public static User Get(RestClient client, string userId) { var uri = string.Format("/users/{0}", userId); var request = new RestRequest(uri, Method.GET); var result = Rest.Execute <UserResponse>(client, request); return(result.Data.User); }
/// <summary> /// Creates a new Document on the API-Server and returns the new Id /// </summary> /// <param name="client">the <see cref="RestClient"/> to use</param> /// <param name="schemaId">the schema-Id to store the document to</param> /// <param name="document">the document to store</param> /// <returns>the Id of the new generated documents</returns> internal static string Create(RestClient client, string schemaId, Document document) { var uri = string.Format("schemas/{0}/documents", schemaId); var request = new RestRequest(uri, Method.POST); var result = Rest.Execute <UpdateDocumentResponse>(client, request, new { content = document.Content }); return(result.Data.Document.Id); }
/// <summary> /// The Get /// </summary> /// <param name="userSchemaId">The <see cref="string"/></param> /// <returns>The <see cref="UserSchema"/></returns> public UserSchema Get(string userSchemaId) { var uri = string.Format("/user_schemas/{0}", userSchemaId); var request = new RestRequest(uri, Method.GET); var result = Rest.Execute <UserSchemaResponse>(client, request); return(result.Data.Schema); }
/// <summary> /// The Get /// </summary> /// <param name="client">The <see cref="RestClient"/></param> /// <param name="groupId">The <see cref="string"/></param> /// <returns>The <see cref="Group"/></returns> public static Group Get(RestClient client, string groupId) { var uri = string.Format("/groups/{0}", groupId); var request = new RestRequest(uri, Method.GET); var result = Rest.Execute <GroupResponse>(client, request); return(result.Data.Group); }
/// <summary> /// Retrieves a single Document from the API-Server /// </summary> /// <param name="client">the <see cref="RestClient"/> to use</param> /// <param name="documentId">the id of the document to download</param> /// <returns>a new instance of the <see cref="Document"/> class</returns> internal static Document Get(RestClient client, string documentId) { var uri = string.Format("documents/{0}", documentId); var request = new RestRequest(uri, Method.GET); var result = Rest.Execute <GetDocumentResponse>(client, request); return(result.Data.Document); }
/// <summary> /// The Update /// </summary> /// <param name="client">The <see cref="RestClient"/></param> /// <param name="id">The <see cref="string"/></param> /// <param name="newName">The <see cref="string"/></param> /// <returns>The <see cref="Collection"/></returns> public static Collection Update(RestClient client, string id, string newName) { var request = new RestRequest("/collections/" + id, Method.PUT); Utils.SetJsonBody(request, new { name = newName }); var result = Rest.Execute <CreateCollectionResponse>(client, request); return(result.Data.Collection); }
/// <summary> /// The Search /// </summary> /// <param name="client">The <see cref="RestClient"/></param> /// <param name="name">The <see cref="string"/></param> /// <param name="contains">The <see cref="bool"/></param> /// <returns>The <see cref="CollectionList"/></returns> public static CollectionList Search(RestClient client, string name, bool contains) { var request = new RestRequest("/collections/search", Method.POST); Utils.SetJsonBody(request, new { name = name, contains = contains }); var result = Rest.Execute <CollectionsListResponse>(client, request); return(result.Data); }
/// <summary> /// The Documents /// </summary> /// <param name="client">The <see cref="RestClient"/></param> /// <param name="collectionId">The <see cref="string"/></param> /// <param name="start">The <see cref="int"/></param> /// <param name="limit">The <see cref="int"/></param> /// <returns>The <see cref="IEnumerable{Document}"/></returns> public static IEnumerable <Document> GetDocuments(RestClient client, string collectionId, int start, int limit) { var request = new RestRequest(string.Format("/collections/{0}/documents", collectionId)); request.AddQueryParameter("offset", start.ToString()); request.AddQueryParameter("limit", limit.ToString()); var result = Rest.Execute <CollectionDocumentsResponse>(client, request); return(result.Data.Documents); }
/// <summary> /// The Create /// </summary> /// <param name="client">The <see cref="RestClient"/></param> /// <param name="collectionName">The <see cref="string"/></param> /// <returns>The <see cref="Collection"/></returns> public static Collection Create(RestClient client, string collectionName) { var request = new RestRequest("/collections", Method.POST); Utils.SetJsonBody(request, new { name = collectionName }); var resultSet = Rest.Execute <CreateCollectionResponse>(client, request); return(resultSet.Data.Collection); }
/// <summary> /// The Status /// </summary> /// <param name="client">The <see cref="RestClient"/></param> /// <param name="bearerToken">The <see cref="string"/></param> /// <returns>The <see cref="User"/></returns> public static User Status(RestClient client, string bearerToken) { var request = new RestRequest("/users/me", Method.GET); client.RemoveDefaultParameter("Authorization"); client.AddDefaultHeader("Authorization", "Bearer " + bearerToken); var result = Rest.Execute <StatusResponse>(client, request); return(result.Data.User); }
/// <summary> /// The Logout /// </summary> /// <param name="client">The <see cref="RestClient"/></param> /// <param name="bearerToken">The <see cref="string"/></param> /// <param name="appId">The <see cref="string"/></param> /// <param name="appSecret">The <see cref="string"/></param> public static void Logout(RestClient client, string bearerToken, string appId, string appSecret) { var request = new RestRequest("/auth/revoke_token/", Method.POST); request.AddHeader("Content-Type", "multipart/form-data"); request.AddParameter("token", bearerToken); request.AddParameter("client_id", appId); request.AddParameter("client_secret", appSecret); Rest.Execute <BasicResponse>(client, request); }
/// <summary> /// The List /// </summary> /// <param name="client">The <see cref="RestClient"/></param> /// <param name="start">The <see cref="int"/></param> /// <param name="limit">The <see cref="int"/></param> /// <returns>The <see cref="RepositoryList"/></returns> public static RepositoryList List(RestClient client, int start, int limit) { var request = new RestRequest("/repositories", Method.GET); request.AddQueryParameter("offset", start.ToString()); request.AddQueryParameter("limit", limit.ToString()); var result = Rest.Execute <RepositoryListResponse>(client, request); return(result.Data); }
/// <summary> /// The List /// </summary> /// <param name="client">The <see cref="RestClient"/></param> /// <param name="repositoryId">The <see cref="string"/></param> /// <param name="start">The <see cref="int"/></param> /// <param name="limit">The <see cref="int"/></param> /// <returns>The <see cref="SchemaList"/></returns> public static SchemaList List(RestClient client, string repositoryId, int start, int limit) { var uri = string.Format("/repositories/{0}/schemas", repositoryId); var request = new RestRequest(uri, Method.GET); request.AddQueryParameter("offset", start.ToString()); request.AddQueryParameter("limit", limit.ToString()); var result = Rest.Execute <ListSchemaResponse>(client, request); return(result.Data); }
/// <summary> /// The Delete /// </summary> /// <param name="client">The <see cref="RestClient"/></param> /// <param name="id">The <see cref="string"/></param> /// <param name="deactivateOnly">The <see cref="bool"/></param> public static void Delete(RestClient client, string id, bool deactivateOnly) { var request = new RestRequest("/repositories/" + id, Method.DELETE); if (!deactivateOnly) { request.AddQueryParameter("force", "true"); } Rest.Execute <BasicResponse>(client, request); }
/// <summary> /// The List /// </summary> /// <param name="client">The <see cref="RestClient"/></param> /// <param name="userSchemaId">The <see cref="string"/></param> /// <param name="start">The <see cref="int"/></param> /// <param name="limit">The <see cref="int"/></param> /// <returns>The <see cref="UserList"/></returns> public static UserList List(RestClient client, string userSchemaId, int start, int limit) { var uri = string.Format("/user_schemas/{0}/users", userSchemaId); var request = new RestRequest(uri, Method.GET); request.AddQueryParameter("offset", start.ToString()); request.AddQueryParameter("limit", limit.ToString()); var result = Rest.Execute <ListUserResponse>(client, request); return(result.Data); }
/// <summary> /// The CommitUpload /// </summary> /// <param name="client">The <see cref="RestClient"/></param> /// <param name="uploadId">The <see cref="string"/></param> /// <returns>The <see cref="Blob"/></returns> private static Blob CommitUpload(RestClient client, string uploadId) { var request = new RestRequest("/blobs/commit", Method.POST); var commitBlobUploadRequest = new CommitBlobUploadRequest(); commitBlobUploadRequest.UploadId = uploadId; var result = Rest.Execute <CommitBlobUploadResponse>(client, request, commitBlobUploadRequest); return(result.Data.Blob); }
/// <summary> /// Gets a list of Applications from the api server /// </summary> /// <param name="client">The <see cref="RestClient"/> to use for communication</param> /// <param name="start">where the list should start</param> /// <param name="limit">the amount of records to read</param> /// <returns>a new instance of the <see cref="ApplicationList"/> class</returns> public static ApplicationList List(RestClient client, int start, int limit) { var request = new RestRequest("/auth/applications", Method.GET); request.AddQueryParameter("offset", start.ToString()); request.AddQueryParameter("limit", limit.ToString()); var response = Rest.Execute <ListApplicationsResponse>(client, request); return(response.Data); }
/// <summary> /// The ChangePermissionsion /// </summary> /// <param name="client">The <see cref="RestClient"/></param> /// <param name="action">The <see cref="PermissionAction"/></param> /// <param name="grants">The <see cref="PermissionSet"/></param> /// <param name="resourceType">The <see cref="PermissionResourceType"/></param> /// <param name="resourceId">The <see cref="string"/></param> /// <param name="childType">The <see cref="PermissionResourceType"/></param> /// <param name="subjectType">The <see cref="PermissionSubjectType"/></param> /// <param name="subjectId">The <see cref="string"/></param> private static void ChangePermission(RestClient client, PermissionAction action, PermissionSet grants, PermissionResourceType resourceType, string resourceId, PermissionResourceType childType, PermissionSubjectType subjectType, string subjectId) { var uri = string.Format("/perms/{0}/{1}/{2}/{3}/{4}/{5}", action.ToString().ToLower(), resourceType.ToString().ToLower(), resourceId, childType == PermissionResourceType.none ? string.Empty : childType.ToString(), subjectType.ToString().ToLower(), subjectId ); var permsManage = PermissionsToList(grants.Manage); //.Where(o=>o == "R" ||o=="U" || o == "D"); var permsAuthorize = PermissionsToList(grants.Authorize); //.Where(o=>o =="R" || o == "U" || o == "D" || o == "A"); var permsCreatedManage = PermissionsToList(grants.CreatedDocument.Manage); //.Where(o => o == "R" || o == "U" || o == "D"); var permsCreatedAuthorize = PermissionsToList(grants.CreatedDocument.Authorize); // .Where(o => o == "R" || o == "U" || o == "D" || o == "A"); object grantBody = new { }; if (!permsCreatedManage.Any() && !permsCreatedAuthorize.Any()) { grantBody = new { manage = permsManage, authorize = permsAuthorize }; } else { var created = new { manage = permsCreatedManage, authorize = permsCreatedAuthorize, }; grantBody = new { manage = permsManage, authorize = permsAuthorize, created_document = created }; } uri = uri.Replace("//", "/"); var request = new RestRequest(uri, Method.POST); #if DEBUG var bodyTxt = JsonConvert.SerializeObject(grantBody); #endif Rest.Execute <BasicResponse>(client, request, grantBody); }
/// <summary> /// The List /// </summary> /// <param name="client">The <see cref="RestClient"/></param> /// <param name="start">The <see cref="int"/></param> /// <param name="limit">The <see cref="int"/></param> /// <returns>The <see cref="GroupList"/></returns> public static GroupList List(RestClient client, int start, int limit) { var uri = "/groups"; var request = new RestRequest(uri, Method.GET); request.AddQueryParameter("offset", start.ToString()); request.AddQueryParameter("limit", limit.ToString()); var result = Rest.Execute <ListGroupResponse>(client, request); return(result.Data); }
/// <summary> /// The Update /// </summary> /// <param name="client">The <see cref="RestClient"/></param> /// <param name="id">The <see cref="string"/></param> /// <param name="description">The <see cref="string"/></param> /// <param name="isActive">The <see cref="bool"/></param> public static void Update(RestClient client, string id, string description, bool isActive) { var request = new RestRequest("/repositories/" + id, Method.PUT); var result = Rest.Execute <RepositoryListResponse>(client, request, new { description = description, is_active = isActive }); Rest.Execute <BasicResponse>(client, request); }
/// <summary> /// The Get /// </summary> /// <param name="client">The <see cref="RestClient"/></param> /// <param name="id">The <see cref="string"/></param> /// <param name="readDocuments">Specifies whether the documents should be read from the server</param> /// <returns>The <see cref="Collection"/></returns> public static Collection Get(RestClient client, string id, bool readDocuments = false) { var request = new RestRequest("/collections/" + id, Method.GET); var result = Rest.Execute <GetCollectionResponse>(client, request); if (readDocuments) { result.Data.Collection.ReadDocuments(client); } return(result.Data.Collection); }