Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New IDP class and new distribution methods for generating links #17

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ dist/
QualtricsAPI.egg-info
setup.py
pipfile.lock
build/
3 changes: 3 additions & 0 deletions QualtricsAPI/IDP/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .importedDataProject import *

__all__ = ['importedDataProject']
494 changes: 494 additions & 0 deletions QualtricsAPI/IDP/importedDataProject.py

Large diffs are not rendered by default.

11 changes: 8 additions & 3 deletions QualtricsAPI/Setup/credentials.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import numpy as np
import os


class Credentials(object):
''' This class handles the setup of credentials needed to setup the Qualtrics API Authorization. Use the
qualtrics_api_credentials method to create enviornment variables that will automatically populate the correct
Expand All @@ -21,7 +22,7 @@ def qualtrics_api_credentials(self, token, data_center, directory_id=None):
:return: Nothing explicitly, However you just create enviornment variables that will populate you HTTP Headers.
'''
assert len(token) == 40, 'Hey there! It looks like your api token is a the incorrect length. It needs to be 40 characters long. Please try again.'
if directory_id:
if directory_id:
assert len(directory_id) == 20, 'Hey there! It looks like your api directory ID is a the incorrect length. It needs to be 20 characters long. Please try again.'
assert directory_id[:5] == 'POOL_', 'Hey there! It looks like your directory ID is incorrect. You can find the directory ID on the Qualtrics site under your account settings. Please try again.'
os.environ['directory_id'] = directory_id
Expand All @@ -30,21 +31,25 @@ def qualtrics_api_credentials(self, token, data_center, directory_id=None):
os.environ['data_center'] = data_center
return

def header_setup(self, content_type=False, xm=True, path=None):
def header_setup(self, content_type=False, xm=True, path=None, accept=False):
'''This method accepts the argument content_type and returns the correct header, and base url. (Not a User-Facing Method)

response => path = 'responseexports/'
distributions => path = 'distributions'

:param content_type: use to return json response.
:param accept: use to add accept param to header. (required for some GET requests)
:return: a HTML header and base url.
'''
if xm:
assert os.environ['directory_id'], 'Hey there! This endpoint is only accessible for XM Directory Users . If you have access to the XM Directory, then be sure to include your directory_id when you use the qualtrics_api_credentials() method. '
path = 'directories/{0}/'.format(os.environ['directory_id']) if xm else path
path = 'directories/{0}/'.format(
os.environ['directory_id'])+path if xm else path

header = {"x-api-token": os.environ['token']}
base_url = f"https://{os.environ['data_center']}.qualtrics.com/API/v3/{path}"
if content_type is True:
header["Content-Type"] = "application/json"
if accept is True:
header["Accept"] = "application/json"
return header, base_url
492 changes: 441 additions & 51 deletions QualtricsAPI/Survey/distributions.py

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions QualtricsAPI/Survey/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ def get_survey_response(self, survey=None, response=None, verbose=False, verify=
'Qualtrics Error\n(Http Error: 403 - Forbidden): The Qualtrics API user was authenticated and made a valid request, but is not authorized to access this requested resource.')
except (Qualtrics503Error, Qualtrics504Error) as e:
# Recursive call to handle Internal Server Errors
return self.get_survey_response(self, survey=survey, response=response, verbose=verbose)
return self.get_survey_response(survey=survey, response=response, verbose=verbose)
except (Qualtrics500Error, Qualtrics400Error, Qualtrics401Error, Qualtrics403Error) as e:
# Handle Authorization/Bad Request Errors
return print(e)
Expand Down Expand Up @@ -409,7 +409,7 @@ def create_survey_response(self, survey=None, dynamic_payload={}, verbose=False,
'Qualtrics Error\n(Http Error: 403 - Forbidden): The Qualtrics API user was authenticated and made a valid request, but is not authorized to access this requested resource.')
except (Qualtrics503Error, Qualtrics504Error) as e:
# Recursive call to handle Internal Server Errors
return self.create_survey_response(self, survey=survey, dynamic_payload=dynamic_payload, verify=verify)
return self.create_survey_response(survey=survey, dynamic_payload=dynamic_payload, verify=verify)
except (Qualtrics500Error, Qualtrics400Error, Qualtrics401Error, Qualtrics403Error) as e:
# Handle Authorization/Bad Request Errors
return print(e, response['meta'])
Expand Down
Loading