/// <summary> /// Adds new post to group /// </summary> /// <param name="options">Value containing post's details</param> /// <returns>Request result</returns> /// <exception cref="LinkedInMissingParameterException">Thrown when any of post's required parameters is null or empty string</exception> public LinkedInResponse<bool> AddPost(LinkedInGroupPostOptions options) { options.GroupId = Id; if (string.IsNullOrEmpty(options.Title)) throw new LinkedInMissingParameterException("Post title cannot be empty", "Title"); if (string.IsNullOrEmpty(options.Summary)) throw new LinkedInMissingParameterException("Post summary cannot be empty", "Summary"); var contentPresented = Utils.IsAnyString(options.ContentTitle, options.ContentText, options.SubmittedUrl, options.SubmittedImageUrl); if (contentPresented && string.IsNullOrEmpty(options.ContentTitle)) throw new LinkedInMissingParameterException("Post content title cannot be empty", "ContentTitle"); if (contentPresented && string.IsNullOrEmpty(options.ContentText)) throw new LinkedInMissingParameterException("Post content text cannot be empty", "ContentText"); if (contentPresented && string.IsNullOrEmpty(options.SubmittedUrl)) throw new LinkedInMissingParameterException("Submitted URL cannot be empty", "SubmittedUrl"); if (contentPresented && string.IsNullOrEmpty(options.SubmittedImageUrl)) throw new LinkedInMissingParameterException("Submitted image URL cannot be empty", "SubmittedImageUrl"); return RequestRunner.AddGroupPost(options); }
internal static LinkedInResponse<bool> AddGroupPost(LinkedInGroupPostOptions options) { try { var sb = new StringBuilder(Utils.GROUP_POSTS_URL.Replace("{GROUP_ID}", options.GroupId)); sb.Append("?oauth2_access_token="); sb.Append(Singleton.Instance.AccessToken); var request = new StringBuilder("<post>"); request.Append("<title>"); request.Append(Utils.EscapeXml(options.Title)); request.Append("</title>"); request.Append("<summary>"); request.Append(Utils.EscapeXml(options.Summary)); request.Append("</summary>"); if (!string.IsNullOrEmpty(options.SubmittedUrl) && !string.IsNullOrEmpty(options.SubmittedImageUrl) && !string.IsNullOrEmpty(options.ContentTitle) && !string.IsNullOrEmpty(options.ContentText)) { request.Append("<content>"); request.Append("<submitted-url>"); request.Append(Utils.EscapeXml(options.SubmittedUrl)); request.Append("</submitted-url>"); request.Append("<submitted-image-url>"); request.Append(Utils.EscapeXml(options.SubmittedImageUrl)); request.Append("</submitted-image-url>"); request.Append("<title>"); request.Append(Utils.EscapeXml(options.ContentTitle)); request.Append("</title>"); request.Append("<description>"); request.Append(Utils.EscapeXml(options.ContentText)); request.Append("</description></content>"); } request.Append("</post>"); var statusCode = HttpStatusCode.OK; Utils.MakeRequest(sb.ToString(), "POST", ref statusCode, request.ToString()); return new LinkedInResponse<bool>(statusCode == HttpStatusCode.Created, LinkedInResponseStatus.OK, null); } catch (WebException wex) { return Utils.GetResponse(false, wex, null); } catch (Exception ex) { return new LinkedInResponse<bool>(false, LinkedInResponseStatus.OtherException, null, ex); } }