/// <summary> /// Create a new content object with specified characteristics, and return an entity representing the newly created content object. /// </summary> /// <param name="published">Date and time when this content object was originally created. Set 'updated' param as well. Only set this field when importing content.</param> /// <param name="updated">Date and time when this content object was most recently updated. Set 'published' param as well. Only set this field when importing content.</param> /// <param name="fields">The fields to include in the returned entity</param> /// <param name="content">The content object to be created</param> /// <returns></returns> // remember to use the jiveDateFormat(DateTime time) function to use the correct format public GenericContent CreateContent(GenericContent content, DateTime? published = null, DateTime? updated = null, List<string> fields = null) { //adds the query strings to the url if present string url = contentUrl; bool first = true; if (published != null) { url += "?published=" + jiveDateFormat((DateTime)published); first = false; } if (updated != null) { if (first == true) { url += "?updated=" + jiveDateFormat((DateTime)updated); first = false; } else { url += "&updated=" + jiveDateFormat((DateTime)updated); } } if (fields != null && fields.Count > 0) { if (first == true) { url += "?fields="; first = false; } else url += "&fields="; foreach (var field in fields) { url += field + ","; } //remove last comma url = url.Remove(url.Length - 1); } string json = JsonConvert.SerializeObject(content, new JsonSerializerSettings { DefaultValueHandling = DefaultValueHandling.Ignore }); string result = ""; try { result = PostAbsolute(url, json); //makes the HTTP request } catch (HttpException e) { switch (e.GetHttpCode()) { case 400: throw new HttpException(e.WebEventCode, "An input field is malformed", e); case 403: throw new HttpException(e.WebEventCode, "You are not allowed to access the specified content", e); case 409: throw new HttpException(e.WebEventCode, "The new entity would conflict with system restrictions (such as two contents of the same type with the same name)", e); } } JObject Json = JObject.Parse(result); return Json.ToObject<GenericContent>(); }
//public GetUserEntitlements() /// <summary> /// Update an existing content with specified characteristics. /// </summary> /// <param name="contentID">ID of the content object to be updated</param> /// <param name="content">GenericContent object describing the content to be updated</param> /// <param name="minor">Flag indicating whether this update is a minor edit (true) or not (false)</param> /// <param name="abridged">Flag indicating that if content.text is requested, it will be abridged (length shortened, HTML tags removed)</param> /// <param name="updated">Date and time when this content object was most recently updated. Only set this field when importing content.</param> /// <param name="fields">Fields to include in the returned entity</param> /// <returns>GenericContent object representing the updated content object</returns> public GenericContent UpdateContent(int contentID, GenericContent content, bool minor = true, bool abridged = false, DateTime? updated = null, List<string> fields = null) { //constructs the url for the HTTP request based on the user specifications string url = contentUrl + "/" + contentID.ToString(); url += "?minor=" + minor.ToString(); url += "&abridged=" + abridged.ToString(); if (updated != null) { url += "&updated=" + jiveDateFormat((DateTime)updated); } if (fields != null && fields.Count > 0) { url += "&fields="; foreach (var field in fields) { url += field + ","; } // remove last comma url = url.Remove(url.Length - 1); } //converts the content into a JSON string and makes the HTTP request string json = JsonConvert.SerializeObject(content, new JsonSerializerSettings { DefaultValueHandling = DefaultValueHandling.Ignore, Formatting = Formatting.Indented }); string result; try { result = PutAbsolute(url, json); } catch (HttpException e) { switch (e.GetHttpCode()) { case 400: throw new HttpException(e.WebEventCode, "An input field is malformed", e); case 403: throw new HttpException(e.WebEventCode, "You are not allowed to access the specified content object, or to make the requested change in content object state", e); case 404: throw new HttpException(e.WebEventCode, "The specified content does not exist", e); case 409: throw new HttpException(e.WebEventCode, "The new entity would conflict with system restrictions (such as two content objects of the same type with the same subject", e); default: throw; } } //parses the result into a GenericContent object and returns it to the user JObject Json = JObject.Parse(result); return Json.ToObject<GenericContent>(); }