예제 #1
0
        public static async Task <T> CacheOf <T>(int id) where T : ApiObject
        {
            var type = typeof(T);

            if (!ShouldCacheData)
            {
                return(JsonConvert.DeserializeObject <T>(await Client.GetStringAsync(BASE_URL + UrlOfType[type] + SLASH + id)));
            }

            if (!Cache.ContainsKey(type))
            {
                Cache.Add(type, new Dictionary <int, ApiObject>());
            }

            var dictionary = Cache[type];

            if (!dictionary.TryGetValue(id, out var apiObject))
            {
                apiObject = JsonConvert.DeserializeObject <T>(await Client.GetStringAsync(BASE_URL + UrlOfType[type] + SLASH + id));
                dictionary.Add(id, apiObject);
            }

            return((T)apiObject);
        }
예제 #2
0
 static async Task <JsonData> GetJsonAsync(Uri url) => JsonMapper.ToObject(await client.GetStringAsync(url.AbsoluteUri));
예제 #3
0
 static async Task <JsonData> GetJsonAsync(string obj) => JsonMapper.ToObject(await client.GetStringAsync(BASE_URL + obj));