Exemple #1
0
 def get_device_lsit(self, suid):
     ckey = "devicelist"        
     result = yield get_cache(CACHED_PREFIX_KEY, suid, ckey)
     if result is None:        
         url = self._API_URL + "/devicelist"
         result = yield self.api_request(suid, url)
         set_cache(CACHED_PREFIX_KEY, suid, ckey, result, 0)
     raise Return(result)
Exemple #2
0
 def servc_get_profile(self, suid):
     ckey = "profile"
     result = yield get_cache(CACHED_PREFIX_KEY, suid, ckey)
     if result is None:
         url = self._API_URL + "/users/@me"
         result = yield self.api_request(suid, url, json_schema=SCHEMA_USER_PROFILE)
         set_cache(CACHED_PREFIX_KEY, suid, ckey, result, 0)
     raise Return(result)
Exemple #3
0
 def servc_get_body_events(self, suid):
     ckey = "bodyevents"
     result = yield get_cache(CACHED_PREFIX_KEY, suid, ckey)
     if result is None:
         url = self._API_URL + "/users/@me/body_events"
         result = yield self.api_request(suid, url, json_schema=SCHEMA_BODY_EVENTS_DATA)
         set_cache(CACHED_PREFIX_KEY, suid, ckey, result, 0)
     raise Return(result)
Exemple #4
0
 def get_profile(self, suid):
     ckey = "profile"        
     result = yield get_cache(CACHED_PREFIX_KEY, suid, ckey)
     if result is None:        
         url = self._API_URL + "/me"
         result = yield self.api_request(suid, url)
         set_cache(CACHED_PREFIX_KEY, suid, ckey, result, 0)
     raise Return(result)
Exemple #5
0
 def get_measure_data(self, user_id, type, start_time, end_time):
     type_key = ('%s.%s.%s' % (type, start_time, end_time))
     result = yield get_cache(CACHED_PREFIX_WITHINGS, user_id, type_key)
     if result is None:
         result = yield self.api_request(user_id, 'measure',  action='getmeas',
                                         startdate=start_time, enddate=end_time)
         set_cache(CACHED_PREFIX_WITHINGS, user_id, type_key, result, 0)
     raise Return(result)
Exemple #6
0
 def servc_get_heartrates(self, suid, date):
     ckey = "heartrates.%s" % date
     result = yield get_cache(CACHED_PREFIX_KEY, suid, ckey)
     if result is None:
         url = self._API_URL + "/users/@me/heartrates"
         #json_schema=SCHEMA_BODY_EVENTS_DATA
         result = yield self.api_request(suid, url, date=date)
         set_cache(CACHED_PREFIX_KEY, suid, ckey, result, 0)
     raise Return(result)    
Exemple #7
0
 def servc_get_trends(self, suid, end_date, period):
     ckey = "trends.%s" % end_date
     result = yield get_cache(CACHED_PREFIX_KEY, suid, ckey)
     if result is None:
         url = self._API_URL + "/users/@me/trends"
         result = yield self.api_request(suid, url, json_schema=SCHEMA_USER_TRENDS,
                                         end_date=end_date, 
                                         bucket_size='d', num_buckets=period)
         set_cache(CACHED_PREFIX_KEY, suid, ckey, result, 0)
     raise Return(result)
Exemple #8
0
def update_user_auth(suid, auth_info, prefix = CACHED_PREFIX_USER):
    ''' Update user auth information 
    '''
    # Update the user auth info.
    set_cache(prefix, suid, CACHED_PREFIX_AUTH, auth_info, 0)
    # Update user's subscribution service list. 
    user_servc_set = yield get_cache(CACHED_PREFIX_USER, suid, CACHED_PREFIX_SERVC)
    if user_servc_set is None:
        user_servc_set = Set()
    else:
        user_servc_set = Set(user_servc_set)
    if auth_info:
        user_servc_set.add(prefix)
    else:
        user_servc_set.discard(prefix)        
    set_cache(CACHED_PREFIX_USER, suid, CACHED_PREFIX_SERVC, list(user_servc_set), 0)