Skip to content

Commit

Permalink
fixed #19. Added BaseModel with string method
Browse files Browse the repository at this point in the history
  • Loading branch information
mmohades committed Oct 3, 2020
1 parent e0e78de commit 8f85f8d
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 40 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ media

### Other ###
test*.py
testing

### Linux ###
*~
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.2.0',
version='0.2.1',
author="Mark Mohades",
license="GNU General Public License v3",
url='https://github.com/mmohades/venmo',
Expand Down
3 changes: 2 additions & 1 deletion venmo_api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from .utils.model_util import (string_to_timestamp, get_phone_model_from_json, random_device_id)
from .models.exception import *
from .models.base_model import BaseModel
from .models.json_schema import JSONSchema
from .models.user import User
from .models.transaction import Transaction
Expand All @@ -18,6 +19,6 @@
"get_phone_model_from_json", "random_device_id",
"deserialize", "wrap_callback", "warn", "confirm", "get_user_id", "validate_access_token",
"JSONSchema", "User", "Transaction", "Payment", "PaymentStatus", "PaymentMethod", "PaymentRole",
"PaymentPrivacy", "ApiClient", "AuthenticationApi", "UserApi", "PaymentApi",
"BaseModel", "PaymentPrivacy", "ApiClient", "AuthenticationApi", "UserApi", "PaymentApi",
"Client"
]
12 changes: 8 additions & 4 deletions venmo_api/apis/payment_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,26 @@ def __init__(self, profile, api_client: ApiClient):
"no_pending_payment_error2": 2905
}

def get_charge_payments(self, callback=None):
def get_charge_payments(self, limit=100000, callback=None):
"""
Get a list of charge ongoing payments (pending request money)
:param limit:
:param callback:
:return:
"""
return self.__get_payments(action="charge",
limit=limit,
callback=callback)

def get_pay_payments(self, callback=None):
def get_pay_payments(self, limit=100000, callback=None):
"""
Get a list of pay ongoing payments (pending requested money from your profile)
:param limit:
:param callback:
:return:
"""
return self.__get_payments(action="pay",
limit=limit,
callback=callback)

def remind_payment(self, payment: Payment = None, payment_id: int = None) -> bool:
Expand Down Expand Up @@ -166,7 +170,7 @@ def __update_payment(self, action, payment_id):
method='PUT',
ok_error_codes=list(self.__payment_update_error_codes.values()))

def __get_payments(self, action, callback=None):
def __get_payments(self, action, limit, callback=None):
"""
Get a list of ongoing payments with the given action
:return:
Expand All @@ -178,7 +182,7 @@ def __get_payments(self, action, callback=None):
parameters = {
"action": action,
"actor": self.__profile.id,
"limit": 100000
"limit": limit
}
response = self.__api_client.call_api(resource_path=resource_path,
params=parameters,
Expand Down
4 changes: 4 additions & 0 deletions venmo_api/models/base_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class BaseModel(object):
def __str__(self):
return f"{type(self).__name__}:" \
f" ({', '.join('%s=%s' % item for item in vars(self).items() if not item[0].startswith('_'))})"
10 changes: 2 additions & 8 deletions venmo_api/models/payment.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from enum import Enum

from venmo_api import string_to_timestamp, User
from venmo_api import string_to_timestamp, User, BaseModel
from venmo_api import JSONSchema


class Payment(object):
class Payment(BaseModel):

def __init__(self, id_, actor, target, action, amount, audience, date_created, date_reminded, date_completed,
note, status):
Expand Down Expand Up @@ -61,12 +61,6 @@ def from_json(cls, json):
status=PaymentStatus(parser.get_status())
)

def __str__(self) -> str:
return '%s(%s)' % (
type(self).__name__,
', '.join('%s=%s' % item for item in vars(self).items())
)


class PaymentStatus(Enum):
SETTLED = 'settled'
Expand Down
17 changes: 9 additions & 8 deletions venmo_api/models/payment_method.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from typing import Dict
from enum import Enum
from venmo_api import JSONSchema
from venmo_api import JSONSchema, BaseModel
import logging


class PaymentMethod(object):
class PaymentMethod(BaseModel):
def __init__(self, pid: str, p_role: str, p_name: str, p_type: str):
super().__init__()

Expand All @@ -23,23 +24,23 @@ def from_json(cls, json: Dict):
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]
payment_class = payment_type.get(p_type)
if not payment_class:
logging.warning(f"Skipped a payment_method; No schema existed for the payment_method: {p_type}")
return

return payment_class(pid=pid,
p_role=p_role,
p_name=p_name,
p_type=p_type)

def __str__(self):
return f"Payment: id: {self.id}, role: {self.role}, name: {self.name}, type: {self.type}"


class VenmoBalance(PaymentMethod):
class VenmoBalance(PaymentMethod, BaseModel):
def __init__(self, pid, p_role, p_name, p_type):
super().__init__(pid, p_role, p_name, p_type)


class BankAccount(PaymentMethod):
class BankAccount(PaymentMethod, BaseModel):
def __init__(self, pid, p_role, p_name, p_type):
super().__init__(pid, p_role, p_name, p_type)

Expand Down
13 changes: 2 additions & 11 deletions venmo_api/models/transaction.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from enum import Enum
from venmo_api import string_to_timestamp
from venmo_api import string_to_timestamp, BaseModel
from venmo_api import User
from venmo_api import get_phone_model_from_json
from venmo_api import JSONSchema


class Transaction(object):
class Transaction(BaseModel):

def __init__(self, story_id, payment_id, date_completed, date_created,
date_updated, payment_type, amount, audience, status,
Expand Down Expand Up @@ -71,15 +71,6 @@ def from_json(cls, json):
actor=actor,
target=target)

def __str__(self):

return f'Transaction: story_id: {self.id}, payment_id: {self.payment_id}, date_completed: {self.date_completed},' \
f'date_created: {self.date_created}, date_updated: {self.date_updated},' \
f'payment_type: {self.payment_type}, amount: {self.amount},' \
f'audience: {self.audience}, status: {self.status}, note: {self.note}, device_used: {self.device_used},\n' \
f'actor_user: {self.actor},\n' \
f'target_user: {self.target}\n'


class TransactionType(Enum):
PAYMENT = 'payment'
Expand Down
9 changes: 2 additions & 7 deletions venmo_api/models/user.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from venmo_api import string_to_timestamp
from venmo_api import string_to_timestamp, BaseModel
from venmo_api import JSONSchema


class User(object):
class User(BaseModel):

def __init__(self, user_id, username, first_name, last_name, display_name, phone,
profile_picture_url, about, date_joined, is_group, is_active):
Expand Down Expand Up @@ -61,8 +61,3 @@ def from_json(cls, json, is_profile=False):
date_joined=date_joined_timestamp,
is_group=parser.get_is_group(),
is_active=parser.get_is_active())

def __str__(self):
return f'User: id: {self.id}, username: {self.username}, first_name: {self.first_name}, last_name: {self.last_name}'\
f' display_name: {self.display_name}, phone: {self.phone}, profile_picture_url: {self.profile_picture_url}, about: {self.about},'\
f' joined: {self.date_joined}, is_group: {self.is_group}, is_active: {self.is_active}'

0 comments on commit 8f85f8d

Please sign in to comment.