Ejemplo n.º 1
0
        /// <summary>
        /// Performs an asynchronous HTTP request to the Stack Exchange API, with the specified data, and request method.
        /// </summary>
        /// <typeparam name="T">The type implementing <see cref="IStackExchangeModel"/>, to which the response gets deserialized to.</typeparam>
        /// <param name="path">The path relative to <see cref="ApiBaseUrl"/> to which the request should be made.</param>
        /// <param name="data">The data to be sent along with the HTTP request.</param>
        /// <param name="requestMethod">The HTTP method used for the request.</param>
        public async Task <Models.Wrapper <T> > PerformRequestAsync <T>(string path, Dictionary <string, string> data, HttpRequestMethod requestMethod)
            where T : IStackExchangeModel
        {
            if (data == null)
            {
                data = new Dictionary <string, string>();
            }

            if (!IsAnonymous)
            {
                data.Add("key", Key);

                if (HasAccessToken)
                {
                    data.Add("access_token", accessToken);
                }
            }

            var url = ApiBaseUrl.AppendPathSegment(path);

            var response = await httpRequester.PerformRequestAsync(url, data, requestMethod).ConfigureAwait(false);

            return(jsonDeserializer.Deserialize <Models.Wrapper <T> >(response.Content));
        }