Beispiel #1
0
        public static string ToPairsString(this Pairs pairs)
        {
            var query = string.Empty;
            var i     = 0;

            if (pairs == null)
            {
                return(query);
            }
            foreach (var para in pairs.Where(para => !para.Value.IsEmpty()))
            {
                query += $"{(i > 0 ? "&" : "?")}{para.Key}={para.Value}";
                i++;
            }

            return(query);
        }
Beispiel #2
0
        public async Task <XmlDocument> GetXmlAsync(string api, CancellationToken token = new CancellationToken(), Pairs pairs = null)
        {
            var query = pairs.ToPairsString();
            var xml   = new XmlDocument();

            try
            {
                var response = await Client.GetAsync($"{api}{query}", token);

                var s = await response.Content.ReadAsStringAsync();

                xml.LoadXml(s);
            }
            catch (Exception e)
            {
                Extend.ShowMessage(e.Message);
                Extend.Log(e);
                return(null);
            }
            return(xml);
        }
Beispiel #3
0
        public async Task <dynamic> GetJsonAsync(string api, CancellationToken token = new CancellationToken(), Pairs parapairs = null)
        {
            var query = parapairs.ToPairsString();

            try
            {
                var response = await Client.GetAsync($"{api}{query}", token);

                var s = await response.Content.ReadAsStringAsync();

                return(JsonConvert.DeserializeObject(s));
            }
            catch (Exception e)
            {
                Extend.Log(e);
                Extend.ShowMessage(e.Message);
                return(null);
            }
        }