Skip to content

Commit

Permalink
Fixed some formatting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
mmohades committed Feb 5, 2020
1 parent 1a1cb05 commit 13448e1
Show file tree
Hide file tree
Showing 12 changed files with 267 additions and 241 deletions.
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,52 @@

## Introduction

This is a wrapper for the Venmo API. This library provides a Python interface for the Venmo API. It's compatible with Python versions 3.6+ and PyPy.
This is a wrapper for the Venmo API. This library provides a Python interface for the Venmo API. It's compatible with Python versions 3.6+.

## Usage

In short, you can send money, request for money, get anyone's public transactions, get public profile info, etc. You can use the wrapper for various reasons. One cool example could be crawling public transactions and using graph databases, like Neo4j, to find fraud or drug dealers. You can also run any analysis on transactions' notes.
In short, you can send money, request for money, get a user's public transactions, get a user's public profile info, etc. The following is an example of initializing and working with it.

```python
from Venmo import VenmoApi

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

# Search for users. You get 50 results per page.
users = venmo.user.search_for_users(query="Peter",
page=2)
page=2)
for user in users:
print(user.username)

# Or, you can pass a callback to make it async

# Or, you can pass a callback to make it multi-threaded
def callback(users):
for user in users:
print(user.username)
venmo.user.search_for_users(query="peter",
callback=callback,
page=2,
count=10)
callback=callback,
page=2,
count=10)

```
Or you can get anyone's public transactions
Getting a user's public transactions

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

# callback is optional
venmo_api.user.get_user_transactions(user_id='0000000000000',
callback=callback)
```
You can also make payments, request money, get friends_list, get public profile info and so on and so forth.


## Getting Started

### Installing
### Installation



Expand Down
5 changes: 3 additions & 2 deletions apis/auth_api.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from utils import random_device_id, warn, confirm
from models.exception import AuthenticationFailedError
from api_client import ApiClient
from utils.api_client import ApiClient


class AuthenticationApi(object):
Expand Down Expand Up @@ -82,7 +82,8 @@ def __send_text_otp(self, otp_secret):

return response

def __ask_user_for_otp_password(self):
@staticmethod
def __ask_user_for_otp_password():

otp = ""
while len(otp) < 6 or not otp.isdigit():
Expand Down
20 changes: 9 additions & 11 deletions apis/payment_api.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from api_client import ApiClient
from utils.api_client import ApiClient
from models import User, PaymentMethod, PaymentRole, PaymentPrivacy
from models.exception import ArgumentMissingError, NoPaymentMethodFoundError
from utils import deserialize, wrap_callback
from typing import List
from threading import Thread
from typing import List, Union


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

def get_payment_methods(self, callback=None) -> List[PaymentMethod]:
def get_payment_methods(self, callback=None) -> Union[List[PaymentMethod], Thread]:

wrapped_callback = wrap_callback(callback=callback,
data_type=PaymentMethod)
Expand All @@ -31,15 +32,15 @@ def send_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) -> bool:
callback=None) -> Union[bool, Thread]:
"""
:param amount: <float>
:param note: <str>
:param funding_source_id: <str> Your payment_method id for this payment
:param privacy_setting: <str> private/friends/public
:param target_user_id: <str>
:param target_user: <User>
:param callback: <function>
:param callback: <function> Passing callback will run it in a distinct thread, and returns Thread
:return: <bool> Either the transaction was successful or an exception will rise.
"""

Expand All @@ -56,9 +57,9 @@ def request_money(self, amount: float,
note: str,
privacy_setting: str = PaymentPrivacy.private.value,
target_user_id: int = None, target_user: User = None,
callback=None) -> bool:
callback=None) -> Union[bool, Thread]:
"""
Request money from a 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 @@ -82,7 +83,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):
callback=None) -> Union[bool, Thread]:
"""
Generic method for sending and requesting money
:param amount:
Expand All @@ -103,9 +104,6 @@ def __send_or_request_money(self, amount: float,
amount = -amount

body = {
"metadata": {
"quasi_cash_disclaimer_viewed": False
},
"user_id": target_user_id,
"audience": privacy_setting,
"amount": amount,
Expand Down
36 changes: 19 additions & 17 deletions apis/user_api.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from typing import List, Union
from models.user import User
from models.transaction import Transaction
from models.exception import InvalidArgumentError, ArgumentMissingError
from utils import deserialize, wrap_callback
from threading import Thread
from typing import List, Union


class UserApi(object):
Expand All @@ -11,7 +12,7 @@ def __init__(self, api_client):
self.__api_client = api_client

def search_for_users(self, query: str, callback=None,
page: int = 1, count: int = 50) -> List[User]:
page: int = 1, count: int = 50) -> Union[List[User], Thread]:
"""
:param query: <str>
:param callback: <function>
Expand All @@ -33,17 +34,17 @@ def search_for_users(self, query: str, callback=None,

response = self.__api_client.call_api(resource_path=resource_path, params=params,
method='GET', callback=wrapped_callback)

# return the Thread
if callback:
return []
return response

return deserialize(response=response, data_type=User)

def get_user_profile(self, user_id: str, callback=None) -> Union[User, None]:
def get_profile(self, user_id: str, callback=None) -> Union[User, Thread, None]:
"""
:param user_id: <str>, example: '2859950549165568970'
:param callback: <function>
:return user: <User>
:return user: <User> <Thread> <NoneType>
"""

# Prepare the request
Expand All @@ -54,7 +55,7 @@ def get_user_profile(self, user_id: str, callback=None) -> Union[User, None]:
response = self.__api_client.call_api(resource_path=resource_path,
method='GET',
callback=wrapped_callback)
# Return the thread or process the response
# Return the thread
if callback:
return response

Expand All @@ -64,7 +65,7 @@ def get_user_friends_list(self, user: User = None,
user_id: str = None,
callback=None,
page: int = 1,
count: int = 1337) -> Union[User, None]:
count: int = 1337) -> Union[User, Thread, None]:
"""
:return users_list: <list> A list of <User> objects or empty
Expand All @@ -86,16 +87,16 @@ def get_user_friends_list(self, user: User = None,
response = self.__api_client.call_api(resource_path=resource_path,
method='GET', params=params,
callback=wrapped_callback)
# Return or process the response
# Return the Thread
if callback:
return
return response

return deserialize(response=response, data_type=User)

def get_user_transactions(self, user: User = None, user_id: str = None,
callback=None,
page: int = 1,
count: int = 50) -> Union[Transaction, None]:
count: int = 50) -> Union[Transaction, Thread, None]:

user_id = user_id or user.id

Expand All @@ -115,9 +116,9 @@ def get_user_transactions(self, user: User = None, user_id: str = None,
response = self.__api_client.call_api(resource_path=resource_path,
method='GET', params=params,
callback=wrapped_callback)
# Return or process the response
# Return the Thread
if callback:
return
return response

return deserialize(response=response, data_type=Transaction)

Expand All @@ -127,7 +128,7 @@ def get_transaction_between_two_users(self, user_one: User = None,
user_id_two: str = None,
callback=None,
page: int = 1,
count: int = 50) -> Union[Transaction, None]:
count: int = 50) -> Union[Transaction, Thread, None]:

user_id_one = user_id_one or user_one.id
user_id_two = user_id_two or user_two.id
Expand All @@ -150,13 +151,14 @@ def get_transaction_between_two_users(self, user_one: User = None,
response = self.__api_client.call_api(resource_path=resource_path,
method='GET', params=params,
callback=wrapped_callback)
# Return or process the response
# Return the Thread
if callback:
return
return response

return deserialize(response=response, data_type=Transaction)

def __prepare_offset_limit_params(self, page_number, max_number_per_page, max_offset, count):
@staticmethod
def __prepare_offset_limit_params(page_number, max_number_per_page, max_offset, count):
"""Get the offset for going to that page."""
max_page = max_offset//max_number_per_page + 1
if page_number == 0 or page_number > max_page:
Expand Down
2 changes: 1 addition & 1 deletion models/exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ def __init__(self, msg: str = None, arguments: tuple = None, reason=None):
self.msg = msg or f"One of f{arguments} must be passed to this method." + (reason or "")
super(ArgumentMissingError, self).__init__(self.msg)

# ======= Payment =======

# ======= Payment =======

class NoPaymentMethodFoundError(Exception):
def __init__(self, msg: str = None, reason=None):
Expand Down
19 changes: 9 additions & 10 deletions models/payment_method.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import Dict
from enum import Enum
from utils.json_schema import JSONSchema


class PaymentMethod(object):
Expand All @@ -13,10 +14,13 @@ def __init__(self, pid: str, p_role: str, p_name: str, p_type: str):

@classmethod
def from_json(cls, json: Dict):
pid = json.get(p_format['id'])
p_role = json.get(p_format['payment_role'])
p_name = json.get(p_format['name'])
p_type = json.get(p_format['type'])

payment_parser = JSONSchema.payment_method(json)

pid = payment_parser.get_id()
p_role = payment_parser.get_payment_method_role()
p_name = payment_parser.get_payment_method_name()
p_type = payment_parser.get_payment_method_type()

# Get the class for this payment, must be either VenmoBalance or BankAccount
payment_class = payment_type[p_type]
Expand All @@ -27,7 +31,7 @@ def from_json(cls, json: Dict):
p_type=p_type)

def __str__(self):
return f"id: {self.id}, payment_role: {self.role}, payment_name: {self.name}, type: {self.type}"
return f"id: {self.id}, payment_method_role: {self.role}, payment_method_name: {self.name}, type: {self.type}"


class VenmoBalance(PaymentMethod):
Expand All @@ -54,8 +58,3 @@ class PaymentPrivacy(Enum):


payment_type = {'bank': BankAccount, 'balance': VenmoBalance}

p_format = {'id': 'id',
'payment_role': 'peer_payment_role',
'name': 'name',
'type': 'type'}

0 comments on commit 13448e1

Please sign in to comment.