/// <summary> /// Creates a new Resource. /// </summary> /// <param name="collectionType">Collection type to add the resource to</param> /// <param name="resource">Resource to add to the Collection</param> /// <returns>Newly created Resource</returns> public Resource create(string collectionType, Resource resource) { gdapi.WebRequest rRequestor = new gdapi.WebRequest(this); rRequestor.setType("POST"); rRequestor.setBody(JsonConvert.SerializeObject(resource.getProperties())); rRequestor.setQuery(collectionType); return getResourceByRequest(rRequestor); }
/// <summary> /// Deletes a Resource /// </summary> /// <param name="collectionType">Collection type to delete the resource from</param> /// <param name="resource">Resource to delete</param> /// <returns>Deleted Resource</returns> public Resource delete(string collectionType, Resource resource) { gdapi.WebRequest rRequestor = new gdapi.WebRequest(this); rRequestor.setType("DELETE"); rRequestor.setQuery(collectionType + "/" + resource.getProperty("id")); return getResourceByRequest(rRequestor); }
/// <summary> /// Fetches a link from the API as a Resource. /// </summary> /// <param name="resource">Resource object which contains links.</param> /// <param name="linkName">Link name to return.</param> /// <exception cref="NotFoundException"/> /// <returns>Resource from Resource</returns> public Resource fetchLinkAsResource(Resource resource, string linkName) { if (resource.hasLink(linkName)) { gdapi.WebRequest rRequestor = new gdapi.WebRequest(this); rRequestor.setType("GET"); rRequestor.setUrl(resource.getLink(linkName)); return getResourceByRequest(rRequestor); } else { return null; } }
/// <summary> /// Saves a Resource /// </summary> /// <param name="collectionType">Collection type to save the resource to</param> /// <param name="resource">Resource to save</param> /// <returns>Saved Resource</returns> public Resource save(string collectionType, Resource resource) { if (resource.hasProperty("id")) { gdapi.WebRequest rRequestor = new gdapi.WebRequest(this); rRequestor.setType("PUT"); rRequestor.setBody(JsonConvert.SerializeObject(resource.getProperties())); rRequestor.setQuery(collectionType + "/" + resource.getProperty("id")); return getResourceByRequest(rRequestor); } else { return create(collectionType, resource); } }
/// <summary> /// Performs an action from an action url and an input resource and returns the resulting Resource /// </summary> /// <param name="actionUrl">Action URL to perform.</param> /// <param name="inputResource">Input Resource to use send with the action URL.</param> /// <returns>Resource result of the action.</returns> public Resource doAction(string actionUrl, Resource inputResource) { gdapi.WebRequest rRequestor = new gdapi.WebRequest(this); rRequestor.setType("POST"); rRequestor.setUrl(actionUrl); if (inputResource != null) { rRequestor.setBody(JsonConvert.SerializeObject(inputResource.getProperties())); } return getResourceByRequest(rRequestor); }