mirror of
https://github.com/bspeice/playwithfriends
synced 2024-11-12 10:08:08 -05:00
Add friend name lookups
This commit is contained in:
parent
82849bfd14
commit
8ede6abb9b
@ -36,7 +36,7 @@ class SteamAPI(object):
|
||||
logging.debug('Return code: {}'.format(response.status_code))
|
||||
return response.json()
|
||||
|
||||
def get_friends(self, steam_id):
|
||||
def get_friends_ids(self, steam_id):
|
||||
"""
|
||||
Return the steam_id's of all users this user is friends with
|
||||
|
||||
@ -97,18 +97,28 @@ class SteamAPI(object):
|
||||
|
||||
return [g['appid'] for g in games]
|
||||
|
||||
def get_player_summary(self, steam_id):
|
||||
def get_player_summary(self, steam_ids):
|
||||
|
||||
return self._make_request(
|
||||
WebAPI.user,
|
||||
'GetPlayerSummaries',
|
||||
'v0002',
|
||||
{
|
||||
'steamids': steam_id
|
||||
'steamids': ','.join(steam_ids)
|
||||
}
|
||||
)
|
||||
)['response']['players']
|
||||
|
||||
def get_steam64_id(self, profile_url):
|
||||
def get_player_names(self, steam_ids):
|
||||
"""
|
||||
|
||||
:param steam_ids:
|
||||
:return: Persona names for all id's supplied
|
||||
:rtype: list
|
||||
"""
|
||||
players = self.get_player_summary(steam_ids)
|
||||
return {p['steamid']: p['personaname'] for p in players}
|
||||
|
||||
def get_steam64_from_profile(self, profile_url):
|
||||
"""
|
||||
Get the Steam64 ID for a user, given their profile URL.
|
||||
This is by far and above the mostly likely piece of code
|
||||
|
@ -7,7 +7,7 @@ class SteamTest(TestCase):
|
||||
|
||||
def test_returns_friends_list(self):
|
||||
steam_id = '76561198020882912'
|
||||
friends = steam.SteamAPI().get_friends(steam_id)
|
||||
friends = steam.SteamAPI().get_friends_ids(steam_id)
|
||||
self.assertTrue(len(friends) > 0)
|
||||
|
||||
def test_I_own_games(self):
|
||||
@ -24,4 +24,9 @@ class SteamTest(TestCase):
|
||||
profile_url = 'http://steamcommunity.com/id/fractalize/'
|
||||
steam_id = '76561198020882912'
|
||||
|
||||
self.assertEqual(steam.SteamAPI().get_steam64_id(profile_url), steam_id)
|
||||
self.assertEqual(steam.SteamAPI().get_steam64_from_profile(profile_url), steam_id)
|
||||
|
||||
def test_my_persona(self):
|
||||
steam_id = '76561198020882912'
|
||||
names = steam.SteamAPI().get_player_names([steam_id])
|
||||
self.assertEqual({steam_id: 'Fractalize'}, names)
|
||||
|
Loading…
Reference in New Issue
Block a user