Esempio n. 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ApiRequest"/> class.
 /// </summary>
 /// <param name="token">Access token to API.</param>
 /// <param name="url">API endpoint.</param>
 /// <param name="method">HTTP method.</param>
 public ApiRequest(string token, string url, RestSharp.Method method = RestSharp.Method.GET)
 {
     client           = new RestClient(ProductConstants.FxAUrl);
     client.UserAgent = ProductConstants.GetUserAgent();
     request          = new RestRequest(url, method);
     request.AddParameter("Authorization", "Bearer " + token, ParameterType.HttpHeader);
     request.RequestFormat = DataFormat.Json;
 }
Esempio n. 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ApiRequest"/> class.
        /// </summary>
        /// <param name="token">Access token to API.</param>
        /// <param name="url">API endpoint.</param>
        /// <param name="method">HTTP method.</param>
        /// <param name="caching">Indicates whether caching is enabled for requests.</param>
        public ApiRequest(string token, string url, RestSharp.Method method = RestSharp.Method.GET, bool caching = true)
        {
            client  = new RestClient(ProductConstants.FxAUrl);
            request = new RestRequest(url, method);

            client.UserAgent = ProductConstants.GetUserAgent();

            if (!caching)
            {
                client.CachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.Revalidate);
                request.AddHeader("Connection", "close");
            }

            request.AddParameter("Authorization", "Bearer " + token, ParameterType.HttpHeader);
            request.RequestFormat = DataFormat.Json;
        }