示例#1
0
        private static void Exploration()
        {
            //pepere bailey
            //var personId = "L899-5WF";
            var personId = "L5ND-KKY";
            //production?
            //var username = "******";
            //var password = "******";
            //integration
            var username = "******";
            var password = "******";

            var applicationKey = "a02f100000TbRwqAAF";
            //integration
            var ft = new FamilySearchSDK(username, password, applicationKey, "SampleConsoleApp", "1.0.0", Gedcomx.Api.Lite.Environment.Integration);
            //production
            //var ft = new FamilySearchSDK(username, password, applicationKey, "SampleConsoleApp", "1.0.0", Gedcomx.Api.Lite.Environment.Production);

            //404 error
            var response = ft.Get("/platform/tree/persons/" + personId).Result;

            var encoded      = Uri.EscapeDataString("motherGivenName:Clarissa~ fatherSurname:Heaton~ motherSurname:Hoyt~ surname:Heaton~ givenName:Israel~ fatherGivenName:Jonathan~");
            var searchResult = ft.Get("/platform/tree/search?q=" + encoded, MediaType.X_GEDCOMX_ATOM_JSON).Result;
            //Console.WriteLine($"Found close hits {searchResult.searchInfo[0].closeHits} with {searchResult.searchInfo[0].totalHits} total");

            var matchSearch = ft.Get("/platform/tree/persons/L5ND-KKY/matches?collection=https://familysearch.org/platform/collections/records").Result;

            Console.WriteLine(matchSearch.ToString());
        }
示例#2
0
        public static void Main(string[] args)
        {
            var ft = new FamilySearchSDK("username", "password", "applicationKey", "Example2.Core", "1.0.0", Gedcomx.Api.Lite.Environment.Integration);

            // Search for a Person
            var searchString = $" surname:Smith~ givenName:John~";
            var encoded      = Uri.EscapeDataString(searchString);
            var searchResult = ft.Get("/platform/tree/search?q=" + encoded, MediaType.X_GEDCOMX_ATOM_JSON).Result;

            var stopCount    = 1000;
            var totalFetched = 0;

            while (searchResult != null &&
                   (totalFetched <= searchResult.results.Value || totalFetched > stopCount))
            {
                totalFetched = (searchResult.index + searchResult.entries.Count);
                foreach (var e in searchResult.entries)
                {
                    var p = e.content.gedcomx.persons[0];
                    Console.WriteLine($"{p.id} - {p.display.name} birthDate {p.display.birthDate} birthPlace {p.display.birthPlace}");
                }

                // Advance & get the next search results if there.
                if (searchResult.results > (searchResult.index + searchResult.entries.Count))
                {
                    Console.WriteLine($"fetching another. total={totalFetched}");
                    searchResult = ft.Get(searchResult.links.next.href.Value, MediaType.X_GEDCOMX_ATOM_JSON).Result;
                }
            }

            Console.ReadLine();
        }
        public List <Person> Search(string authToken, string surname, string givenName)
        {
            var searchString = "";

            if (!string.IsNullOrEmpty(surname))
            {
                searchString += $" surname:{surname}~ ";
            }
            if (!string.IsNullOrEmpty(givenName))
            {
                searchString += $" givenName:{givenName}~ ";
            }
            var encoded = Uri.EscapeDataString(searchString);

            // Pass in the auth token to our familysearch api
            var ft           = new FamilySearchSDK(authToken, "NotPassed", "FamilySearchAncestorMap.Core", "1.0.0", _config.Value.Environment);
            var searchResult = ft.Get("/platform/tree/search?q=" + encoded, MediaType.X_GEDCOMX_ATOM_JSON).Result;

            var list = new List <Person>();

            foreach (var e in searchResult.entries)
            {
                var p = e.content.gedcomx.persons[0];
                list.Add(new Person()
                {
                    Id    = p.id,
                    Name  = p.display.name,
                    Birth = p.display.birthPlace + " on " + p.display.birthDate,
                    Death = p.display.deathPlace + " on " + p.display.deathDate,
                });
            }
            return(list);
        }
示例#4
0
        public void GetAPerson()
        {
            var ft = new FamilySearchSDK(Settings.Default.UserName, Settings.Default.Password, Settings.Default.ApplicationKey,
                                         TestBacking.AppName, TestBacking.AppVersion, Gedcomx.Api.Lite.Environment.Integration);

            // Create a Person
            var gedcomx = new Gx.Gedcomx();

            gedcomx.AddPerson(TestBacking.GetCreateMalePerson());
            var postResults = ft.Post("/platform/tree/persons", JsonConvert.SerializeObject(gedcomx), MediaType.X_GEDCOMX_v1_JSON).Result;

            // Now get the new person.
            string personId = ((string[])postResults.Headers.Location.ToString().Split('/')).Last();
            var    response = ft.Get("/platform/tree/persons/" + personId).Result;

            Assert.IsNotNull(response.persons, "resonse should contain a person");
        }
示例#5
0
        public void GetAPortrait()
        {
            var ft = new FamilySearchSDK(Settings.Default.UserName, Settings.Default.Password, Settings.Default.ApplicationKey,
                                         TestBacking.AppName, TestBacking.AppVersion, Gedcomx.Api.Lite.Environment.Integration);

            // Create a Person
            var gedcomx = new Gx.Gedcomx();

            gedcomx.AddPerson(TestBacking.GetCreateMalePerson());
            var postResults = ft.Post("/platform/tree/persons", JsonConvert.SerializeObject(gedcomx), MediaType.X_GEDCOMX_v1_JSON).Result;

            // Now get the new person.
            string personId         = ((string[])postResults.Headers.Location.ToString().Split('/')).Last();
            var    portraitResponse = ft.Get($"/platform/tree/persons/{personId}/portrait", MediaType.X_FS_v1_JSON);
            var    portrait         = portraitResponse.Result;

            Assert.IsTrue(postResults.StatusCode == HttpStatusCode.Created, "Portrait should flag the reply as created");
        }
        public List <Person> Ancestry(string authToken, string personId)
        {
            List <Person> list = new List <Person>();

            // TODO: https://familysearch.org/developers/docs/api/tree/Ancestry_resource
            // Add personDetails as a parameter

            var ft  = new FamilySearchSDK(authToken, "NotPassed", "FamilySearchAncestorMap.Core", "1.0.0", _config.Value.Environment);
            var anc = ft.Get("/platform/tree/ancestry?person=" + personId + "&personDetails").Result;

            foreach (var person in anc.persons)
            {
                //var data = ft.Get("/platform/tree/persons/" + p.id).Result;
                //var person = data.persons[0];
                list.Add(new Person()
                {
                    Id           = person.id,
                    Name         = person.display.name,
                    Birth        = person.display.birthPlace + " on " + person.display.birthDate,
                    Death        = person.display.deathPlace + " on " + person.display.deathDate,
                    BirthAddress = person.display.birthPlace,
                    DeathAddress = person.display.deathPlace,
                });
            }

            //var anc = ft.Get("/platform/tree/ancestry?person=" + personId).Result;
            //foreach (var p in anc.persons)
            //{
            //	var data = ft.Get("/platform/tree/persons/" + p.id).Result;
            //	var person = data.persons[0];
            //	list.Add(new Person()
            //	{
            //		Id = person.id,
            //		Name = person.display.name,
            //		Birth = person.display.birthPlace + " on " + person.display.birthDate,
            //		Death = person.display.deathPlace + " on " + person.display.deathDate,
            //		BirthAddress = person.display.birthPlace,
            //		DeathAddress = person.display.deathPlace,
            //	});
            //}

            return(list);
        }
示例#7
0
        private static void TraverseTree(FamilySearchSDK ft, string personId, int generationCount)
        {
            //end the recursion at 5 generations
            if (generationCount > 5)
            {
                return;
            }
            var parsingResult   = new RecordParsingResult();
            var personDetailUrl = "/platform/tree/persons/";
            var personHintsUrl  = "/platform/tree/persons/{0}/matches?collection=https://familysearch.org/platform/collections/records";

            //fetch the person
            var response = ft.Get(personDetailUrl + personId).Result;

            //Console.WriteLine(response.ToString());
            //look for tasks in the person's data
            EvaluatePersonDetails(response, parsingResult);
            if (!parsingResult.IsLiving)
            {
                Console.WriteLine(parsingResult.DetailSuggestions);
            }
            else
            {
                Console.WriteLine("No suggestions for records of living people");
            }
            //look for tasks in the person's parents
            EvaluatePersonParents(response, parsingResult);
            Console.WriteLine(parsingResult.ParentSuggestions);
            //no record hints for living people
            if (!parsingResult.IsLiving)
            {
                //fetch hints
                var matchSearch = ft.Get(String.Format(personHintsUrl, personId)).Result;
                //look for tasks in the hints
                EvaluatePersonHints(matchSearch, parsingResult);
                if (!String.IsNullOrWhiteSpace(parsingResult.HintSuggestions))
                {
                    Console.WriteLine(parsingResult.HintSuggestions);
                }
                //evaluate children and their spouses for tasks
                if (parsingResult.ChildrenIds != null && parsingResult.ChildrenIds.Count > 0)
                {
                    foreach (var childId in parsingResult.ChildrenIds)
                    {
                        var childParsing  = new RecordParsingResult();
                        var childResponse = ft.Get(personDetailUrl + childId).Result;
                        EvaluatePersonDetailsShallow(childResponse, childParsing);
                        if (!childParsing.IsLiving)
                        {
                            Console.WriteLine(childParsing.DetailSuggestions);
                            if (childParsing.SpouseIds != null && childParsing.SpouseIds.Count > 0)
                            {
                                foreach (var inlawId in childParsing.SpouseIds)
                                {
                                    var inlawParsing  = new RecordParsingResult();
                                    var inlawResponse = ft.Get(personDetailUrl + inlawId).Result;
                                    EvaluatePersonDetailsShallow(inlawResponse, inlawParsing);
                                    if (!inlawParsing.IsLiving)
                                    {
                                        Console.WriteLine(inlawParsing.DetailSuggestions);
                                    }
                                }
                            }
                        }
                    }
                }
                if (parsingResult.SpouseIds != null && parsingResult.SpouseIds.Count > 0)
                {
                    foreach (var spouseId in parsingResult.SpouseIds)
                    {
                        var spouseParsing  = new RecordParsingResult();
                        var spouseResponse = ft.Get(personDetailUrl + spouseId).Result;
                        EvaluatePersonDetailsShallow(spouseResponse, spouseParsing);
                        if (!spouseParsing.IsLiving)
                        {
                            Console.WriteLine(spouseParsing.DetailSuggestions);
                        }
                    }
                }
            }
            Console.WriteLine();

            //start recursion
            if (!String.IsNullOrWhiteSpace(parsingResult.FatherId))
            {
                TraverseTree(ft, parsingResult.FatherId, generationCount + 1);
            }
            if (!String.IsNullOrWhiteSpace(parsingResult.MotherId))
            {
                TraverseTree(ft, parsingResult.MotherId, generationCount + 1);
            }
        }
示例#8
0
        static void Main(string[] args)
        {
            var ft = new FamilySearchSDK(Settings.Default.UserName, Settings.Default.Password, Settings.Default.ApplicationKey, "Example1", "1.0.0", Gedcomx.Api.Lite.Environment.Integration);

            // Create a Person
            var gedcomx = new Gx.Gedcomx();

            gedcomx.AddPerson(TestBacking.GetCreateMalePerson());

            // Now post two of them to family search asynchronously
            var postTask  = ft.Post("/platform/tree/persons", JsonConvert.SerializeObject(gedcomx), MediaType.X_GEDCOMX_v1_JSON);
            var postTask2 = ft.Post("/platform/tree/persons", JsonConvert.SerializeObject(gedcomx), MediaType.X_GEDCOMX_v1_JSON);

            Task.WaitAll(postTask, postTask2);
            var postResultSon    = postTask.Result;
            var postResultFather = postTask2.Result;

            // Or if only one and you want synchronous results
            var postResults3 = ft.Post("/platform/tree/persons", JsonConvert.SerializeObject(gedcomx), MediaType.X_GEDCOMX_v1_JSON).Result;

            // Now get the new person.
            string personId = ((string[])postResultSon.Headers.Location.ToString().Split('/')).Last();
            var    response = ft.Get("/platform/tree/persons/" + personId).Result;

            // By presuming we have single element.
            Console.WriteLine(response.persons[0].id + " - " + response.persons[0].display.name);

            // Get a person's portrait
            var portraitResponse = ft.Get($"/platform/tree/persons/{personId}/portrait", MediaType.X_FS_v1_JSON);
            var portrait         = portraitResponse.Result;
            //Console.WriteLine(response.persons[0].id + " - " + response.persons[0].display.name);

            // Set parentage
            List <ChildAndParentsRelationship> relationships = new List <ChildAndParentsRelationship>();

            relationships.Add(new ChildAndParentsRelationship()
            {
                Father = new ResourceReference(postResultFather.Headers.Location.ToString()),
                Child  = new ResourceReference(postResultSon.Headers.Location.ToString())
            });
            // use an array wrapper as we have to name the array.
            var content = JsonConvert.SerializeObject(new { childAndParentsRelationships = relationships }, jsettings);

            var rel     = ft.Post("/platform/tree/relationships", content, MediaType.X_FS_v1_JSON);
            var results = rel.Result;

            // Now read the relationship back. (the Son)
            var anc = ft.Get("/platform/tree/ancestry?person=" + personId).Result;

            Console.WriteLine($"For {personId} then have these ancestors");
            foreach (var a in anc.persons)
            {
                Console.WriteLine(a.id + " - " + a.display.name);
            }


            // Now search!
            //platform/tree/search?q=motherGivenName%3AClarissa~%20fatherSurname%3AHeaton~%20motherSurname%3AHoyt~%20surname%3AHeaton~%20givenName%3AIsrael~%20fatherGivenName%3AJonathan~
            var encoded      = Uri.EscapeDataString("motherGivenName:Clarissa~ fatherSurname:Heaton~ motherSurname:Hoyt~ surname:Heaton~ givenName:Israel~ fatherGivenName:Jonathan~");
            var searchResult = ft.Get("/platform/tree/search?q=" + encoded, MediaType.X_GEDCOMX_ATOM_JSON).Result;

            Console.WriteLine($"Found close hits {searchResult.searchInfo[0].closeHits} with {searchResult.searchInfo[0].totalHits} total");

            var stopCount    = 1000;
            var totalFetched = 0;

            while (searchResult != null &&
                   (totalFetched <= Convert.ToInt32(searchResult.results) || totalFetched > stopCount))
            {
                totalFetched = (searchResult.index + searchResult.entries.Count);
                foreach (var e in searchResult.entries)
                {
                    var p = e.content.gedcomx.persons[0];
                    Console.WriteLine($"{p.id} - {p.display.name} birthDate {p.display.birthDate} birthPlace {p.display.birthPlace}");
                }

                // Advance & get the next search results if there.
                if (searchResult.results > (searchResult.index + searchResult.entries.Count))
                {
                    Console.WriteLine($"fetching another. total={totalFetched}");
                    searchResult = ft.Get(searchResult.links.next.href.Value, MediaType.X_GEDCOMX_ATOM_JSON).Result;
                }
            }

            Console.WriteLine("Press Enter to Exit");
            Console.ReadLine();
        }