예제 #1
0
        /// <summary>
        /// Advanced mode for library usage. Allows custom creation of HttpClient to account for future authentication methods
        /// </summary>
        /// <param name="customFactory">A function or lambda expression who is in charge of creating th HttpClient. It takes as an argument a HttpMessageHandler which does wiring for IFitbitInterceptor. To use IFitbitInterceptor you must pass this HttpMessageHandler as anargument to the constuctor of HttpClient</param>
        /// <param name="interceptor">An interface that enables sniffing all outgoing and incoming http requests from FitbitClient</param>
        public FitbitClient(Func <HttpMessageHandler, HttpClient> customFactory, IFitbitInterceptor interceptor = null, ITokenManager tokenManager = null)
        {
            this.OAuth2TokenAutoRefresh = false;

            ConfigureTokenManager(tokenManager);
            this.HttpClient = customFactory(new FitbitHttpMessageHandler(this, interceptor));
        }
예제 #2
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();
 }
예제 #3
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;
        }
예제 #4
0
        /// <summary>
        /// Private base constructor which takes it all and constructs or throws exceptions as appropriately
        /// </summary>
        /// <param name="consumerKey"></param>
        /// <param name="consumerSecret"></param>
        /// <param name="accessToken"></param>
        /// <param name="accessSecret"></param>
        /// <param name="httpClient"></param>
        public static FitbitClient Create(string consumerKey, string consumerSecret, string accessToken, string accessSecret, IFitbitInterceptor interceptor = null)
        {
            #region Parameter checking
            if (string.IsNullOrWhiteSpace(consumerKey))
            {
                throw new ArgumentNullException(nameof(consumerKey), "ConsumerKey must not be empty or null");
            }

            if (string.IsNullOrWhiteSpace(consumerSecret))
            {
                throw new ArgumentNullException(nameof(consumerSecret), "ConsumerSecret must not be empty or null");
            }

            if (string.IsNullOrWhiteSpace(accessToken))
            {
                throw new ArgumentNullException(nameof(accessToken), "AccessToken must not be empty or null");
            }

            if (string.IsNullOrWhiteSpace(accessSecret))
            {
                throw new ArgumentNullException(nameof(accessSecret), "AccessSecret must not be empty or null");
            }
            #endregion

            if (interceptor != null)
            {
                return(new FitbitClient(mh =>
                {
                    //Injecting the Message Handler provided by FitbitClient library (mh) allows us to invoke any IFitbitInterceptor that has been registered
                    return AsyncOAuth.OAuthUtility.CreateOAuthClient(mh, consumerKey, consumerSecret,
                                                                     new AsyncOAuth.AccessToken(accessToken, accessSecret));
                }, interceptor));
            }
            else
            {
                return(new FitbitClient(mh =>
                {
                    return AsyncOAuth.OAuthUtility.CreateOAuthClient(consumerKey, consumerSecret,
                                                                     new AsyncOAuth.AccessToken(accessToken, accessSecret));
                }));
            }
        }
예제 #5
0
        /// <summary>
        /// Simplest constructor for OAuth2- requires the minimum information required by FitBit.Net client to make succesful calls to Fitbit Api
        /// </summary>
        /// <param name="credentials">Obtain this information from your developer dashboard. App credentials are required to perform token refresh</param>
        /// <param name="accessToken">Authenticate with Fitbit API using OAuth2. Authenticator2 class is a helper for this process</param>
        /// <param name="interceptor">An interface that enables sniffing all outgoing and incoming http requests from FitbitClient</param>
        public FitbitClient(FitbitAppCredentials credentials, OAuth2AccessToken accessToken, IFitbitInterceptor interceptor = null, bool enableOAuth2TokenRefresh = true, ITokenManager tokenManager = null)
        {
            this.AppCredentials = credentials;
            this.AccessToken    = accessToken;

            this.FitbitInterceptorPipeline = new List <IFitbitInterceptor>();


            if (interceptor != null)
            {
                this.FitbitInterceptorPipeline.Add(interceptor);
            }

            ConfigureTokenManager(tokenManager);

            //Auto refresh should always be the last handle to be registered.
            ConfigureAutoRefresh(enableOAuth2TokenRefresh);

            CreateHttpClientForOAuth2();
        }
예제 #6
0
 public FitbitClient(FitbitAppCredentials credentials, OAuth2AccessToken accessToken, IFitbitInterceptor interceptor, ITokenManager tokenManager) : this(credentials, accessToken, interceptor, true, tokenManager)
 {
 }