Skip to content

Commit b427bf3

Browse files
committed
Added test URLs
1 parent 02348bb commit b427bf3

File tree

4 files changed

+31
-18
lines changed

4 files changed

+31
-18
lines changed

CONTRIBUTING.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,17 @@ Please use the [GitHub Issues](https://github.com/dynata/python-cmixapi-client/i
4848

4949
### Releasing
5050

51-
The release can be done completely on the command line:
51+
The release can be done completely on the command line. First make sure the version number has been updated in `setup.py`. Then
5252

53+
git commit -am "feature(s) for this release"
54+
git push origin dev
5355
git tag -a 0.1.0 -m "Initial release with minimal functionality used by PopResearch"
5456
git push origin 0.1.0
5557
python3 -m pip install --user --upgrade setuptools wheel
5658
python3 setup.py sdist bdist_wheel
5759
python3 -m pip install --user --upgrade twine
5860
python3 -m twine upload dist/*
5961

60-
but it's also a good idea to attach the `.whl` and `.tar.gz` files to the release in GitHub.
62+
and it's also a good idea to attach the `.whl` and `.tar.gz` files to the release in GitHub.
6163

6264
Thats it.

CmixAPIClient/api.py

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,27 @@
1010
CMIX_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:

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ A Python client library for the [Dynata Cmix API](https://wiki2.criticalmix.net/
88

99
## Setup
1010

11-
Something here
11+
pip install python-cmixapi-client
1212

1313
## Example Usage
1414

15+
from CmixAPIClient.api import CmixAPI
16+
1517
cmix = CmixAPI(
1618
username="test_username",
1719
password="test_password",

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setuptools.setup(
77
name="python-cmixapi-client",
8-
version="0.1.0",
8+
version="0.1.2",
99
author="Bradley Wogsland",
1010
author_email="bradley@wogsland.org",
1111
description="A Python client for the Cmix API.",

0 commit comments

Comments
 (0)