def get_profile_photo(self, size='medium'): if size not in ('small', 'medium', 'large'): raise InvalidSizeException('User get_profile_photo size must one of "small", "medium" or "large".') from mapmyfitness import MapMyFitness instance = MapMyFitness.instance() user_profile_photo = instance._user_profile_photo.find(self.id) return getattr(user_profile_photo, size)
def get_profile_photo(self, size='medium'): if size not in ('small', 'medium', 'large'): raise InvalidSizeException( 'User get_profile_photo size must one of "small", "medium" or "large".' ) from mapmyfitness import MapMyFitness instance = MapMyFitness.instance() user_profile_photo = instance._user_profile_photo.find(self.id) return getattr(user_profile_photo, size)
def activity_type(self): if hasattr(self, '_activity_type'): return self._activity_type else: from mapmyfitness import MapMyFitness instance = MapMyFitness.instance() activity_type = instance.activity_type.find(self.activity_type_id) self._activity_type = activity_type return self._activity_type
def route(self): if self.route_id: if hasattr(self, '_route'): return self._route else: from mapmyfitness import MapMyFitness instance = MapMyFitness.instance() route = instance.route.find(self.route_id) self._route = route return self._route
def activity_type(self): if hasattr(self, "_activity_type"): return self._activity_type else: from mapmyfitness import MapMyFitness instance = MapMyFitness.instance() activity_type = instance.activity_type.find(self.activity_type_id) self._activity_type = activity_type return self._activity_type
def root_activity_type(self): if not self.has_parent: return self if hasattr(self, '_activity_type'): return self._activity_type else: from mapmyfitness import MapMyFitness instance = MapMyFitness.instance() activity_type = instance.activity_type.find(self.root_activity_type_id) self._activity_type = activity_type return self._activity_type
def time_series(self): if self.has_time_series: if 'time_series' in self.original_dict: return self.original_dict['time_series'] elif hasattr(self, '_time_series'): return self._time_series else: from mapmyfitness import MapMyFitness instance = MapMyFitness.instance() workout = instance.workout.find(self.id) self._time_series = workout.time_series return self._time_series
def __getattr__(self, name): # First checking to see if we're entering a recursion # cycle, and if so exiting immediately. Calling `hasattr(self, name)` # will call getattr(self, name) itself and therefore keep recursing. if '__getattr__' in inspect.stack()[1]: raise AttributeNotFoundException from mapmyfitness import MapMyFitness instance = MapMyFitness.instance() user = instance.user.find(self.id) self.__init__(user.original_dict) return getattr(self, name)
def tearDown(self): MapMyFitness._drop()
def test_MapMyFitness_instance(self): MapMyFitness('api-key', 'access_token') assert MapMyFitness.instance()
def test_MapMyFitness_singleton_not_initialized(self): MapMyFitness._drop() self.assertRaises(NotInitializedException, MapMyFitness.instance)
def test_MapMyFitness_is_singleton(self): mmf1 = MapMyFitness('api-key1', 'access_token1') mmf2 = MapMyFitness('api-key2', 'access_token2') assert mmf1 == mmf2
def get_friends(self): from mapmyfitness import MapMyFitness instance = MapMyFitness.instance() friends = instance.user.search(friends_with=self.id) return friends
def setUp(self): self.mmf = MapMyFitness(api_key='abc123', access_token='super-secret-token')
from mapmyfitness import MapMyFitness z = MapMyFitness(api_key='vd9aadfjcrd6ncae2wx92mc8tm4zfnx2', access_token='21933fbf63aad3d8a49dde82d703fbbff3dbc727') print z.user.find("self/")