Beispiel #1
0
 public FitbitHttpMessageHandler(FitbitClient fitbitClient, IFitbitInterceptor interceptor)
 {
     this.FitbitClient = fitbitClient;
     this.interceptor  = interceptor;
     responseHandler   = ResponseHandler;
     //Define the inner must handler. Otherwise exception is thrown.
     InnerHandler = new HttpClientHandler();
 }
Beispiel #2
0
        public FitbitHttpMessageHandler(FitbitClient fitbitClient, IFitbitInterceptor interceptor, int?maxConnectionsPerServer = null)
        {
            this.FitbitClient = fitbitClient;
            this.interceptor  = interceptor;
            responseHandler   = ResponseHandler;

            //Define the inner must handler. Otherwise exception is thrown.
            var innerHandler = new HttpClientHandler();

            if (maxConnectionsPerServer != null)
            {
                innerHandler.MaxConnectionsPerServer = maxConnectionsPerServer.Value;
            }

            InnerHandler = innerHandler;
        }
        /// <summary>
        /// Creates the processing request pipeline using the message handlers
        /// </summary>
        /// <param name="authorization"></param>
        /// <param name="interceptors"></param>
        /// <returns></returns>
        internal static HttpMessageHandler CreatePipeline(this FitbitClient client, List <IFitbitInterceptor> interceptors)
        {
            if (interceptors.Count > 0)
            {
                // inspired by the code referenced from the web api source; this creates the russian doll effect
                FitbitHttpMessageHandler innerHandler = new FitbitHttpMessageHandler(client, interceptors[0]);

                List <IFitbitInterceptor> innerHandlers = interceptors.GetRange(1, interceptors.Count - 1);

                foreach (IFitbitInterceptor handler in innerHandlers)
                {
                    FitbitHttpMessageHandler messageHandler = new FitbitHttpMessageHandler(client, handler);
                    messageHandler.InnerHandler = innerHandler;
                    innerHandler = messageHandler;
                }

                return(innerHandler);
            }

            return(null);
        }