コード例 #1
0
        private void updateAwlPets(AwlApi api)
        {
            HashSet <Id> found = new HashSet <Id>();

            foreach (AwlPet p in api.data)
            {
                Id id = new Id(ORIGIN, p.unique_id);
                found.Add(id);

                Pet pet = allPets.Get(id);
                if (pet == null)
                {
                    pet = p.Create();
                    allPets.Add(pet);
                }
                else
                {
                    p.Update(pet);
                }
            }

            foreach (Pet pet in allPets.GetAll().Where(p => p.Id.Origin == ORIGIN && !found.Contains(p.Id)))
            {
                pet.Status = Status.Adopted;
            }
        }
コード例 #2
0
        private async Task <AwlApi> fetchOnce()
        {
            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, "api/pets");

            request.Content = new StringContent("type=all&lifestyle=all&size=all&age=all&gender=all", Encoding.UTF8);
            HttpResponseMessage response = await client.SendAsync(request);

            string data = await response.Content.ReadAsStringAsync();

            return(AwlApi.parse(data));
        }
コード例 #3
0
        private async Task <AwlApi> fetch()
        {
            AwlApi first = await fetchOnce();

            if (first.message != null && first.message != "")
            {
                string token = await client.GetStringAsync("adopt");

                token = getToken.Match(token).Groups[1].Value;
                client.DefaultRequestHeaders.Add("Authorization", "Bearer " + token);

                return(await fetchOnce());
            }

            return(first);
        }
コード例 #4
0
        public async Task Update()
        {
            AwlApi api = await fetch();

            updateAwlPets(api);
        }