예제 #1
0
        public static async Task <Planet> Get(int id)
        {
            string data;

            using (HttpClient client = WebClientFactory.GetClient())
            {
                data = await client.GetStringAsync(string.Format("{0}/planets/{1}/", Settings.RootUrl, id));
            }
            TextReader textreader = new StringReader(data);
            JsonReader reader     = new JsonTextReader(textreader);
            Planet     planet     = JsonSerializer.Create().Deserialize <Planet>(reader);

            planet.extractIds();
            return(planet);
        }
예제 #2
0
        public static async Task <Character> Get(int id)
        {
            string data;

            using (HttpClient client = WebClientFactory.GetClient())
            {
                data = await client.GetStringAsync(string.Format("{0}/people/{1}/", Settings.RootUrl, id));
            }
            TextReader textreader = new StringReader(data);
            JsonReader reader     = new JsonTextReader(textreader);
            Character  character  = JsonSerializer.Create().Deserialize <Character>(reader);

            character.extractIds();
            return(character);
        }
예제 #3
0
        public static async Task <Vehicle> Get(int id)
        {
            string data;

            using (HttpClient client = WebClientFactory.GetClient())
            {
                data = await client.GetStringAsync(string.Format("{0}/vehicles/{1}/", Settings.RootUrl, id));
            }
            TextReader textreader = new StringReader(data);
            JsonReader reader     = new JsonTextReader(textreader);
            Vehicle    vehicle    = JsonSerializer.Create().Deserialize <Vehicle>(reader);

            vehicle.extractIds();

            return(vehicle);
        }
예제 #4
0
        public static async Task <Film> Get(int id)
        {
            string data;

            using (HttpClient client = WebClientFactory.GetClient())
            {
                data = await client.GetStringAsync(string.Format("{0}/films/{1}/", Settings.RootUrl, id));
            }
            TextReader textreader = new StringReader(data);
            JsonReader reader     = new JsonTextReader(textreader);
            Film       film       = JsonSerializer.Create().Deserialize <Film>(reader);

            film.ExtractIds();

            return(film);
        }
예제 #5
0
        public static async Task <Starship> Get(int id)
        {
            string data;

            using (HttpClient client = WebClientFactory.GetClient())
            {
                data = await client.GetStringAsync(string.Format("{0}/starships/{1}/", Settings.RootUrl, id));
            }
            TextReader textreader = new StringReader(data);
            JsonReader reader     = new JsonTextReader(textreader);
            Starship   ship       = JsonSerializer.Create().Deserialize <Starship>(reader);

            ship.extractIds();

            return(ship);
        }
예제 #6
0
        public static async Task <List <Planet> > GetPage(int pageNumber = 1)
        {
            string data;

            using (HttpClient client = WebClientFactory.GetClient())
            {
                data = await client.GetStringAsync(string.Format("{0}/planets/?page={1}", Settings.RootUrl, pageNumber));
            }
            StringReader  stringreader = new StringReader(data);
            JsonReader    jsonReader   = new JsonTextReader(stringreader);
            List <Planet> planets      = JsonSerializer.Create().Deserialize <BulkGet <Planet> >(jsonReader).items;

            foreach (Planet planet in planets)
            {
                planet.extractIds();
            }
            return(planets);
        }
예제 #7
0
        public static async Task <Species> Get(int id)
        {
            string data;

            using (HttpClient client = WebClientFactory.GetClient())
            {
                data = await client.GetStringAsync(string.Format("{0}/species/{1}/", Settings.RootUrl, id));
            }
            TextReader textreader = new StringReader(data);
            JsonReader reader     = new JsonTextReader(textreader);
            Species    species    = JsonSerializer.Create().Deserialize <Species>(reader);

            species.Homeworld = extractId(species.HomeworldUri);

            species.extractIds();

            return(species);
        }
예제 #8
0
        public static async Task <List <Film> > GetPage(int pageNumber = 1)
        {
            Uri nextPageUri = new Uri(string.Format("{0}/films/?page={1}", Settings.RootUrl, pageNumber));

            BulkGet <Film> films = new BulkGet <Film>();
            string         data;
            StringReader   stringreader;
            JsonReader     jsonReader;

            using (HttpClient client = WebClientFactory.GetClient())
            {
                data = await client.GetStringAsync(nextPageUri);

                stringreader = new StringReader(data);
                jsonReader   = new JsonTextReader(stringreader);
                films        = JsonSerializer.Create().Deserialize <BulkGet <Film> >(jsonReader);
            }
            foreach (Film film in films.items)
            {
                film.ExtractIds();
            }

            return(films.items);
        }
예제 #9
0
        public static async Task <List <Character> > GetPage(int pageNumber = 1)
        {
            string              data;
            StringReader        stringreader;
            JsonReader          jsonReader;
            BulkGet <Character> characters;

            Uri nextPageUri = new Uri(string.Format("{0}/people/?page={1}", Settings.RootUrl, pageNumber));

            using (HttpClient client = WebClientFactory.GetClient())
            {
                data = await client.GetStringAsync(nextPageUri);

                stringreader = new StringReader(data);
                jsonReader   = new JsonTextReader(stringreader);
                characters   = JsonSerializer.Create().Deserialize <BulkGet <Character> >(jsonReader);
            }

            foreach (Character character in characters.items)
            {
                character.extractIds();
            }
            return(characters.items);
        }