Example #1
0
        internal static LinkedInResponse<bool> SendInvitation(LinkedInInvitationOptions options)
        {
            try
            {
                var sb = new StringBuilder(Utils.SEND_MESSAGE_URL);
                sb.Append("?oauth2_access_token=");
                sb.Append(Singleton.Instance.AccessToken);
                var message = new StringBuilder("<?xml version='1.0' encoding='UTF-8'?><mailbox-item><recipients><recipient>");
                switch (options.InvitationType)
                {
                    case LinkedInInvitationType.InviteById:
                        message.Append("<person path='/people/id=");
                        message.Append(Utils.EscapeXml(options.RecipientId));
                        message.Append("' />");
                        break;
                    case LinkedInInvitationType.InviteByEmail:
                        message.Append("<person path='/people/email=");
                        message.Append(Utils.EscapeXml(options.RecipientEmail));
                        message.Append("'>");
                        message.Append("<first-name>");
                        message.Append(Utils.EscapeXml(options.RecipientFirstName));
                        message.Append("</first-name>");
                        message.Append("<last-name>");
                        message.Append(Utils.EscapeXml(options.RecipientLastName));
                        message.Append("</last-name>");
                        message.Append("</person>");
                        break;
                }
                message.Append("</recipient></recipients>");
                message.Append("<subject>");
                message.Append(Utils.EscapeXml(options.Subject));
                message.Append("</subject>");
                message.Append("<body>");
                message.Append(Utils.EscapeXml(options.Body));
                message.Append("</body>");
                message.Append("<item-content><invitation-request><connect-type>friend</connect-type>");
                if (options.InvitationType == LinkedInInvitationType.InviteById)
                {
                    message.Append("<authorization>");
                    message.Append("<name>");
                    message.Append(Utils.EscapeXml(options.AuthorizationName));
                    message.Append("</name>");
                    message.Append("<value>");
                    message.Append(Utils.EscapeXml(options.AuthorizationValue));
                    message.Append("</value>");
                    message.Append("</authorization>");
                }
                message.Append("</invitation-request></item-content>");
                message.Append("</mailbox-item>");

                var statusCode = HttpStatusCode.OK;
                Utils.MakeRequest(sb.ToString(), "POST", ref statusCode, message.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);
            }
        }
Example #2
0
 /// <summary>
 /// Sends invitation over LinkedIn network
 /// </summary>
 /// <param name="options">The object of type <see cref="LinkedInInvitationOptions"/> representing invitation options</param>
 /// <returns>Value containing <see cref="LinkedInSearchResult"/> object and response status</returns>
 /// <exception cref="LinkedInMissingParameterException">Thrown when options.InvitationType is set to InviteById and either RecipientId or AuthorizationName or AuthorizationValue is missing, 
 /// or when options.InvitationType is set to InviteByEmail and either RecipientEmail or RecipientFirstName or RecipientLastName is 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 invitation options
 /// var options = new LinkedInInvitationOptions
 ///        {
 ///            InvitationType = LinkedInInvitationType.InviteByEmail,
 ///            Subject = "Invitation subject",
 ///            Body = "Invitation body",
 ///            RecipientEmail = "*****@*****.**",
 ///            RecipientFirstName = "Recipient first name",
 ///            RecipientLastName = "Recipient last name"
 ///        };
 /// // send invitation
 /// var response = _Client.SendInvitation(options);
 /// // always check response.Result and response.Status before processing
 /// if (result.Result != null &amp;&amp; result.Status == LinkedInResponseStatus.OK)
 /// {
 ///     MessageBox.Show(@"Invitation sent successfully.");
 /// }
 /// </code>
 /// </example>
 public LinkedInResponse<bool> SendInvitation(LinkedInInvitationOptions options)
 {
     if (string.IsNullOrEmpty(options.Subject))
         throw new LinkedInMissingParameterException("Invitation's subject cannot be null or empty", "Subject");
     if (string.IsNullOrEmpty(options.Body))
         throw new LinkedInMissingParameterException("Invitation's body cannot be null or empty", "Body");
     switch (options.InvitationType)
     {
         case LinkedInInvitationType.InviteById:
             if (string.IsNullOrEmpty(options.RecipientId))
                 throw new LinkedInMissingParameterException("Invitation's recipient ID cannot be null or empty", "RecipientId");
             if (string.IsNullOrEmpty(options.AuthorizationName))
                 throw new LinkedInMissingParameterException("Invitation's authorization name cannot be null or empty", "AuthorizationName");
             if (string.IsNullOrEmpty(options.AuthorizationValue))
                 throw new LinkedInMissingParameterException("Invitation's authorization value cannot be null or empty", "AuthorizationValue");
             break;
         case LinkedInInvitationType.InviteByEmail:
             if (string.IsNullOrEmpty(options.RecipientEmail))
                 throw new LinkedInMissingParameterException("Invitation's recipient email cannot be null or empty", "RecipientEmail");
             if (string.IsNullOrEmpty(options.RecipientFirstName))
                 throw new LinkedInMissingParameterException("Invitation's recipient first name cannot be null or empty", "RecipientFirstName");
             if (string.IsNullOrEmpty(options.RecipientLastName))
                 throw new LinkedInMissingParameterException("Invitation's recipient last name cannot be null or empty", "RecipientLastName");
             break;
     }
     return RequestRunner.SendInvitation(options);
 }
Example #3
0
        /// <summary>
        /// Sends invitation to current member
        /// </summary>
        /// <param name="subject">Invitation subject</param>
        /// <param name="body">Invitation body</param>
        /// <returns>Value containing true or false, depending on operation success, and response status</returns>
        /// <exception cref="LinkedInMissingParameterException">Thrown when some of the following is missing: subject, body, <see cref="ApiStandardProfileRquest"/> property or ApiStandardProfileRquest headers</exception>
        public LinkedInResponse<bool> SendInvitation(string subject, string body)
        {
            if (string.IsNullOrEmpty(subject))
                throw new LinkedInMissingParameterException("Invitation subject cannot be null or empty", "Subject");
            if (string.IsNullOrEmpty(body))
                throw new LinkedInMissingParameterException("Invitation body cannot be null or empty", "Body");
            if (ApiStandardProfileRquest == null)
                throw new LinkedInMissingParameterException("ApiStandardProfileRquest field is not set", "ApiStandardProfileRquest");
            if (!ApiStandardProfileRquest.Headers.Any())
                throw new LinkedInMissingParameterException("There are no headers in ApiStandardProfileRquest field", "Headers");
            var header = ApiStandardProfileRquest.Headers.First();
            var arr = header.Value.Split(':');

            var options = new LinkedInInvitationOptions
            {
                Body = body,
                Subject = subject,
                RecipientId = Id,
                AuthorizationName = arr[0],
                AuthorizationValue = arr[1]
            };
            return RequestRunner.SendInvitation(options);
        }