Esempio n. 1
0
        public async Task <HttpResponseMessage> ExecuteRequestAsync(List <Pair <string, string> > parameters = null, JodelRequest payload = null, string urlExtension = null)
        {
            var payloadString = payload != null
                ? JsonConvert.SerializeObject(payload, Formatting.None,
                                              new JsonSerializerSettings
            {
                NullValueHandling = NullValueHandling.Ignore
            })
                : null;

            var dt       = DateTime.Now;
            var urlParam = Url;

            if (!string.IsNullOrWhiteSpace(urlExtension))
            {
                urlParam += urlExtension;
            }
            if (!string.IsNullOrWhiteSpace(PostData))
            {
                urlParam += PostData;
            }

            if (parameters != null)
            {
                urlParam += "?" + string.Join("&", parameters.Select(p => $"{p.First}={p.Second}"));
            }

            var stringifiedUrl = "https://" + Constants.BASE_URL + "/api/" + Version + urlParam;

            var stringifiedPayload = Method.Method + "%" + Constants.BASE_URL + "%443%/api/" + Version + urlParam;

            stringifiedPayload += "%" + User.AccessToken;
            stringifiedPayload += "%" + $"{dt:s}Z" + "%%" + payloadString;

            try
            {
                var client = JodelHttpClient.Create(dt, stringifiedPayload, User.AccessToken, Method);
                return(await client.SendAsync(stringifiedUrl, Method, payloadString));
            }
            catch (WebException e)
            {
                var s = new StreamReader(e.Response.GetResponseStream()).ReadToEnd();
                return(new HttpResponseMessage(HttpStatusCode.BadRequest));
            }
        }
Esempio n. 2
0
        public async Task <bool> PerformActionAsync(List <Pair <string, string> > parameters = null, JodelRequest payload = null, string postId = null)
        {
            var plainResponse = await ExecuteRequestAsync(parameters, payload, postId);

            return((int)plainResponse.StatusCode == 204 || (int)plainResponse.StatusCode == 200);
        }
Esempio n. 3
0
        public async Task <T> PerformActionAsync(List <Pair <string, string> > parameters = null, JodelRequest payload = null, string postId = null)
        {
            var plainResponse = await ExecuteRequestAsync(parameters, payload, postId);

            return(await Deserialize <T>(plainResponse));
        }
Esempio n. 4
0
        public async Task <string> PerformActionAsync(List <Pair <string, string> > parameters = null, JodelRequest payload = null, string postId = null)
        {
            var plainResponse = await ExecuteRequestAsync(parameters, payload, postId);

            return(await plainResponse.Content.ReadAsStringAsync());
        }