Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions mailwizz/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ class Client(Base):
# the DELETE params sent in the request.
params_delete = {}

# Whether or not to pass data to requests using json kwarg
# Only applies (currently) to PUT
send_as_json = False

def __init__(self, options):
self.__populate(options)

Expand Down Expand Up @@ -119,3 +123,6 @@ def __populate(self, options):

if 'headers' in options:
self.headers = options['headers']

if 'send_as_json' in options:
self.send_as_json = options['send_as_json']
9 changes: 6 additions & 3 deletions mailwizz/endpoint/list_subscribers.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def create(self, list_uid: str, data: dict):
client = Client({
'method': Client.METHOD_POST,
'url': self.config.get_api_url('lists/{list_uid}/subscribers'.format(list_uid=list_uid)),
'params_post': data
'params_post': data,
})

return client.request()
Expand All @@ -81,12 +81,14 @@ def create_bulk(self, list_uid: str, data):

return client.request()

def update(self, list_uid: str, subscriber_uid: str, data: dict):
def update(self, list_uid: str, subscriber_uid: str,
data: dict, send_as_json: bool = False):
"""
Update existing subscriber in given list
:param list_uid:
:param subscriber_uid:
:param data:
:param send_as_json: whether or not to send body as json
:return:
"""

Expand All @@ -98,7 +100,8 @@ def update(self, list_uid: str, subscriber_uid: str, data: dict):
subscriber_uid=subscriber_uid
)
),
'params_put': data
'params_put': data,
'send_as_json': send_as_json
})

return client.request()
Expand Down
40 changes: 16 additions & 24 deletions mailwizz/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,38 +56,30 @@ def _make_request(self):
"""

client = self.client
kwargs = {
'url': client.url,
'headers': client.headers,
'timeout': client.timeout
}

if client.is_get_method():
return requests.get(
url=client.url,
params=client.params_get,
headers=client.headers,
timeout=client.timeout
)
kwargs['params'] = client.params_get
return requests.get(**kwargs)

if client.is_post_method():
return requests.post(
url=client.url,
data=client.params_post,
headers=client.headers,
timeout=client.timeout
)
kwargs['data'] = client.params_post
return requests.post(**kwargs)

if client.is_put_method():
return requests.put(
url=client.url,
data=client.params_put,
headers=client.headers,
timeout=client.timeout
)
if client.send_as_json:
kwargs['json'] = client.params_put
else:
kwargs['data'] = client.params_put
return requests.put(**kwargs)

if client.is_delete_method():
return requests.delete(
url=client.url,
data=client.params_put,
headers=client.headers,
timeout=client.timeout
)
kwargs['data'] = client.params_put
return requests.delete(**kwargs)

def _sign(self, request_url):
"""
Expand Down