Skip to content

Commit e23f73e

Browse files
committed
Cleaned recipient.py of static methods and moved it to types package, adjusted recipient_gateway imports accordingly and added more inline comments.
1 parent c3a5848 commit e23f73e

File tree

5 files changed

+143
-146
lines changed

5 files changed

+143
-146
lines changed

test/integration/RecipientTest.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
sys.path.append(os.path.abspath('.'))
77

88
from trolley.configuration import Configuration
9-
from trolley.recipient import Recipient
9+
from trolley.types.recipient import Recipient
1010
from trolley.types.recipient_account import RecipientAccount
1111
from TestSetup import TestSetup
1212
from TestHelper import TestHelper

trolley/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from trolley.configuration import Configuration
22
from trolley.client import Client
33
from trolley.gateway import Gateway
4-
from trolley.recipient import Recipient
4+
from trolley.types.recipient import Recipient
55
from trolley.types.recipient_account import RecipientAccount
66
from trolley.types.log import Log
77
from trolley.types.batch import Batch

trolley/recipient.py

-136
This file was deleted.

trolley/recipient_gateway.py

+58-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
from collections import namedtuple
22
from trolley.exceptions.invalidFieldException import InvalidFieldException
33
import trolley.configuration
4+
from trolley.types.log import Log
45
from trolley.types.meta import Meta
6+
from trolley.types.payment import Payment
7+
from trolley.types.recipient import Recipient
58
from trolley.utils.url_utils import UrlUtils
69

710

@@ -15,13 +18,18 @@ def __init__(self, gateway, config):
1518
self.gateway = gateway
1619
self.config = config
1720

21+
"""
22+
Retrieve a recipient
23+
A recipient_id is required::
24+
recipient.find('R-fjeracjmuflh')
25+
"""
1826
def find(self, recipient_id, term=""):
1927
if recipient_id is None:
2028
raise InvalidFieldException("Recipient id cannot be None.")
2129
endpoint = f'/v1/recipients/{recipient_id}/{term}'
2230
response = trolley.configuration.Configuration.client(
2331
self.config).get(endpoint)
24-
recip = trolley.Recipient.factory(response)
32+
recip = Recipient.factory(response)
2533
recipient = namedtuple("Recipient", recip.keys())(*recip.values())
2634
count = 0
2735
for account in recipient.accounts:
@@ -30,16 +38,27 @@ def find(self, recipient_id, term=""):
3038
count = count + 1
3139
return recipient
3240

41+
"""
42+
Create a recipient
43+
A body is required::
44+
recipient.create({"type": "individual", "firstName": "John",
45+
"lastName": "Smith", "email": "[email protected]"})
46+
"""
3347
def create(self, body):
3448
if body is None:
3549
raise InvalidFieldException("Body cannot be None.")
3650
endpoint = '/v1/recipients/'
3751
response = trolley.configuration.Configuration.client(
3852
self.config).post(endpoint, body)
39-
recip = trolley.Recipient.factory(response)
53+
recip = Recipient.factory(response)
4054
recipient = namedtuple("Recipient", recip.keys())(*recip.values())
4155
return recipient
4256

57+
"""
58+
Update a recipient
59+
A recipient_id and body are required::
60+
recipient.update('R-fjeracjmuflh', {'firstName': 'tom'})
61+
"""
4362
def update(self, recipient_id, body):
4463
if recipient_id is None:
4564
raise InvalidFieldException("Recipient id cannot be None.")
@@ -50,6 +69,11 @@ def update(self, recipient_id, body):
5069
self.config).patch(endpoint, body)
5170
return True
5271

72+
"""
73+
Delete a recipient
74+
A recipient_id is required::
75+
recipient.delete('R-fjeracjmuflh')
76+
"""
5377
def delete(self, recipient_id):
5478
if recipient_id is None:
5579
raise InvalidFieldException("Recipient id cannot be None.")
@@ -58,6 +82,14 @@ def delete(self, recipient_id):
5882
self.config).delete(endpoint)
5983
return True
6084

85+
"""
86+
Delete multiple recipients
87+
A list of recipient_ids is required::
88+
recipient.delete_multiple([
89+
'R-fjeracjmuflh',
90+
'R-ajerasdfuflf'
91+
])
92+
"""
6193
def delete_multiple(self, recipient_ids):
6294
if recipient_ids is None:
6395
raise InvalidFieldException("Recipient ids cannot be None.")
@@ -67,6 +99,11 @@ def delete_multiple(self, recipient_ids):
6799
self.config).delete(endpoint, recipient_ids)
68100
return True
69101

102+
"""
103+
Retrieve Recipient activity logs, by page
104+
A recipient_id is required:
105+
recipient.retrieve_logs('R-fjeracjmuflh')
106+
"""
70107
def retrieve_logs(self, recipient_id, page=1, pageSize=10):
71108
if recipient_id is None:
72109
raise InvalidFieldException("Recipient id cannot be None.")
@@ -78,7 +115,7 @@ def retrieve_logs(self, recipient_id, page=1, pageSize=10):
78115
logs = []
79116
count = 0
80117
for log in response['recipientLogs']:
81-
temp = trolley.Log.factory(log)
118+
temp = Log.factory(log)
82119

83120
logs.insert(count, namedtuple("Log", temp.keys())(*temp.values()))
84121

@@ -89,6 +126,11 @@ def retrieve_logs(self, recipient_id, page=1, pageSize=10):
89126

90127
return logs
91128

129+
"""
130+
Retrieve all payments of the Recipient
131+
A recipient_id is required:
132+
recipient.get_all_payments('R-fjeracjmuflh')
133+
"""
92134
def get_all_payments(self, recipient_id):
93135
if recipient_id is None:
94136
raise InvalidFieldException("Recipient id cannot be None.")
@@ -99,7 +141,7 @@ def get_all_payments(self, recipient_id):
99141
payments = []
100142
count = 0
101143
for payment in response['payments']:
102-
temppayment = trolley.Payment.factory(payment)
144+
temppayment = Payment.factory(payment)
103145
newpayment = namedtuple("Payment", temppayment.keys())(*temppayment.values())
104146
payments.insert(count, newpayment)
105147
count = count + 1
@@ -109,6 +151,11 @@ def get_all_payments(self, recipient_id):
109151

110152
return payments
111153

154+
"""
155+
Retrieve all offline payments of the Recipient
156+
A recipient_id is required:
157+
recipient.get_all_offline_payments('R-fjeracjmuflh')
158+
"""
112159
def get_all_offline_payments(self, recipient_id):
113160
if recipient_id is None:
114161
raise InvalidFieldException("Recipient id cannot be None.")
@@ -119,7 +166,7 @@ def get_all_offline_payments(self, recipient_id):
119166
offlinePayments = []
120167
count = 0
121168
for offlinePayment in response['offlinePayments']:
122-
temppayment = trolley.Payment.factory(offlinePayment)
169+
temppayment = Payment.factory(offlinePayment)
123170
newpayment = namedtuple("Payment", temppayment.keys())(*temppayment.values())
124171
offlinePayments.insert(count, newpayment)
125172
count = count + 1
@@ -134,7 +181,8 @@ def get_all_offline_payments(self, recipient_id):
134181
You can use this generator in a foreach loop to sequentially go through all the
135182
search results without needing to call this method again.
136183
137-
For accessing specific pages, check the search_by_page() method. """
184+
For accessing specific pages, check the search_by_page() method.
185+
"""
138186
def search(self, search=None, name=None, email=None, reference_id=None, start_date=None,
139187
end_date=None, status=None, compliance_status=None, country=None, payout_method=None, currency=None,
140188
order_by=None, sort_by=None):
@@ -156,7 +204,9 @@ def search(self, search=None, name=None, email=None, reference_id=None, start_da
156204

157205
""" Search Recipients by providing a page number.
158206
This method returns a list.
159-
You should use this function when you want to paginate manually. """
207+
You should use this function when you want to paginate manually.
208+
recipient.search_by_page(1,10,'test')
209+
"""
160210
def search_by_page(self, page=1, page_size=10, search=None, name=None, email=None, reference_id=None, start_date=None,
161211
end_date=None, status=None, compliance_status=None, country=None, payout_method=None, currency=None,
162212
order_by=None, sort_by=None):
@@ -169,7 +219,7 @@ def __build_recipients_from_response(self, response, include_meta=False):
169219
recipients = []
170220
count = 0
171221
for recipient in response['recipients']:
172-
temp = trolley.recipient.Recipient.factory(recipient)
222+
temp = Recipient.factory(recipient)
173223

174224
recipient = namedtuple("Recipient", temp.keys())(*temp.values())
175225
recipients.insert(count, recipient)

0 commit comments

Comments
 (0)