Skip to content

Commit

Permalink
added get_user_by_username(); fixed a bug with device_used
Browse files Browse the repository at this point in the history
  • Loading branch information
mmohades committed Jan 2, 2021
1 parent 27f25e4 commit eb74da7
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 10 deletions.
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ def requirements():

setup(
name='venmo-api',
version='0.2.2',
version='0.2.3',
author="Mark Mohades",
license="GNU General Public License v3",
url='https://github.com/mmohades/venmo',
keywords='Python Venmo API wrapper',
description="A Simple Python Wrapper For The Venmo API",
description="Venmo API client for Python",
long_description=readme,
long_description_content_type="text/markdown",
packages=find_packages(),
Expand Down
27 changes: 22 additions & 5 deletions venmo_api/apis/user_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,14 @@ def get_my_profile(self, callback=None, force_update=False) -> Union[User, None]
return self.__profile

def search_for_users(self, query: str, callback=None,
page: int = 1, count: int = 50) -> Union[List[User], None]:
page: int = 1, count: int = 50, username=False) -> Union[List[User], None]:
"""
search for [query] in users
:param query: <str>
:param callback: <function>
:param count: <int>
:param page: <int>
:param query:
:param callback:
:param page:
:param count:
:param username: default: False; Pass True if search is by username
:return users_list: <list> A list of <User> objects or empty
"""

Expand All @@ -57,6 +58,8 @@ def search_for_users(self, query: str, callback=None,
max_offset=9900,
count=count)
params = {'query': query}
if username or '@' in query:
params = {'query': query.replace('@', ''), 'type': 'username'}
params.update(offset_limit_params)

response = self.__api_client.call_api(resource_path=resource_path, params=params,
Expand Down Expand Up @@ -89,6 +92,20 @@ def get_user(self, user_id: str, callback=None) -> Union[User, None]:

return deserialize(response=response, data_type=User)

def get_user_by_username(self, username: str) -> Union[User, None]:
"""
Get the user profile with [username]
:param username:
:return user: <User> <NoneType>
"""
users = self.search_for_users(query=username, username=True)
for user in users:
if user.username == username:
return user

# username not found
return None

def get_user_friends_list(self, user_id: str = None,
user: User = None,
callback=None,
Expand Down
1 change: 1 addition & 0 deletions venmo_api/models/payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,4 @@ class PaymentStatus(Enum):
SETTLED = 'settled'
CANCELLED = 'cancelled'
PENDING = 'pending'
FAILED = 'failed'
8 changes: 5 additions & 3 deletions venmo_api/utils/model_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ def get_phone_model_from_json(app_json):
:param app_json:
:return:
"""
app = {1: "iPhone", 4: "Android"}
_id = app_json['id']
app = {1: "iPhone", 4: "Android", 0: "Other"}
_id = 0
if app_json:
_id = app_json['id']

return app.get(int(_id)) or "undefined"
return app.get(int(_id))


def random_device_id():
Expand Down

0 comments on commit eb74da7

Please sign in to comment.