Skip to content

Commit 9077e40

Browse files
committed
Add possibility to use dash contained URLs
1 parent 0d660c9 commit 9077e40

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Check out all the resources and Python code examples in the official [Mailjet Do
2626
- [Client / Call configuration specifics](#client--call-configuration-specifics)
2727
- [API versioning](#api-versioning)
2828
- [Base URL](#base-url)
29+
- [URL path](#url-path)
2930
- [Request examples](#request-examples)
3031
- [POST request](#post-request)
3132
- [Simple POST request](#simple-post-request)
@@ -147,6 +148,22 @@ mailjet = Client(auth=(api_key, api_secret),api_url="https://api.us.mailjet.com/
147148

148149
If your account has been moved to Mailjet's **US architecture**, the URL value you need to set is `https://api.us.mailjet.com`.
149150

151+
### URL path
152+
153+
According to python special characters limitations we can't use slashes `/` and dashes `-` which is acceptable for URL path building. Instead python client uses another way for path building. You should replase slashes `/` by underscore `_` and dashes `-` by capitalizing next letter in path.
154+
For example, to reach `statistics/link-click` path you should call `statistics_linkClick` attribute of python client.
155+
156+
```python
157+
# GET `statistics/link-click`
158+
mailjet = Client(auth=(api_key, api_secret))
159+
filters = {
160+
'CampaignId': 'xxxxxxx'
161+
}
162+
result = mailjet.statistics_linkClick.get(filters=filters)
163+
print result.status_code
164+
print result.json()
165+
```
166+
150167
## Request examples
151168

152169
### POST request

mailjet_rest/client.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import json
55
import logging
6+
import re
67

78
import requests
89
from requests.compat import urljoin
@@ -11,6 +12,13 @@
1112
requests.packages.urllib3.disable_warnings()
1213

1314

15+
def prepare_url(key: str):
16+
"""Replaces capital letters to lower one with dash prefix."""
17+
char_elem = key.group(0)
18+
if char_elem.isupper():
19+
return '-' + char_elem.lower()
20+
21+
1422
class Config(object):
1523
DEFAULT_API_URL = 'https://api.mailjet.com/'
1624
API_REF = 'http://dev.mailjet.com/email-api/v3/'
@@ -79,6 +87,7 @@ def __init__(self, auth=None, **kwargs):
7987
self.config = Config(version=version, api_url=api_url)
8088

8189
def __getattr__(self, name):
90+
name = re.sub(r"[A-Z]", prepare_url, name)
8291
split = name.split('_')
8392
#identify the resource
8493
fname = split[0]

0 commit comments

Comments
 (0)