1
1
# -*- coding: utf-8 -*-
2
2
3
3
"""
4
- firstlanguage
4
+ firstlanguage_python
5
5
6
6
This file was automatically generated by APIMATIC v3.0 (
7
7
https://www.apimatic.io ).
@@ -142,13 +142,14 @@ def get_schema_path(path):
142
142
return path
143
143
144
144
@staticmethod
145
- def serialize_array (key , array , formatting = "indexed" ):
145
+ def serialize_array (key , array , formatting = "indexed" , is_query = False ):
146
146
"""Converts an array parameter to a list of key value tuples.
147
147
148
148
Args:
149
149
key (str): The name of the parameter.
150
150
array (list): The value of the parameter.
151
151
formatting (str): The type of key formatting expected.
152
+ is_query (bool): Decides if the parameters are for query or form.
152
153
153
154
Returns:
154
155
list: A list with key value tuples for the array elements.
@@ -168,6 +169,16 @@ def serialize_array(key, array, formatting="indexed"):
168
169
tuples += [("{0}[{1}]" .format (key , index ), element ) for index , element in enumerate (array )]
169
170
elif formatting == "plain" :
170
171
tuples += [(key , element ) for element in array ]
172
+ elif is_query :
173
+ if formatting == "csv" :
174
+ tuples += [(key , "," .join (str (x ) for x in array ))]
175
+
176
+ elif formatting == "psv" :
177
+ tuples += [(key , "|" .join (str (x ) for x in array ))]
178
+
179
+ elif formatting == "tsv" :
180
+ tuples += [(key , "\t " .join (str (x ) for x in array ))]
181
+
171
182
else :
172
183
raise ValueError ("Invalid format provided." )
173
184
else :
@@ -231,41 +242,25 @@ def append_url_with_query_parameters(url,
231
242
raise ValueError ("URL is None." )
232
243
if parameters is None :
233
244
return url
234
-
235
- for key , value in parameters .items ():
245
+ parameters = APIHelper .process_complex_types_parameters (parameters , array_serialization )
246
+ for index , value in enumerate (parameters ):
247
+ key = value [0 ]
248
+ val = value [1 ]
236
249
seperator = '&' if '?' in url else '?'
237
250
if value is not None :
238
- if isinstance (value , list ):
239
- value = [element for element in value if element ]
240
- if array_serialization == "csv" :
241
- url += "{0}{1}={2}" .format (
242
- seperator ,
243
- key ,
244
- "," .join (quote (str (x ), safe = '' ) for x in value )
245
- )
246
- elif array_serialization == "psv" :
247
- url += "{0}{1}={2}" .format (
248
- seperator ,
249
- key ,
250
- "|" .join (quote (str (x ), safe = '' ) for x in value )
251
- )
252
- elif array_serialization == "tsv" :
253
- url += "{0}{1}={2}" .format (
254
- seperator ,
255
- key ,
256
- "\t " .join (quote (str (x ), safe = '' ) for x in value )
257
- )
258
- else :
259
- url += "{0}{1}" .format (
260
- seperator ,
261
- "&" .join (("{0}={1}" .format (k , quote (str (v ), safe = '' )))
262
- for k , v in APIHelper .serialize_array (key , value , array_serialization ))
263
- )
264
- else :
265
- url += "{0}{1}={2}" .format (seperator , key , quote (str (value ), safe = '' ))
251
+ url += "{0}{1}={2}" .format (seperator , key , quote (str (val ), safe = '' ))
266
252
267
253
return url
268
254
255
+ @staticmethod
256
+ def process_complex_types_parameters (query_parameters , array_serialization ):
257
+ processed_params = []
258
+ for key , value in query_parameters .items ():
259
+ processed_params .extend (
260
+ APIHelper .form_encode (value , key , array_serialization = array_serialization , is_query = True ))
261
+ return processed_params
262
+
263
+
269
264
@staticmethod
270
265
def clean_url (url ):
271
266
"""Validates and processes the given query Url to clean empty slashes.
@@ -315,14 +310,15 @@ def form_encode_parameters(form_parameters,
315
310
@staticmethod
316
311
def form_encode (obj ,
317
312
instance_name ,
318
- array_serialization = "indexed" ):
313
+ array_serialization = "indexed" , is_query = False ):
319
314
"""Encodes a model in a form-encoded manner such as person[Name]
320
315
321
316
Args:
322
317
obj (object): The given Object to form encode.
323
318
instance_name (string): The base name to appear before each entry
324
319
for this object.
325
320
array_serialization (string): The format of array parameter serialization.
321
+ is_query (bool): Decides if the parameters are for query or form.
326
322
327
323
Returns:
328
324
dict: A dictionary of form encoded properties of the model.
@@ -336,11 +332,11 @@ def form_encode(obj,
336
332
if obj is None :
337
333
return []
338
334
elif isinstance (obj , list ):
339
- for element in APIHelper .serialize_array (instance_name , obj , array_serialization ):
340
- retval += APIHelper .form_encode (element [1 ], element [0 ], array_serialization )
335
+ for element in APIHelper .serialize_array (instance_name , obj , array_serialization , is_query ):
336
+ retval += APIHelper .form_encode (element [1 ], element [0 ], array_serialization , is_query )
341
337
elif isinstance (obj , dict ):
342
338
for item in obj :
343
- retval += APIHelper .form_encode (obj [item ], instance_name + "[" + item + "]" , array_serialization )
339
+ retval += APIHelper .form_encode (obj [item ], instance_name + "[" + item + "]" , array_serialization , is_query )
344
340
else :
345
341
retval .append ((instance_name , obj ))
346
342
0 commit comments