Skip to content

Commit

Permalink
watchLists > watchlists in response for watchlist_type_id_map (#…
Browse files Browse the repository at this point in the history
…416)

* `watchLists` > `watchlists` in response

* use property for type>id map
  • Loading branch information
timabrmsn committed Apr 22, 2022
1 parent 3164037 commit 044119a
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/py42/services/watchlists.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def watchlist_type_id_map(self):
"""Map watchlist types to IDs, if they exist."""
if not self._watchlist_type_id_map:
self._watchlist_type_id_map = {}
watchlists = self.get_page(page_size=100).data["watchLists"]
watchlists = self.get_page(page_size=100).data["watchlists"]
for item in watchlists:
# We will need to custom handle CUSTOM types when they come around
self._watchlist_type_id_map[item["listType"]] = item["watchlistId"]
Expand All @@ -40,9 +40,9 @@ def delete(self, watchlist_id):
response = self._connection.delete(uri)
# delete dictionary entry if success
if response.status_code == 200:
for k, v in self._watchlist_type_id_map.items():
for k, v in self.watchlist_type_id_map.items():
if v == watchlist_id:
del self._watchlist_type_id_map[k]
del self.watchlist_type_id_map[k]
break
return response
except Py42NotFoundError as err:
Expand All @@ -62,7 +62,7 @@ def create(self, watchlist_type):
data = {"watchlistType": watchlist_type}
try:
response = self._connection.post(self._uri_prefix, json=data)
self._watchlist_type_id_map[watchlist_type] = response.data["watchlistId"]
self.watchlist_type_id_map[watchlist_type] = response.data["watchlistId"]
return response
except Py42BadRequestError as err:
if (
Expand Down Expand Up @@ -97,7 +97,7 @@ def add_included_users_by_watchlist_id(self, user_ids, watchlist_id):

def add_included_users_by_watchlist_type(self, user_ids, watchlist_type):
try:
id = self._watchlist_type_id_map[watchlist_type]
id = self.watchlist_type_id_map[watchlist_type]
except KeyError:
# if watchlist of specified type not found, create watchlist
id = (self.create(watchlist_type)).data["watchlistId"]
Expand All @@ -115,7 +115,7 @@ def delete_included_users_by_watchlist_id(self, user_ids, watchlist_id):

def delete_included_users_by_watchlist_type(self, user_ids, watchlist_type):
try:
id = self._watchlist_type_id_map[watchlist_type]
id = self.watchlist_type_id_map[watchlist_type]
except KeyError:
# if specified watchlist type not found, raise error
raise Py42Error(f"Couldn't find watchlist of type:'{watchlist_type}'.")
Expand Down

0 comments on commit 044119a

Please sign in to comment.