/// <summary> /// Initializes new instance of LinkedInSearchOptions /// </summary> public LinkedInSearchOptions() { Keywords = new List<string>(); MemberFieldOptions = new LinkedInGetMemberOptions(); FacetFields = new BitField<LinkedInFacetFields>(); BucketFields = new BitField<LinkedInBucketFields>(); FacetLanguageValues = new List<LinkedInFacetLanguage>(); FacetLocationValues = new List<string>(); FacetIndustryValues = new List<string>(); FacetCurrentCompanyValues = new List<string>(); FacetPastCompanyValues = new List<string>(); FacetSchoolValues = new List<string>(); }
/// <summary> /// Initializes new instance of LinkedInSearchOptions /// </summary> public LinkedInSearchOptions() { Keywords = new List <string>(); MemberFieldOptions = new LinkedInGetMemberOptions(); FacetFields = new BitField <LinkedInFacetFields>(); BucketFields = new BitField <LinkedInBucketFields>(); FacetLanguageValues = new List <LinkedInFacetLanguage>(); FacetLocationValues = new List <string>(); FacetIndustryValues = new List <string>(); FacetCurrentCompanyValues = new List <string>(); FacetPastCompanyValues = new List <string>(); FacetSchoolValues = new List <string>(); }
/// <summary> /// Gets LinkedIn member details /// </summary> /// <param name="options">The object of type <see cref="LinkedInGetMemberOptions"/> representing retrieval options</param> /// <returns>Value containing <see cref="LinkedInMember"/> object and response status</returns> /// <exception cref="LinkedInMissingMemberIdException">Thrown when member is requested by id, but no member Id is set</exception> /// <exception cref="LinkedInMissingProfileUrlException">Thrown when member is requested by public URL, but no URL is set</exception> /// <exception cref="LinkedInInvalidProfileUrlException">Thrown when member is requested by public URL, but URL is not well formed</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 retrieval options /// var options = new LinkedInGetMemberOptions(); /// options.BasicProfileOptions.SelectAll(); /// options.EmailProfileOptions.SelectAll(); /// options.FullProfileOptions.SelectAll(); /// // get member by ID /// options.Parameters.GetBy = LinkedInGetMemberBy.Id; /// options.Parameters.RequestBy = "12345"; /// // call the method /// var response = _client.GetMember(options); /// // always check response.Result and response.Status before processing /// if (response.Result != null && response.Status == LinkedInResponseStatus.OK) /// { /// Console.WriteLine(@"Member name: {0} {1}", response.Result.BasicProfile.FirstName, /// response.Result.BasicProfile.LastName); /// } /// else /// { /// // show possible error message LinkedIn response /// MessageBox.Show(response.Message); /// } /// </code> /// </example> public LinkedInResponse<LinkedInMember> GetMember(LinkedInGetMemberOptions options) { switch (options.Parameters.GetBy) { case LinkedInGetMemberBy.Id: if (string.IsNullOrEmpty(options.Parameters.RequestBy)) throw new LinkedInMissingMemberIdException("Member Id is not set", "RequestBy"); break; case LinkedInGetMemberBy.Url: if (string.IsNullOrEmpty(options.Parameters.RequestBy)) throw new LinkedInMissingProfileUrlException("User profile url is not set", "RequestBy"); if (!Uri.IsWellFormedUriString(options.Parameters.RequestBy, UriKind.RelativeOrAbsolute)) throw new LinkedInInvalidProfileUrlException("Invalid user profile url", "RequestBy"); break; } return RequestRunner.GetMember(options); }
/// <summary> /// Gets LinkedIn member details asynchronously /// </summary> /// <param name="options">The object of type <see cref="LinkedInGetMemberOptions"/> representing retrieval options</param> /// <param name="action">Action to be invoked when retrieval process ends</param> /// <returns>Status of asynchronus operation</returns> /// <exception cref="LinkedInMissingMemberIdException">Thrown when member is requested by id, but no member Id is set</exception> /// <exception cref="LinkedInMissingProfileUrlException">Thrown when member is requested by public URL, but no URL is set</exception> /// <exception cref="LinkedInInvalidProfileUrlException">Thrown when member is requested by public URL, but URL is not well formed</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 retrieval options /// var options = new LinkedInGetMemberOptions(); /// options.BasicProfileOptions.SelectAll(); /// options.EmailProfileOptions.SelectAll(); /// options.FullProfileOptions.SelectAll(); /// // get currently logged in user /// options.Parameters.GetBy = LinkedInGetMemberBy.Self; /// // call the method where processProfile is application defined callback function /// _client.GetMember(options, processProfile); /// /// ... /// /// // application defined function /// private void processProfile(LinkedInResponse<LinkedInMember> response) /// { /// // always check response.Result and response.Status before processing /// if (response.Result != null && response.Status == LinkedInResponseStatus.OK) /// { /// Console.WriteLine(@"Member name: {0} {1}", response.Result.BasicProfile.FirstName, /// response.Result.BasicProfile.LastName); /// } /// else /// { /// // show possible error message LinkedIn response /// MessageBox.Show(response.Message); /// } /// } /// </code> /// </example> public IAsyncResult GetMember(LinkedInGetMemberOptions options, Action<LinkedInResponse<LinkedInMember>> action) { switch (options.Parameters.GetBy) { case LinkedInGetMemberBy.Id: if (string.IsNullOrEmpty(options.Parameters.RequestBy)) throw new LinkedInMissingMemberIdException("Member Id is not set", "RequestBy"); break; case LinkedInGetMemberBy.Url: if (string.IsNullOrEmpty(options.Parameters.RequestBy)) throw new LinkedInMissingProfileUrlException("User profile url is not set", "RequestBy"); if ( !Uri.IsWellFormedUriString(options.Parameters.RequestBy, UriKind.RelativeOrAbsolute)) throw new LinkedInInvalidProfileUrlException("Invalid user profile url", "RequestBy"); break; } GetMemberDelegate _delegate = GetMember; return _delegate.BeginInvoke(options, getMemberCallback, action); }
internal static LinkedInResponse<LinkedInMember> GetMember(LinkedInGetMemberOptions options) { var sb = new StringBuilder(); var fieldsParams = RequestFields.PrepareMemberFields(options); switch (options.Parameters.GetBy) { case LinkedInGetMemberBy.Self: sb.Append(Utils.PROFILE_SELF_URL); break; case LinkedInGetMemberBy.Id: sb.Append(Utils.PROFILE_BY_ID_URL); sb.Append(options.Parameters.RequestBy); break; default: //LinkedInGetMemberBy.Url sb.Append(Utils.PROFILE_BY_URL_URL); sb.Append(Utils.NormalizeUrl(options.Parameters.RequestBy)); break; } if (!string.IsNullOrEmpty(fieldsParams)) sb.Append(fieldsParams); sb.Append("?oauth2_access_token="); sb.Append(Singleton.Instance.AccessToken); return getMember(sb.ToString(), options); }
private static LinkedInResponse<LinkedInMember> getMember(string request, LinkedInGetMemberOptions options) { try { string responseString; switch (options.Parameters.GetBy) { case LinkedInGetMemberBy.Url: var getSyntax = typeof(UriParser).GetMethod("GetSyntax", BindingFlags.Static | BindingFlags.NonPublic); var flagsField = typeof(UriParser).GetField("m_Flags", BindingFlags.Instance | BindingFlags.NonPublic); setCompressionFlag(getSyntax, flagsField, false); try { responseString = Utils.MakeRequest(request, "GET"); } finally { setCompressionFlag(getSyntax, flagsField, true); } break; default: responseString = Utils.MakeRequest(request, "GET"); break; } var xdoc = XDocument.Parse(responseString); var result = xdoc.Root != null ? Utils.BuildMember(xdoc.Root) : null; return new LinkedInResponse<LinkedInMember>(result, LinkedInResponseStatus.OK, null); } catch (WebException wex) { return Utils.GetResponse<LinkedInMember>(null, wex, null); } catch (Exception ex) { return new LinkedInResponse<LinkedInMember>(null, LinkedInResponseStatus.OtherException, null, ex); } }
internal static string PrepareMemberFields(LinkedInGetMemberOptions options) { var fields = new StringBuilder(); var addFields = options.BasicProfileOptions.HasValues | options.EmailProfileOptions.HasValues | options.FullProfileOptions.HasValues; if (addFields) { fields.Append(":("); } if (options.BasicProfileOptions.HasValues) { if (options.BasicProfileOptions[LinkedInBasicProfileFields.Id]) fields.Append("id,"); if (options.BasicProfileOptions[LinkedInBasicProfileFields.FirstName]) fields.Append("first-name,"); if (options.BasicProfileOptions[LinkedInBasicProfileFields.LastName]) fields.Append("last-name,"); if (options.BasicProfileOptions[LinkedInBasicProfileFields.MaidenName]) fields.Append("maiden-name,"); if (options.BasicProfileOptions[LinkedInBasicProfileFields.FormattedName]) fields.Append("formatted-name,"); if (options.BasicProfileOptions[LinkedInBasicProfileFields.PhoneticFirstName]) fields.Append("phonetic-first-name,"); if (options.BasicProfileOptions[LinkedInBasicProfileFields.PhoneticLastName]) fields.Append("phonetic-last-name,"); if (options.BasicProfileOptions[LinkedInBasicProfileFields.FormattedPhoneticName]) fields.Append("formatted-phonetic-name,"); if (options.BasicProfileOptions[LinkedInBasicProfileFields.Headline]) fields.Append("headline,"); if (options.BasicProfileOptions[LinkedInBasicProfileFields.Location]) fields.Append("location,"); if (options.BasicProfileOptions[LinkedInBasicProfileFields.Industry]) fields.Append("industry,"); if (options.BasicProfileOptions[LinkedInBasicProfileFields.Distance]) fields.Append("distance,"); if (options.BasicProfileOptions[LinkedInBasicProfileFields.RelationToViewer]) fields.Append("relation-to-viewer,"); if (options.BasicProfileOptions[LinkedInBasicProfileFields.CurrentShare]) fields.Append("current-share,"); if (options.BasicProfileOptions[LinkedInBasicProfileFields.NumConnections]) fields.Append("num-connections,"); if (options.BasicProfileOptions[LinkedInBasicProfileFields.NumConnectionsCapped]) fields.Append("num-connections-capped,"); if (options.BasicProfileOptions[LinkedInBasicProfileFields.Summary]) fields.Append("summary,"); if (options.BasicProfileOptions[LinkedInBasicProfileFields.Specialities]) fields.Append("specialties,"); if (options.BasicProfileOptions[LinkedInBasicProfileFields.Positions]) fields.Append("positions:(id,title,summary,start-date,end-date,is-current,company:(id,name,type,size,industry,ticker)),"); if (options.BasicProfileOptions[LinkedInBasicProfileFields.PictureUrl]) fields.Append("picture-url,"); if (options.BasicProfileOptions[LinkedInBasicProfileFields.SiteStandardProfileRequest]) fields.Append("site-standard-profile-request,"); if (options.BasicProfileOptions[LinkedInBasicProfileFields.ApiStandardProfileRequest]) fields.Append("api-standard-profile-request,"); if (options.BasicProfileOptions[LinkedInBasicProfileFields.PublicProfileUrl]) fields.Append("public-profile-url,"); } if (options.EmailProfileOptions.HasValues) { if (options.EmailProfileOptions[LinkedInEmailProfileFields.EmailAddress]) fields.Append("email-address,"); } if (options.FullProfileOptions.HasValues) { if (options.FullProfileOptions[LinkedInFullProfileFields.LastModifiedTimestamp]) fields.Append("last-modified-timestamp,"); if (options.FullProfileOptions[LinkedInFullProfileFields.ProposalComments]) fields.Append("proposal-comments,"); if (options.FullProfileOptions[LinkedInFullProfileFields.Associations]) fields.Append("associations,"); if (options.FullProfileOptions[LinkedInFullProfileFields.Interests]) fields.Append("interests,"); if (options.FullProfileOptions[LinkedInFullProfileFields.Publications]) fields.Append("publications:(id,title,publisher,authors,date,url,summary),"); if (options.FullProfileOptions[LinkedInFullProfileFields.Patents]) fields.Append("patents:(id,title,summary,number,status,office,inventors,date,url),"); if (options.FullProfileOptions[LinkedInFullProfileFields.Languages]) fields.Append("languages:(id,language,proficiency),"); if (options.FullProfileOptions[LinkedInFullProfileFields.Skills]) fields.Append("skills,"); if (options.FullProfileOptions[LinkedInFullProfileFields.Certifications]) fields.Append("certifications:(id,name,authority,number,start-date,end-date),"); if (options.FullProfileOptions[LinkedInFullProfileFields.Educations]) fields.Append("educations,"); if (options.FullProfileOptions[LinkedInFullProfileFields.Courses]) fields.Append("courses,"); if (options.FullProfileOptions[LinkedInFullProfileFields.Volunteer]) fields.Append("volunteer:(volunteer-experiences:(id,role,organization,cause)),"); if (options.FullProfileOptions[LinkedInFullProfileFields.ThreeCurrentPositions]) fields.Append("three-current-positions,"); if (options.FullProfileOptions[LinkedInFullProfileFields.ThreeLastPositions]) fields.Append("three-past-positions,"); if (options.FullProfileOptions[LinkedInFullProfileFields.NumRecommenders]) fields.Append("num-recommenders,"); if (options.FullProfileOptions[LinkedInFullProfileFields.RecommendationsReceived]) fields.Append("recommendations-received,"); if (options.FullProfileOptions[LinkedInFullProfileFields.MfeedRssUrl]) fields.Append("mfeed-rss-url,"); if (options.FullProfileOptions[LinkedInFullProfileFields.Following]) fields.Append("following,"); if (options.FullProfileOptions[LinkedInFullProfileFields.JobBookmarks]) fields.Append("job-bookmarks,"); if (options.FullProfileOptions[LinkedInFullProfileFields.Suggestions]) fields.Append("suggestions,"); if (options.FullProfileOptions[LinkedInFullProfileFields.DateOfBirth]) fields.Append("date-of-birth,"); if (options.FullProfileOptions[LinkedInFullProfileFields.MemberUrlResources]) fields.Append("member-url-resources,"); if (options.FullProfileOptions[LinkedInFullProfileFields.RelatedProfileViews]) fields.Append("related-profile-views,"); } if (addFields) { if (fields.Length > 2) fields.Length -= 1; fields.Append(")"); } return fields.ToString(); }