Exemplo n.º 1
0
        private string Fetch(string cacheKey, object request)
        {
            string raw;

            try
            {
                var content  = JObject.FromObject(request).ToString().ToLower();
                var response = _http.PostAsync("jsonrpc", new StringContent(content, Encoding.UTF8, "application/json")).Result;
                if (!response.IsSuccessStatusCode)
                {
                    throw new Exception($"Failed to retrieve songs from Kodi. Response code: {response.StatusCode}.");
                }

                raw = response.Content.ReadAsStringAsync().Result;
            }
            catch (Exception e)
            {
                throw new Exception("Failed to retrieve songs from Kodi", e);
            }

            _cache.Save(raw, cacheKey);

            return(raw);
        }