def get_user(self, username): """ Gets a user's profile data. :param username: List of :class:`Message <kik.messages.Message>` to be sent. :type username: str :returns: A :class:`User <kik.User>` containing the user's profile data. :rtype: kik.User .. note:: In order to fetch a user's profile, the user must be a subscriber to your bot Usage: >>> from kik import KikApi >>> kik = KikApi(BOT_USERNAME, BOT_API_KEY) >>> kik.get_user('aleem') <kik.User> """ response = requests.get( ROOT_URL.format('/v1/user/{}'.format(username)), auth=(self.bot, self.api_key), timeout=60 ) if response.status_code != 200: raise KikError(response.text) content = response.json() return User.from_json(content)
def test_from_json(self): user = User.from_json({ 'firstName': 'First', 'lastName': 'Last', 'profilePicUrl': 'http://foo.bar/profile', 'profilePicLastModified': 1458657367 }) self.assertEqual(user.first_name, 'First') self.assertEqual(user.last_name, 'Last') self.assertEqual(user.profile_pic_url, 'http://foo.bar/profile') self.assertEqual(user.profile_pic_last_modified, 1458657367)
def test_from_json_no_picture(self): user = User.from_json({ 'firstName': 'First', 'lastName': 'Last', 'profilePicUrl': None, 'profilePicLastModified': None }) self.assertEqual(user.first_name, 'First') self.assertEqual(user.last_name, 'Last') self.assertEqual(user.profile_pic_url, None) self.assertEqual(user.profile_pic_last_modified, None)