示例#1
0
        public async Task <FavoritesRES> GetSingle(string id)
        {
            Universal    universal    = new Universal();
            FavoritesRES favoritesRES = await universal.GET <FavoritesRES>("favorites/", id, true);

            Console.WriteLine($"{favoritesRES.id}");
            Console.WriteLine($"Grabbed favorite {favoritesRES.favoriteId} type of {favoritesRES.typeOptions}");
            Console.WriteLine();

            return(favoritesRES);
        }
示例#2
0
        public async Task <FavoritesRES> New(TypeOptions?typeOptions, string favoriteId)
        {
            string type = "";

            switch (typeOptions.Value)
            {
            case TypeOptions.Avatar:
                type = "avatar";
                break;

            case TypeOptions.Friend:
                type = "friend";
                break;

            case TypeOptions.World:
                type = "world";
                break;
            }

            JObject json = new JObject();

            json["type"]       = type;
            json["favoriteId"] = favoriteId;

            StringContent content = new StringContent(json.ToString(), Encoding.UTF8);

            content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

            HttpResponseMessage response = await httpClient.PostAsync($"favorites{apiKey}", content);

            FavoritesRES res = null;

            if (response.IsSuccessStatusCode)
            {
                var receivedJson = await response.Content.ReadAsStringAsync();

                res = JsonConvert.DeserializeObject <FavoritesRES>(receivedJson);

                Console.WriteLine($"{res.id}");
                Console.WriteLine($"Posted new favorite: {res.favoriteId}");
                Console.WriteLine();
            }

            return(res);
        }