@@ -163,6 +163,19 @@ def add_extra_url_params(self, url, params):
163
163
164
164
return url
165
165
166
+ def get_survey_data_layouts (self , survey_id ):
167
+ self .check_auth_headers ()
168
+ data_layouts_url = '{}/surveys/{}/data-layouts' .format (CMIX_SERVICES ['survey' ][self .url_type ], survey_id )
169
+ data_layouts_response = requests .get (data_layouts_url , headers = self ._authentication_headers )
170
+ if data_layouts_response .status_code != 200 :
171
+ raise CmixError (
172
+ 'CMIX returned a non-200 response code while getting data_layouts: {} and error {}' .format (
173
+ data_layouts_response .status_code ,
174
+ data_layouts_response .text
175
+ )
176
+ )
177
+ return data_layouts_response .json ()
178
+
166
179
def get_survey_definition (self , survey_id ):
167
180
self .check_auth_headers ()
168
181
definition_url = '{}/surveys/{}/definition' .format (CMIX_SERVICES ['survey' ][self .url_type ], survey_id )
@@ -209,6 +222,19 @@ def get_survey_status(self, survey_id):
209
222
raise CmixError ('Get Survey Status returned without a status. Response: {}' .format (status_response .json ()))
210
223
return status .lower ()
211
224
225
+ def get_survey_sources (self , survey_id ):
226
+ self .check_auth_headers ()
227
+ sources_url = '{}/surveys/{}/sources' .format (CMIX_SERVICES ['survey' ][self .url_type ], survey_id )
228
+ sources_response = requests .get (sources_url , headers = self ._authentication_headers )
229
+ if sources_response .status_code != 200 :
230
+ raise CmixError (
231
+ 'CMIX returned a non-200 response code while getting sources: {} and error {}' .format (
232
+ sources_response .status_code ,
233
+ sources_response .text
234
+ )
235
+ )
236
+ return sources_response .json ()
237
+
212
238
def get_survey_completes (self , survey_id ):
213
239
return self .get_survey_respondents (survey_id , "COMPLETE" , True )
214
240
@@ -255,25 +281,14 @@ def create_export_archive(self, survey_id, export_type):
255
281
)
256
282
archive_json = archive_response .json ()
257
283
258
- layout_url = '{}/surveys/{}/data-layouts/' .format (CMIX_SERVICES ['survey' ]["BASE_URL" ], survey_id )
259
- layout_response = requests .get (layout_url , headers = self ._authentication_headers )
260
- if layout_response .status_code != 200 :
261
- raise CmixError (
262
- 'CMIX returned a non-200 response code: {} and error {}' .format (
263
- layout_response .status_code ,
264
- layout_response .text
265
- )
266
- )
284
+ layout_json = self .get_survey_data_layouts (survey_id )
267
285
layout_id = None
268
- for layout in layout_response . json () :
286
+ for layout in layout_json :
269
287
if layout .get ('name' ) == 'Default' :
270
288
layout_id = layout .get ('id' )
271
289
if layout_id is None :
272
290
raise CmixError (
273
- 'Layouts response did not contain a "Default" layout. Response Code: {}, Body {}' .format (
274
- layout_response .status_code ,
275
- layout_response .content
276
- )
291
+ 'Layouts response did not contain a "Default" layout.'
277
292
)
278
293
279
294
archive_json ['dataLayoutId' ] = layout_id
0 commit comments