Skip to content

Commit 82887fb

Browse files
Change 'Client.users' to a dictionary
The key of a pair in 'Client.users' is the ‘_id’ of the contained ‘User’ object. This means that the user can only be added if it has been “logged in”. Because of this, a ‘ValueError’ is raised if a ‘token’ or ‘code’ argument is not supplied.
1 parent 15795f9 commit 82887fb

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

instagram/client.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class Client:
3535

3636
def __init__(self, *, loop=None, client_id=None, client_secret=None,
3737
redirect_uri=None):
38-
self.users = []
38+
self.users = {}
3939
self.loop = asyncio.get_event_loop() if loop is None else loop
4040
self.session = create_client_session()
4141

@@ -72,7 +72,12 @@ def get_user(self, *args, token=None, code=None, **kwargs):
7272
@asyncio.coroutine
7373
def add_user(self, *args, **kwargs):
7474
user = yield from self.get_user(*args, **kwargs)
75-
self.users.append(user)
75+
if user._id is None:
76+
raise ValueError(
77+
"Please supply either a 'token' or 'code' argument")
78+
79+
self.users[user._id] = user
80+
7681
return user
7782

7883
@asyncio.coroutine

0 commit comments

Comments
 (0)