Beispiel #1
0
        /// <summary>
        /// Syncronize data between keepzer and the service
        /// </summary>
        /// <param name="context"></param>
        /// <param name="fullSync">True if a full sync should be run</param>
        /// <exception cref="Keepzer.Data.Exceptions.ClientException">Thrown when no access token is available</exception>
        public void Sync(ServiceContext context, Boolean fullSync)
        {
            OpenAuth2 authObject = context.DataClient.GetSingletonData(context.UserAppId, PublicDataTypes.OpenAuth2, new OpenAuth2());

            // not authorized if the access token is empty
            if (String.IsNullOrEmpty(authObject.AccessToken))
            {
                throw new ClientException(ClientError.Forbidden);
            }

            LastFmUserProfile profileData = GetProfileData(context);

            // figure out whether to do a full sync or a partial sync
            // do full sync on first of each month

            /*String[] categories =
             * {
             *      PublicDataTypes.HealthBodySteps,
             *      PublicDataTypes.HealthBodyCalories,
             *      PublicDataTypes.MovementWalking,
             *      PublicDataTypes.MovementRunning,
             *      PublicDataTypes.MovementCycling,
             *      PublicDataTypes.MovementDriving
             * };
             * DateTime startDate = GetLastEntryDate(context, categories) ?? profileData.FirstDate;
             * if (fullSync || startDate < profileData.FirstDate)
             *      startDate = profileData.FirstDate;
             * GetDailySummaryData(context, startDate);*/
        }
Beispiel #2
0
        /// <summary>
        /// Check whether the service is authorized for the current user
        /// </summary>
        /// <returns></returns>
        public Boolean ValidateAuthorization(ServiceContext context)
        {
            OpenAuth2 authObject = context.DataClient.GetSingletonData(context.UserAppId, PublicDataTypes.OpenAuth2, new OpenAuth2());

            // not authorized if the access token is empty
            if (String.IsNullOrEmpty(authObject.AccessToken))
            {
                return(false);
            }

            try
            {
                // validate the authorization token
                GetProfileData(context);
            }
            catch
            {
                return(false);
            }
            return(true);
        }
Beispiel #3
0
        private void AuthorizeRequest(ServiceContext context, HttpWebRequest request)
        {
            OpenAuth2 authObject = context.DataClient.GetSingletonData(context.UserAppId, PublicDataTypes.OpenAuth2, new OpenAuth2());

            context.AuthManager.AuthorizeRequest(request, authObject);
        }