Skip to content

Commit

Permalink
my_profile() added to Client; fixed two bugs; changes in the structure
Browse files Browse the repository at this point in the history
bug fixed with send/request money, when <User> is passed.
bug fixed with getting transactions list. before_id must be specified in order to get older transactions. (Note the limit per request is 50 transactions)
Made it to check for user/user_id across user_api functions
Divided utils into two
  • Loading branch information
mmohades committed Feb 22, 2020
1 parent 647c6c5 commit 9f3e28d
Show file tree
Hide file tree
Showing 12 changed files with 328 additions and 213 deletions.
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ from venmo_api import Client

# Get your access token. You will need to complete the 2FA process
access_token = Client.get_access_token(username='myemail@random.com',
password='your password')
password='your password')
venmo = Client(access_token=access_token)

# Search for users. You get 50 results per page.
Expand All @@ -50,7 +50,7 @@ venmo.user.search_for_users(query="peter",
count=10)

```
Just keep this in mind that your access token almost never expires! You will need to revoke it by yoursef.
Keep this in mind that your access token never expires! You will need to revoke it by yoursef.

```Python
venmo.log_out("Bearer a40fsdfhsfhdsfjhdkgljsdglkdsfj3j3i4349t34j7d")
Expand All @@ -61,16 +61,21 @@ venmo.log_out("Bearer a40fsdfhsfhdsfjhdkgljsdglkdsfj3j3i4349t34j7d")
venmo.payment.request_money(32.5, "house expenses", "1122334455667")
```

```python
# Send money
venmo.payment.send_money(13.68, "thanks for the 🍔", "1122334455667")
```



Getting a user's public transactions
Getting a user's transactions (public, friends and privates that happen between your account and user_id account)

```python
def callback(transactions_list):
for transaction in transactions_list:
print(transaction)

# callback is optional
# callback is optional. Max number of transactions per request is 50.
venmo_api.user.get_user_transactions(user_id='0000000000000',
callback=callback)
```
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def requirements():

setup(
name='venmo-api',
version='0.1.0',
version='0.1.1',
author="Mark Mohades",
license="GNU General Public License v3",
url='https://github.com/mmohades/venmo',
Expand Down
15 changes: 5 additions & 10 deletions venmo_api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
from .utils.model_util import (string_to_timestamp, get_phone_model_from_json, random_device_id)
from .models.exception import *

from .utils import (string_to_timestamp, get_phone_model_from_json, random_device_id, deserialize, wrap_callback,
warn, confirm)
from .utils.api_client import ApiClient

from .models.json_schema import JSONSchema
from .models.user import User
from .models.transaction import Transaction
from .models.payment_method import PaymentMethod, PaymentRole, PaymentPrivacy

from .models.payment_method import (PaymentMethod, PaymentRole, PaymentPrivacy)
from .utils.api_util import (deserialize, wrap_callback, warn, get_user_id, confirm, validate_access_token)
from .utils.api_client import ApiClient
from .apis.auth_api import AuthenticationApi
from .apis.payment_api import PaymentApi
from .apis.user_api import UserApi

from .venmo import Client


__all__ = ["AuthenticationFailedError", "InvalidArgumentError", "InvalidHttpMethodError", "ArgumentMissingError",
"JSONDecodeError", "ResourceNotFoundError", "HttpCodeError", "NoPaymentMethodFoundError",
"string_to_timestamp", "get_phone_model_from_json", "random_device_id", "deserialize", "wrap_callback",
"warn", "confirm",
"warn", "confirm", "get_user_id", "validate_access_token",
"JSONSchema", "User", "Transaction", "PaymentMethod", "PaymentRole", "PaymentPrivacy",
"ApiClient", "AuthenticationApi", "UserApi", "PaymentApi",
"Client"
Expand Down
1 change: 1 addition & 0 deletions venmo_api/apis/auth_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ def log_out(access_token: str) -> bool:
:param access_token: <str>
:return:
"""

resource_path = '/oauth/access_token'
api_client = ApiClient(access_token=access_token)

Expand Down
35 changes: 21 additions & 14 deletions venmo_api/apis/payment_api.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from venmo_api import ApiClient
from venmo_api import User, PaymentMethod, PaymentRole, PaymentPrivacy
from venmo_api import ArgumentMissingError, NoPaymentMethodFoundError
from venmo_api import deserialize, wrap_callback
from threading import Thread
from venmo_api import NoPaymentMethodFoundError
from venmo_api import deserialize, wrap_callback, get_user_id
from typing import List, Union


Expand All @@ -12,7 +11,12 @@ def __init__(self, api_client: ApiClient):
super().__init__()
self.__api_client = api_client

def get_payment_methods(self, callback=None) -> Union[List[PaymentMethod], Thread]:
def get_payment_methods(self, callback=None) -> Union[List[PaymentMethod], None]:
"""
Get a list of available payment_methods
:param callback:
:return:
"""

wrapped_callback = wrap_callback(callback=callback,
data_type=PaymentMethod)
Expand All @@ -23,17 +27,20 @@ def get_payment_methods(self, callback=None) -> Union[List[PaymentMethod], Threa
callback=wrapped_callback)
# return the thread
if callback:
return response
return

return deserialize(response=response, data_type=PaymentMethod)

def send_money(self, amount: float,
note: str,
target_user_id: int = None,
funding_source_id: str = None,
target_user: User = None,
privacy_setting: str = PaymentPrivacy.private.value,
target_user_id: int = None, target_user: User = None,
callback=None) -> Union[bool, Thread]:
callback=None) -> Union[bool, None]:
"""
send [amount] money with [note] to the ([target_user_id] or [target_user]) from the [funding_source_id]
If no [funding_source_id] is provided, it will find the default source_id and uses that.
:param amount: <float>
:param note: <str>
:param funding_source_id: <str> Your payment_method id for this payment
Expand All @@ -55,11 +62,12 @@ def send_money(self, amount: float,

def request_money(self, amount: float,
note: str,
target_user_id: int = None, target_user: User = None,
target_user_id: int = None,
privacy_setting: str = PaymentPrivacy.private.value,
callback=None) -> Union[bool, Thread]:
target_user: User = None,
callback=None) -> Union[bool, None]:
"""
Request money from a user.
Request [amount] money with [note] from the ([target_user_id] or [target_user])
:param amount: <float> amount of money to be requested
:param note: <str> message/note of the transaction
:param privacy_setting: <str> private/friends/public (enum)
Expand All @@ -83,7 +91,7 @@ def __send_or_request_money(self, amount: float,
funding_source_id: str = None,
privacy_setting: str = PaymentPrivacy.private.value,
target_user_id: int = None, target_user: User = None,
callback=None) -> Union[bool, Thread]:
callback=None) -> Union[bool, None]:
"""
Generic method for sending and requesting money
:param amount:
Expand All @@ -96,8 +104,7 @@ def __send_or_request_money(self, amount: float,
:param callback:
:return:
"""
if not target_user and not target_user_id:
raise ArgumentMissingError(arguments=('target_user_id', 'target_user'))
target_user_id = get_user_id(target_user, target_user_id)

amount = abs(amount)
if not is_send_money:
Expand Down Expand Up @@ -125,7 +132,7 @@ def __send_or_request_money(self, amount: float,
body=body,
callback=wrapped_callback)
if callback:
return threaded
return
# if no exception raises, then it was successful
return True

Expand Down

0 comments on commit 9f3e28d

Please sign in to comment.