Example #1
0
        public async Task <T> Get <T>(string url)
        {
            Uri uri = new Uri(Config.UrlPrefix + url);
            HttpResponseMessage result = await http.GetAsync(uri);

            if (!result.IsSuccessStatusCode)
            {
                LogError(url, result);
            }
            ;
            var resultContentString = await result.Content.ReadAsStringAsync();

            KKCommonResponse resultObj = serializer.Deserialize <KKCommonResponse>(resultContentString);

            result.Dispose();
            if (resultObj.status != 200)
            {
                var e = new KKHttpException(url, resultObj);
                SentryLogger.Log(e);
                return(default(T));
            }
            var d = serializer.Deserialize <T>(resultObj.data);

            return(d);
        }
Example #2
0
        public async Task <dynamic> Post(string url, dynamic body)
        {
            HttpStringContent content = getJsonContent(body);
            var uri = new Uri(Config.UrlPrefix + url);

            HttpResponseMessage result = await http.PostAsync(uri, content);

            if (!result.IsSuccessStatusCode)
            {
                LogError(url, result);
            }
            ;

            var resultContentString = await result.Content.ReadAsStringAsync();

            KKCommonResponse resultObj = serializer.Deserialize <KKCommonResponse>(resultContentString);

            result.Dispose();
            if (resultObj.status != 200)
            {
                var e = new KKHttpException(url, resultObj);
                SentryLogger.Log(e);
            }
            return(resultObj.data);
        }
Example #3
0
        private async Task <KKCommonResponse> serializeBodyAsync(dynamic result, string url)
        {
            if (!result.IsSuccessStatusCode)
            {
                LogError(url, result);
            }
            ;

            var resultContentString = await result.Content.ReadAsStringAsync();

            KKCommonResponse resultObj = serializer.Deserialize <KKCommonResponse>(resultContentString);

            result.Dispose();
            if (resultObj.status != 200)
            {
                var e = new KKHttpException(url, resultObj);
                SentryLogger.Log(e);
            }
            return(resultObj);
        }