Example #1
0
        /// <summary>
        /// Retrieves the list of species for given world region. Supports pagination.
        /// </summary>
        /// <param name="region">Identifier (identifier field) of the region</param>
        /// <param name="page">Number of query page. One page has size 10 000</param>
        /// <returns>SpeciesResponse as defined by IUCN API V3</returns>
        public async Task <SpeciesResponse> GetSpeciesRegionalAssesmentsAsync(string region, uint page)
        {
            SpeciesResponse species = null;

            HttpResponseMessage response = await mClient.GetAsync(Uri.EscapeUriString(string.Format(IucnRedListApiV3UriFormats.SpeciesRegionalAssesments, region, page, cToken)));

            if (response.IsSuccessStatusCode)
            {
                species = await response.Content.ReadAsAsync <SpeciesResponse>();
            }

            return(species);
        }
Example #2
0
        static void Main(string[] args)
        {
            using (IucnRedListApiV3Client client = new IucnRedListApiV3Client())
            {
                RegionsResponse regions = client.GetRegionsAsync().Result;

                if (regions == null)
                {
                    Console.WriteLine("Error ocurred loading the list of regions");
                    Console.ReadKey();
                    return;
                }

                Console.WriteLine("Regions:");

                for (int i = 0; i < regions.Results.Count; i++)
                {
                    Console.WriteLine(string.Format("{0}  {1}", i, regions.Results[i].Name));
                }

                Console.WriteLine();
                Console.WriteLine("Enter number of region");

                string selection = Console.ReadLine();

                int regionNr;

                if (!int.TryParse(selection, out regionNr) ||
                    regionNr < 0 ||
                    regionNr >= regions.Results.Count)
                {
                    Console.WriteLine("Invalid region number");
                    Console.ReadKey();
                    return;
                }

                string region = regions.Results[regionNr].Identifier;

                SpeciesResponse species = client.GetSpeciesRegionalAssesmentsAsync(region, 0).Result;

                if (species == null)
                {
                    Console.WriteLine("Error ocurred loading the list of species");
                    Console.ReadKey();
                    return;
                }

                List <Species> criticallyEndangered = species.Result.Where(s => s.Category == cCriticallyEndangered).ToList();

                Console.WriteLine();
                Console.WriteLine("Critically endangered species:");

                FetchMeasuresAndPrintSpeciesDetails(criticallyEndangered, region, client);

                Console.WriteLine();

                List <Species> mammals = species.Result.Where(s => s.ClassName == cMammals).ToList();

                Console.WriteLine();
                Console.WriteLine("Mammals:");

                FetchMeasuresAndPrintSpeciesDetails(mammals, region, client);

                Console.WriteLine();
            }

            Console.WriteLine("Press any key to quit");

            Console.ReadKey();
        }