Skip to content

Commit 31df1a5

Browse files
authored
Merge pull request #29 from alnacle/pagination-fix
Fix pagination URL encoding.
2 parents 1785d23 + 09b437f commit 31df1a5

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

amadeus/client/request.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def __request_for_verb(self):
112112

113113
# Encodes the params before sending them
114114
def _encoded_params(self):
115-
return urlencode(self.params)
115+
return self._urlencode(self.params)
116116

117117
# Builds up the full URL based on the scheme, host, path, and params
118118
def __full_url(self):
@@ -141,3 +141,20 @@ def __add_bearer_token_header(self):
141141
# Applies all the headers to the HTTP Request object
142142
def __apply_headers(self, http_request):
143143
http_request.headers = self.headers
144+
145+
# Helper method to prepare the parameter encoding
146+
def _urlencode(self, d):
147+
return urlencode(self._flatten_keys(d, '', {}))
148+
149+
# Flattens the hash keys, so page: { offset: 1 } becomes page[offet] = 1
150+
def _flatten_keys(self, d, key, out):
151+
if type(d) is not dict:
152+
raise TypeError('Only dicts can be encoded')
153+
154+
for k in d:
155+
keystr = k if not key else '[{}]'.format(k)
156+
if type(d[k]) is dict:
157+
self._flatten_keys(d[k], str(key) + str(keystr), out)
158+
else:
159+
out['{}{}'.format(key, keystr)] = d[k]
160+
return out

0 commit comments

Comments
 (0)