1010CMIX_SERVICES = {
1111 'auth' : {
1212 'BASE_URL' : 'https://auth.cmix.com' ,
13+ 'TEST_URL' : 'https://kaleidoscope-auth.cmix.com' ,
1314 },
1415 'file' : {
1516 'BASE_URL' : 'https://file-processing.cmix.com' ,
17+ 'TEST_URL' : 'https://kaleidoscope-file-processing.cmix.com' ,
1618 },
1719 'launchpad' : {
1820 'BASE_URL' : 'https://launchpad.cmix.com' ,
21+ 'TEST_URL' : 'https://kaleidoscope-launchpad.cmix.com' ,
1922 },
2023 'reporting' : {
2124 'BASE_URL' : 'https://reporting-api.cmix.com' ,
25+ 'TEST_URL' : 'https://kaleidoscope-reporting-api.cmix.com' ,
2226 },
2327 'survey' : {
2428 'BASE_URL' : 'https://survey-api.cmix.com' ,
29+ 'TEST_URL' : 'https://kaleidoscope-survey-api.cmix.com' ,
2530 },
2631 'test' : {
2732 'BASE_URL' : 'https://test.cmix.com' ,
33+ 'TEST_URL' : 'https://kaleidoscope-test.cmix.com' ,
2834 },
2935}
3036
@@ -46,13 +52,16 @@ class CmixAPI(object):
4652 # valid extra survey url params
4753 SURVEY_PARAMS_STATUS_AFTER = 'statusAfter'
4854
49- def __init__ (self , username = None , password = None , client_id = None , client_secret = None , * args , ** kwargs ):
55+ def __init__ (self , username = None , password = None , client_id = None , client_secret = None , test = False , * args , ** kwargs ):
5056 if None in [username , password , client_id , client_secret ]:
5157 raise CmixError ("All authentication data is required." )
5258 self .username = username
5359 self .password = password
5460 self .client_id = client_id
5561 self .client_secret = client_secret
62+ self .url_type = 'BASE_URL'
63+ if test is True :
64+ self .url_type = 'TEST_URL'
5665
5766 def check_auth_headers (self ):
5867 if self ._authentication_headers is None :
@@ -67,7 +76,7 @@ def authenticate(self, *args, **kwargs):
6776 "password" : self .password
6877 }
6978
70- auth_url = '{}/access-token' .format (CMIX_SERVICES ['auth' ]['BASE_URL' ])
79+ auth_url = '{}/access-token' .format (CMIX_SERVICES ['auth' ][self . url_type ])
7180 try :
7281 auth_response = requests .post (auth_url , json = auth_payload , headers = {"Content-Type" : "application/json" })
7382 if auth_response .status_code != 200 :
@@ -95,7 +104,7 @@ def fetch_banner_filter(self, survey_id, question_a, question_b, response_id):
95104 response_id
96105 )
97106 )
98- base_url = CMIX_SERVICES ['reporting' ]['BASE_URL' ]
107+ base_url = CMIX_SERVICES ['reporting' ][self . url_type ]
99108 url = '{}/surveys/{}/response-counts' .format (base_url , survey_id )
100109 payload = {
101110 'testYN' : 'LIVE' ,
@@ -125,7 +134,7 @@ def fetch_raw_results(self, survey_id, payload):
125134 '''
126135 self .check_auth_headers ()
127136 log .debug ('Requesting raw results for CMIX survey {}' .format (survey_id ))
128- base_url = CMIX_SERVICES ['reporting' ]['BASE_URL' ]
137+ base_url = CMIX_SERVICES ['reporting' ][self . url_type ]
129138 url = '{}/surveys/{}/response-counts' .format (base_url , survey_id )
130139 response = requests .post (url , headers = self ._authentication_headers , json = payload )
131140 return response .json ()
@@ -140,7 +149,7 @@ def get_surveys(self, status, *args, **kwargs):
140149 get_surveys('status', extra_params=params)
141150 '''
142151 self .check_auth_headers ()
143- base_url = CMIX_SERVICES ['survey' ]['BASE_URL' ]
152+ base_url = CMIX_SERVICES ['survey' ][self . url_type ]
144153 surveys_url = '{}/surveys?status={}' .format (base_url , status )
145154 extra_params = kwargs .get ('extra_params' )
146155 if extra_params is not None :
@@ -156,25 +165,25 @@ def add_extra_url_params(self, url, params):
156165
157166 def get_survey_definition (self , survey_id ):
158167 self .check_auth_headers ()
159- definition_url = '{}/surveys/{}/definition' .format (CMIX_SERVICES ['survey' ]['BASE_URL' ], survey_id )
168+ definition_url = '{}/surveys/{}/definition' .format (CMIX_SERVICES ['survey' ][self . url_type ], survey_id )
160169 definition_response = requests .get (definition_url , headers = self ._authentication_headers )
161170 return definition_response .json ()
162171
163172 def get_survey_xml (self , survey_id ):
164173 self .check_auth_headers ()
165- xml_url = '{}/surveys/{}' .format (CMIX_SERVICES ['file' ]['BASE_URL' ], survey_id )
174+ xml_url = '{}/surveys/{}' .format (CMIX_SERVICES ['file' ][self . url_type ], survey_id )
166175 xml_response = requests .get (xml_url , headers = self ._authentication_headers )
167176 return xml_response .content
168177
169178 def get_survey_test_url (self , survey_id ):
170179 self .check_auth_headers ()
171- survey_url = '{}/surveys/{}' .format (CMIX_SERVICES ['survey' ]['BASE_URL' ], survey_id )
180+ survey_url = '{}/surveys/{}' .format (CMIX_SERVICES ['survey' ][self . url_type ], survey_id )
172181 survey_response = requests .get (survey_url , headers = self ._authentication_headers )
173182 test_token = survey_response .json ().get ('testToken' , None )
174183 if test_token is None :
175184 raise CmixError ('Survey endpoint for CMIX ID {} did not return a test token.' .format (survey_id ))
176185 test_link = '{}/#/?cmixSvy={}&cmixTest={}' .format (
177- CMIX_SERVICES ['test' ]['BASE_URL' ],
186+ CMIX_SERVICES ['test' ][self . url_type ],
178187 survey_id ,
179188 test_token
180189 )
@@ -183,7 +192,7 @@ def get_survey_test_url(self, survey_id):
183192 def get_survey_respondents (self , survey_id , respondent_type , live ):
184193 self .check_auth_headers ()
185194 respondents_url = '{}/surveys/{}/respondents?respondentType={}&respondentStatus={}' .format (
186- CMIX_SERVICES ['reporting' ]['BASE_URL' ],
195+ CMIX_SERVICES ['reporting' ][self . url_type ],
187196 survey_id ,
188197 "LIVE" if live else "TEST" ,
189198 respondent_type ,
@@ -193,7 +202,7 @@ def get_survey_respondents(self, survey_id, respondent_type, live):
193202
194203 def get_survey_status (self , survey_id ):
195204 self .check_auth_headers ()
196- status_url = '{}/surveys/{}' .format (CMIX_SERVICES ['survey' ]['BASE_URL' ], survey_id )
205+ status_url = '{}/surveys/{}' .format (CMIX_SERVICES ['survey' ][self . url_type ], survey_id )
197206 status_response = requests .get (status_url , headers = self ._authentication_headers )
198207 status = status_response .json ().get ('status' , None )
199208 if status is None :
@@ -205,7 +214,7 @@ def get_survey_completes(self, survey_id):
205214
206215 def create_export_archive (self , survey_id , export_type ):
207216 self .check_auth_headers ()
208- archive_url = '{}/surveys/{}/archives' .format (CMIX_SERVICES ['survey' ]['BASE_URL' ], survey_id )
217+ archive_url = '{}/surveys/{}/archives' .format (CMIX_SERVICES ['survey' ][self . url_type ], survey_id )
209218 headers = self ._authentication_headers .copy ()
210219 headers ['Content-Type' ] = "application/json"
211220 payload = {
@@ -294,7 +303,7 @@ def update_project(self, project_id, status=None):
294303 if payload_json == {}:
295304 raise CmixError ("No update data was provided for CMIX Project {}" .format (project_id ))
296305
297- url = '{}/projects/{}' .format (CMIX_SERVICES ['survey' ]['BASE_URL' ], project_id )
306+ url = '{}/projects/{}' .format (CMIX_SERVICES ['survey' ][self . url_type ], project_id )
298307 response = requests .patch (url , json = payload_json , headers = self ._authentication_headers )
299308 if response .status_code > 299 :
300309 raise CmixError (
@@ -311,7 +320,7 @@ def create_survey(self, xml_string):
311320 '''
312321 self .check_auth_headers ()
313322
314- url = '{}/surveys/data' .format (CMIX_SERVICES ['file' ]['BASE_URL' ])
323+ url = '{}/surveys/data' .format (CMIX_SERVICES ['file' ][self . url_type ])
315324 payload = {"data" : xml_string }
316325 response = requests .post (url , payload , headers = self ._authentication_headers )
317326 if response .status_code > 299 :
0 commit comments