コード例 #1
0
ファイル: LinkedInClient.cs プロジェクト: keithshort/HOPE
 /// <summary>
 /// Shares LinkedIn update asynchronously
 /// </summary>
 /// <param name="options">The object of type <see cref="LinkedInShareOptions"/> representing share options</param>
 /// <param name="action">Action to be invoked when update is shared</param>
 /// <returns>Status of asynchronous operation</returns>
 /// <exception cref="LinkedInMissingParameterException">Thrown when one or more share content's elements (Title, Description, SubmittedUrl, SubmittedImageUrl) are missing</exception>
 /// /// <example>
 /// This sample shows how to call this method:
 /// <code>
 /// using LinkedIn.NET;
 /// using LinkedIn.NET.Groups;
 /// using LinkedIn.NET.Members;
 /// using LinkedIn.NET.Options;
 /// using LinkedIn.NET.Search;
 /// using LinkedIn.NET.Updates;
 /// ...
 /// // define share options 
 /// var options = new LinkedInShareOptions();
 /// options.Title = "My share title";
 /// options.Description = "My share description";
 /// options.Comment = "This is my share comment";
 /// options.SubmittedUrl = "http://share.url.net";
 /// options.SubmittedImageUrl = "http://share.image.png";
 /// options.VisibilityCode = LinkedInShareVisibilityCode.Anyone;
 /// _Client.ShareUpdate(options, updateShared);
 /// ...
 /// // application defined function
 /// private void updateShared(LinkedInResponse&lt;LinkedInShareResult&gt; response)
 /// {
 ///     // always check response.Result and response.Status before processing
 ///     if (response.Result != null &amp;&amp; response.Status == LinkedInResponseStatus.OK)
 ///     {
 ///         MessageBox.Show(@"Update has been posted." + '\n' + @"Update key: " + response.Result.UpdateKey +
 ///                         '\n' + @"Update URL: " + response.Result.UpdateUrl);
 ///     }
 ///     else
 ///     {
 ///         // show possible error message LinkedIn response
 ///         MessageBox.Show(response.Message);
 ///     }
 /// }
 /// </code>
 /// </example>
 public IAsyncResult ShareUpdate(LinkedInShareOptions options, Action<LinkedInResponse<LinkedInShareResult>> action)
 {
     var contentPresented = Utils.IsAnyString(options.Title, options.SubmittedUrl, options.SubmittedImageUrl,
 options.Description);
     if (contentPresented)
     {
         if (string.IsNullOrEmpty(options.Title))
             throw new LinkedInMissingParameterException("Share content's title cannot be null or empty", "Title");
         if (string.IsNullOrEmpty(options.Description))
             throw new LinkedInMissingParameterException("Share content's description cannot be null or empty", "Description");
         if (string.IsNullOrEmpty(options.SubmittedUrl))
             throw new LinkedInMissingParameterException("Share content's submitted URL cannot be null or empty", "SubmittedUrl");
         if (string.IsNullOrEmpty(options.SubmittedImageUrl))
             throw new LinkedInMissingParameterException("Share content's submitted image URL cannot be null or empty", "SubmittedImageUrl");
     }
     ShareUpdateDelegate _delegate = ShareUpdate;
     return _delegate.BeginInvoke(options, shareUpdateCallback, action);
 }
コード例 #2
0
ファイル: LinkedInClient.cs プロジェクト: keithshort/HOPE
 /// <summary>
 /// Shares LinkedIn update
 /// </summary>
 /// <param name="options">The object of type <see cref="LinkedInShareOptions"/> representing share options</param>
 /// <returns>Value containing <see cref="LinkedInShareResult"/> object and response status</returns>
 /// <exception cref="LinkedInMissingParameterException">Thrown when one or more share content's elements (Title, Description, SubmittedUrl, SubmittedImageUrl) are missing</exception>
 /// <example>
 /// This sample shows how to call this method:
 /// <code>
 /// using LinkedIn.NET;
 /// using LinkedIn.NET.Groups;
 /// using LinkedIn.NET.Members;
 /// using LinkedIn.NET.Options;
 /// using LinkedIn.NET.Search;
 /// using LinkedIn.NET.Updates;
 /// ...
 /// // define share options 
 /// var options = new LinkedInShareOptions();
 /// options.Title = "My share title";
 /// options.Description = "My share description";
 /// options.Comment = "This is my share comment";
 /// options.SubmittedUrl = "http://share.url.net";
 /// options.SubmittedImageUrl = "http://share.image.png";
 /// options.VisibilityCode = LinkedInShareVisibilityCode.Anyone;
 /// var response = _Client.ShareUpdate(options);
 /// // always check response.Result and response.Status before processing
 /// if (response.Result != null &amp;&amp; response.Status == LinkedInResponseStatus.OK)
 /// {
 ///     MessageBox.Show(@"Update has been posted." + '\n' + @"Update key: " + response.Result.UpdateKey +
 ///                         '\n' + @"Update URL: " + response.Result.UpdateUrl);
 /// }
 /// else
 /// {
 ///     // show possible error message LinkedIn response
 ///     MessageBox.Show(response.Message);
 /// }
 /// </code>
 /// </example>
 public LinkedInResponse<LinkedInShareResult> ShareUpdate(LinkedInShareOptions options)
 {
     var contentPresented = Utils.IsAnyString(options.Title, options.SubmittedUrl, options.SubmittedImageUrl,
             options.Description);
     if (contentPresented)
     {
         if (string.IsNullOrEmpty(options.Title))
             throw new LinkedInMissingParameterException("Share content's title cannot be null or empty", "Title");
         if (string.IsNullOrEmpty(options.Description))
             throw new LinkedInMissingParameterException("Share content's description cannot be null or empty", "Description");
         if (string.IsNullOrEmpty(options.SubmittedUrl))
             throw new LinkedInMissingParameterException("Share content's submitted URL cannot be null or empty", "SubmittedUrl");
         if (string.IsNullOrEmpty(options.SubmittedImageUrl))
             throw new LinkedInMissingParameterException("Share content's submitted image URL cannot be null or empty", "SubmittedImageUrl");
     }
     return RequestRunner.ShareUpdate(options);
 }
コード例 #3
0
ファイル: RequestRunner.cs プロジェクト: keithshort/HOPE
        internal static LinkedInResponse<LinkedInShareResult> ShareUpdate(LinkedInShareOptions options)
        {
            try
            {
                var url = new StringBuilder(Utils.UPDATE_STATUS_URL);
                url.Append("oauth2_access_token=");
                url.Append(Singleton.Instance.AccessToken);
                var body = new StringBuilder("<?xml version=\"1.0\" encoding=\"UTF-8\"?><share><comment>");
                if (!string.IsNullOrEmpty(options.Comment))
                    body.Append(Utils.EscapeXml(options.Comment));
                body.Append("</comment>");
                var contentPresented = Utils.IsAnyString(options.Title, options.SubmittedUrl, options.SubmittedImageUrl,
                    options.Description);
                if (contentPresented)
                {
                    body.Append("<content><title>");
                    body.Append(Utils.EscapeXml(options.Title));
                    body.Append("</title><description>");
                    body.Append(Utils.EscapeXml(options.Description));
                    body.Append("</description><submitted-url>");
                    body.Append(Utils.EscapeXml(options.SubmittedUrl));
                    body.Append("</submitted-url><submitted-image-url>");
                    body.Append(Utils.EscapeXml(options.SubmittedImageUrl));
                    body.Append("</submitted-image-url></content>");
                }
                body.Append("<visibility><code>");
                body.Append(options.VisibilityCode == LinkedInShareVisibilityCode.Anyone ? "anyone" : "connections-only");
                body.Append("</code></visibility></share>");

                var responseString = Utils.MakeRequest(url.ToString(), "POST", body.ToString());
                var xdoc = XDocument.Parse(responseString);
                if (xdoc.Root != null)
                {
                    var eKey = xdoc.Root.Element("update-key");
                    var eUrl = xdoc.Root.Element("update-url");
                    if (eKey != null && eUrl != null)
                    {
                        return new LinkedInResponse<LinkedInShareResult>(
                            new LinkedInShareResult(eKey.Value, eUrl.Value), LinkedInResponseStatus.OK, null);
                    }
                }
                return new LinkedInResponse<LinkedInShareResult>(null, LinkedInResponseStatus.UpdateFailed, null);
            }
            catch (WebException wex)
            {
                return Utils.GetResponse<LinkedInShareResult>(null, wex, null);
            }
            catch (Exception ex)
            {
                return new LinkedInResponse<LinkedInShareResult>(null, LinkedInResponseStatus.OtherException, null, ex);
            }
        }