flock: Change name of var res to users in get_recipient_id method.

This commit is contained in:
novokrest 2018-06-10 10:29:04 +03:00 committed by showell
parent 7fe37dbfe8
commit 80adce3cee

View file

@ -1,6 +1,6 @@
import logging import logging
import requests import requests
from typing import Any, Dict, Tuple, Optional from typing import Any, Dict, List, Tuple, Optional
from requests.exceptions import ConnectionError from requests.exceptions import ConnectionError
USERS_LIST_URL = 'https://api.flock.co/v1/roster.listContacts' USERS_LIST_URL = 'https://api.flock.co/v1/roster.listContacts'
@ -13,10 +13,10 @@ You can send messages to any Flock user associated with your account from Zulip.
# Matches the recipient name provided by user with list of users in his contacts. # Matches the recipient name provided by user with list of users in his contacts.
# If matches, returns the matched User's ID # If matches, returns the matched User's ID
def find_recipient_id(res: str, recipient_name: str) -> str: def find_recipient_id(users: List[Any], recipient_name: str) -> str:
for obj in res: for user in users:
if recipient_name == obj['firstName']: if recipient_name == user['firstName']:
return obj['id'] return user['id']
# Make request to given flock URL and return a two-element tuple # Make request to given flock URL and return a two-element tuple
# whose left-hand value contains JSON body of response (or None if request failed) # whose left-hand value contains JSON body of response (or None if request failed)
@ -39,11 +39,11 @@ def get_recipient_id(recipient_name: str, config: Dict[str, str]) -> Tuple[Optio
payload = { payload = {
'token': token 'token': token
} }
res, error = make_flock_request(USERS_LIST_URL, payload) users, error = make_flock_request(USERS_LIST_URL, payload)
if res is None: if users is None:
return (None, error) return (None, error)
recipient_id = find_recipient_id(res, recipient_name) recipient_id = find_recipient_id(users, recipient_name)
if recipient_id is None: if recipient_id is None:
error = "No user found. Make sure you typed it correctly." error = "No user found. Make sure you typed it correctly."
return (None, error) return (None, error)