Ejemplo n.º 1
0
        /// <summary>
        /// Create a new comment with the specified characteristics. The parent field must contain the URI of either a content object for which this is a direct reply,
        /// or the URI of a previous comment to which this is a reply.
        /// </summary>
        /// <param name="new_comment">Comment object describing the comment to be created</param>
        /// <param name="author">Flag indicating if new comment is an author comment or a regular comment (only valid for documents). By default a regular comment will be created.</param>
        /// <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">Fields to be included in the returned Comment object</param>
        /// <returns>Comment object representing the created comment</returns>
        public Comment CreateComment(Comment new_comment, bool author = false, DateTime? published = null, DateTime? updated = null, List<string> fields = null)
        {
            //adds the query strings to the url if present
            string url = commentUrl;
            url += "?author=" + author.ToString();
            if (published != null)
            {
                url += "&published=" + jiveDateFormat((DateTime)published);
            }
            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);
            }

            string json = JsonConvert.SerializeObject(new_comment, new JsonSerializerSettings { DefaultValueHandling = DefaultValueHandling.Ignore, Formatting = Formatting.Indented });
            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 missing or malformed", e);
                    case 403:
                        throw new HttpException(e.WebEventCode, "You are not allowed to perform this operation", e);
                    case 404:
                        throw new HttpException(e.WebEventCode, "The specified parent object (or comment) could not be found", e);
                    case 409:
                        throw new HttpException(e.WebEventCode, "Attempt to add a comment to a content object that does not support them, or for which comments have been closed", e);
                }
            }

            return JsonConvert.DeserializeObject<Comment>(result);

            //JObject results = JObject.Parse(json); //this statement has been observed to have the possibility of dropping fields from the returned object

            //return results.ToObject<Comment>();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Create a new comment as a reply to the specified content object. The parent field (if any) in the incoming entity will be ignored.
        /// Instead, it will be set to the URI of the specified content object.
        /// </summary>
        /// <param name="contentID">ID of the content object this comment applies to</param>
        /// <param name="comment">a Comment object describing the comment to be created</param>
        /// <param name="author">Flag indicating if new comment is an author comment or a regular comment (only valid for documents).
        /// By default a regular document will be created.</param>
        /// <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">Fields to include in the returned Comment object</param>
        /// <returns>Comment object representing the newly created comment</returns>
        public Comment CreateComment(int contentID, Comment comment, bool author = false, DateTime? published = null, DateTime? updated = null,
            List<string> fields = null)
        {
            DateTime tmp;
            //create url with the user specified options added
            string url = contentUrl + "/" + contentID.ToString() + "/comments";
            url += "?author=" + author.ToString();
            if (published != null)
            {
                tmp = (DateTime)published;
                url += "&published=" + jiveDateFormat(tmp);
            }
            if (updated != null)
            {
                tmp = (DateTime)updated;
                url += "&updated=" + jiveDateFormat(tmp);
            }
            if (fields != null && fields.Count > 0) {
                url += "&fields=";
                foreach (var field in fields)
                {
                    url += field + ",";

                }
                //remove last comma
                url = url.Remove(url.Length - 1);
            }

            string json = JsonConvert.SerializeObject(comment, 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 missing or malformed", e);
                    case 403:
                        throw new HttpException(e.WebEventCode, "You are not allowed to perform this operation", e);
                    case 404:
                        throw new HttpException(e.WebEventCode, "The specified parent content object (or comment) cannot be found", e);
                    default:
                        throw;
                }
            }

            JObject Json = JObject.Parse(result);
            return Json.ToObject<Comment>();

        }
Ejemplo n.º 3
0
        /// <summary>
        /// Update the specified editable comment with the specified characteristics.
        /// </summary>
        /// <param name="commentID">ID of the editable comment to be updated</param>
        /// <param name="comment">Comment object containing the updated comment</param>
        /// <param name="updated">Date and time when this content object was most recently updated.</param>
        /// <param name="fields">Fields to include in the returned entity</param>
        /// <returns>Comment object representing the updated comment</returns>
        public Comment UpdateEditableComment(int commentID, Comment comment, DateTime? updated = null, List<string> fields = null)
        {
            //adds the query strings to the url if present
            string url = commentUrl + commentID.ToString() + "/editable";
            bool first = true;
            if (updated != null)
            {
                url += "?updated=" + jiveDateFormat((DateTime)updated);
                first = false;
            }
            if (fields != null && fields.Count > 0)
            {
                if (first) url += "?fields=";
                else url += "&fields=";

                foreach (var field in fields)
                {
                    url += field + ",";
                }
                //remove last comma
                url = url.Remove(url.Length - 1);
            }

            string json = JsonConvert.SerializeObject(comment, new JsonSerializerSettings { DefaultValueHandling = DefaultValueHandling.Ignore, Formatting = Formatting.Indented });
            string result = "";
            try
            {
                result = PutAbsolute(url, json); //makes the HTTP request
            }
            catch (HttpException e)
            {
                switch (e.GetHttpCode())
                {
                    case 400:
                        throw new HttpException(e.WebEventCode, "An input field is missing or malformed", e);
                    case 403:
                        throw new HttpException(e.WebEventCode, "You are not allowed to access the specified comment", e);
                    case 404:
                        throw new HttpException(e.WebEventCode, "The specified comment does not exist", e);
                    case 409:
                        throw new HttpException(e.WebEventCode, "Attempt to add a comment to a content object that does not support them, or for which comments have been closed", e);
                }
            }

            return JsonConvert.DeserializeObject<Comment>(result);
        }