Skip to content

Commit 53bbc62

Browse files
committed
Improve Search Methods
By using the UrlUtils.parse method, it will automatically parse all attributes and convert them to lowerCamelCase, as according to the API.
1 parent 79177cc commit 53bbc62

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

paymentrails/recipient_gateway.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from collections import namedtuple
22
from paymentrails.exceptions.invalidFieldException import InvalidFieldException
33
import paymentrails.configuration
4+
from paymentrails.utils import UrlUtils
5+
46

57
class RecipientGateway(object):
68
"""
@@ -46,7 +48,6 @@ def update(self, recipient_id, body):
4648
paymentrails.configuration.Configuration.client(
4749
self.config).patch(endpoint, body)
4850
return True
49-
5051

5152
def delete(self, recipient_id):
5253
if recipient_id is None:
@@ -56,9 +57,10 @@ def delete(self, recipient_id):
5657
self.config).delete(endpoint)
5758
return True
5859

59-
def search(self, page, page_number, term):
60-
endpoint = '/v1/recipients?search=' + term + '&page=' + \
61-
str(page) + '&pageSize=' + str(page_number)
60+
def search(self, page=None, page_size=None, search=None, name=None, email=None, reference_id=None, start_date=None,
61+
end_date=None, status=None, compliance_status=None, country=None, payout_method=None, currency=None,
62+
order_by=None, sort_by=None):
63+
endpoint = '/v1/recipients?' + UrlUtils.parse(locals())
6264
response = paymentrails.configuration.Configuration.client(
6365
self.config).get(endpoint)
6466
recipients = []

paymentrails/utils.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import urllib.parse
2+
3+
4+
class UrlUtils:
5+
@staticmethod
6+
def __to_came_case(string):
7+
# https://stackoverflow.com/a/19053800/6626193
8+
components = string.split('_')
9+
return components[0] + ''.join(x.title() for x in components[1:])
10+
11+
@staticmethod
12+
def parse(attributes):
13+
params = []
14+
for key in attributes.keys():
15+
if key == "self":
16+
continue
17+
if attributes[key] is not None:
18+
param = UrlUtils.__to_came_case(key) + "=" + urllib.parse.quote(str(attributes[key]))
19+
params.append(param)
20+
21+
return "&".join(params)

0 commit comments

Comments
 (0)