Пример #1
0
        public override object Deserialize(JsonValue json, JsonMapper mapper)
        {
            LinkedInFullProfile profile = (LinkedInFullProfile)base.Deserialize(json, mapper);

            profile.Associations             = json.GetValueOrDefault <string>("associations", String.Empty);
            profile.BirthDate                = DeserializeLinkedInDate(json.GetValue("dateOfBirth"));
            profile.ConnectionsCount         = json.GetValue <int>("numConnections");
            profile.Distance                 = json.GetValue <int>("distance");
            profile.Educations               = DeserializeEducations(json.GetValue("educations"));
            profile.Email                    = json.GetValueOrDefault <string>("emailAddress");
            profile.Honors                   = json.GetValueOrDefault <string>("honors", String.Empty);
            profile.ImAccounts               = DeserializeImAccounts(json.GetValue("imAccounts"));
            profile.Interests                = json.GetValueOrDefault <string>("interests", String.Empty);
            profile.IsConnectionsCountCapped = json.GetValue <bool>("numConnectionsCapped");
            JsonValue locationJson = json.GetValue("location");

            profile.CountryCode       = locationJson.GetValue("country").GetValue <string>("code");
            profile.Location          = locationJson.GetValueOrDefault <string>("name", String.Empty);
            profile.MainAddress       = json.GetValueOrDefault <string>("mainAddress", String.Empty);
            profile.PhoneNumbers      = DeserializePhoneNumbers(json.GetValue("phoneNumbers"));
            profile.Positions         = DeserializePositions(json.GetValue("positions"));
            profile.ProposalComments  = json.GetValueOrDefault <string>("proposalComments", String.Empty);
            profile.Recommendations   = DeserializeRecommendations(json.GetValue("recommendationsReceived"), mapper);
            profile.RecommendersCount = json.GetValueOrDefault <int?>("numRecommenders");
            profile.Specialties       = json.GetValueOrDefault <string>("specialties", String.Empty);
            profile.TwitterAccounts   = DeserializeTwitterAccounts(json.GetValue("twitterAccounts"));
            profile.UrlResources      = DeserializeUrlResources(json.GetValue("memberUrlResources"));
            profile.Certifications    = DeserializeCertifications(json.GetValue("certifications"));
            profile.Skills            = DeserializeSkills(json.GetValue("skills"));
            profile.Publications      = DeserializePublications(json.GetValue("publications"));
            profile.Courses           = DeserializeCourses(json.GetValue("courses"));
            profile.Languages         = DeserializeLanguages(json.GetValue("languages"));

            return(profile);
        }
Пример #2
0
        public LinkedInFullProfile GetFullProfile(string accessToken)
        {
            if (string.IsNullOrEmpty(accessToken) == true)
            {
                throw new ArgumentNullException(nameof(accessToken));
            }
            //
            LinkedInFullProfile ret = null;

            //
            using (var client = new LinkedInApiClient(this.OwinContext.Request, accessToken))
            {
                var profileApi = new LinkedInProfileApi(client);
                var task       = profileApi.GetFullProfileAsync();
                task.Wait(LinkedInSettings.Default.Timeout);
                ret = task.Result;
            }
            //
            return(ret);
        }
Пример #3
0
        public LinkedInResponse GetFullProfile()
        {
            LinkedInResponse ret = new LinkedInResponse();

            //
            try
            {
                using (LinkedInLogic linkedInLogic = new LinkedInLogic())
                {
                    ApplicationUser user = linkedInLogic.EnsureUserIsAuthenticated();
                    //
                    string accessToken = linkedInLogic.GetAccessToken(user);
                    if (string.IsNullOrEmpty(accessToken) == true)
                    {
                        throw new UserNotAuthenticatedException();
                    }
                    //
                    LinkedInFullProfile profile = linkedInLogic.GetFullProfile(accessToken);
                    if (profile == null)
                    {
                        throw new ArgumentNullException(nameof(profile));
                    }
                    //
                    string json = JsonConvert.SerializeObject(profile);
                    ret = new LinkedInResponse()
                    {
                        Status = "ok", ErrorMessage = null, RedirectUrl = null, JSON = json,
                    };
                }
            }
            catch (UserNotAuthenticatedException ex) { ret = new LinkedInResponse()
                                                       {
                                                           Status = "error", ErrorMessage = ex.Message, RedirectUrl = getChallengeRedirectUrl(), JSON = null,
                                                       }; }
            catch (Exception ex) { ret = new LinkedInResponse()
                                   {
                                       Status = "error", ErrorMessage = ex.Message, RedirectUrl = null, JSON = null,
                                   }; }
            //
            return(ret);
        }
        public void GetUserFullProfile()
        {
            mockServer.ExpectNewRequest()
            .AndExpect(UriStartsWith("https://api.linkedin.com/v1/people/~:("))
            .AndExpectMethod(HttpMethod.GET)
            .AndRespondWith(JsonResource("FullProfile"), responseHeaders);

#if NET_4_0 || SILVERLIGHT_5
            LinkedInFullProfile profile = linkedIn.ProfileOperations.GetUserFullProfileAsync().Result;
#else
            LinkedInFullProfile profile = linkedIn.ProfileOperations.GetUserFullProfile();
#endif

            AssertProfile(profile, "UB2kruYmAL", "Software Architect", "Robert", "Drysdale", "Telecommunications",
                          "http://media.linkedin.com/pictureUrl", "J2EE Application Architect with over 10 years industry experience.",
                          "http://www.linkedin.com/in/robdrysdale", "http://www.linkedin.com/profile?viewProfile=&key=15567709&authToken=O91G&authType=name&trk=api*a151944*s160233*", "name:O91G");

            Assert.AreEqual("Canoeing Ireland", profile.Associations);
            Assert.AreEqual("None", profile.Honors);
            Assert.AreEqual(206, profile.Specialties.Length);
            Assert.AreEqual(2, profile.RecommendersCount);
            Assert.AreEqual("Telecommunications", profile.Industry);
            Assert.AreEqual("Kayaking", profile.Interests);
            Assert.AreEqual("ie", profile.CountryCode);
            Assert.AreEqual("Ireland", profile.Location);
            Assert.AreEqual(189, profile.ConnectionsCount);
            Assert.AreEqual(false, profile.IsConnectionsCountCapped);
            Assert.AreEqual("Dublin, Ireland", profile.MainAddress);
            Assert.IsNull(profile.Email);
            Assert.AreEqual(0, profile.Distance);
            Assert.AreEqual("", profile.ProposalComments);
            Assert.AreEqual(1900, profile.BirthDate.Year);
            Assert.AreEqual(1, profile.BirthDate.Month);
            Assert.AreEqual(1, profile.BirthDate.Day);
            Assert.AreEqual(1, profile.ImAccounts.Count);
            Assert.AreEqual("skype", profile.ImAccounts[0].Type);
            Assert.AreEqual("robbiedrysdale", profile.ImAccounts[0].Name);
            Assert.AreEqual(1, profile.PhoneNumbers.Count);
            Assert.AreEqual("mobile", profile.PhoneNumbers[0].Type);
            Assert.AreEqual("+353 87 9580000", profile.PhoneNumbers[0].Number);
            Assert.AreEqual(1, profile.UrlResources.Count);
            Assert.AreEqual("Company Website", profile.UrlResources[0].Name);
            Assert.AreEqual("http://www.robatron.com", profile.UrlResources[0].Url);
            Assert.AreEqual(3, profile.Skills.Count);
            Assert.AreEqual("Java", profile.Skills[0].Name);
            Assert.AreEqual(1, profile.TwitterAccounts.Count);
            Assert.AreEqual("23438000", profile.TwitterAccounts[0].ID);
            Assert.AreEqual("robdrysdale", profile.TwitterAccounts[0].Name);
            Assert.AreEqual(8, profile.Positions.Count);
            Assert.AreEqual("133861560", profile.Positions[0].ID);
            Assert.AreEqual(true, profile.Positions[0].IsCurrent);
            Assert.AreEqual(2010, profile.Positions[0].StartDate.Year);
            Assert.AreEqual(6, profile.Positions[0].StartDate.Month);
            Assert.IsNull(profile.Positions[0].StartDate.Day);
            Assert.AreEqual("CBW at robatron, a Media Streaming startup.  Ongoing Technology research into potential new products.", profile.Positions[0].Summary);
            Assert.AreEqual("CBW", profile.Positions[0].Title);
            Assert.AreEqual("Computer Software", profile.Positions[0].Company.Industry);
            Assert.AreEqual("robatron", profile.Positions[0].Company.Name);
            Assert.AreEqual(3, profile.Educations.Count);
            Assert.AreEqual(11962179, profile.Educations[0].ID);
            Assert.AreEqual("MSc Innovation & Technology Management", profile.Educations[0].Degree);
            Assert.AreEqual("University College Dublin", profile.Educations[0].SchoolName);
            Assert.AreEqual("Product Management, Project Management, New Business Development, Portfolio Managment, Supply Chain", profile.Educations[0].StudyField);
            Assert.AreEqual("Activities", profile.Educations[0].Activities);
            Assert.AreEqual("Notes", profile.Educations[0].Notes);
            Assert.AreEqual(2009, profile.Educations[0].EndDate.Year);
            Assert.AreEqual(2007, profile.Educations[0].StartDate.Year);
            Assert.AreEqual(2, profile.Recommendations.Count);
            Assert.AreEqual(236, profile.Recommendations[0].Text.Length);
            Assert.AreEqual(RecommendationType.Colleague, profile.Recommendations[0].Type);
            Assert.AreEqual("Damien", profile.Recommendations[0].Recommender.FirstName);
        }