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

add raw response endpoint #110

Merged
merged 2 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/unit-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ jobs:
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Set up Python 3.9
- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: 3.9
python-version: 3.11
- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand Down
8 changes: 7 additions & 1 deletion qualtrix/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class SurveyModel(BaseModel):

class ResponseModel(SurveyModel):
responseId: str
raw: bool | None = False


class SessionModel(SurveyModel):
Expand Down Expand Up @@ -52,7 +53,7 @@ async def get_bulk_responses(request: SurveyModel):
@router.post("/response")
async def get_response(request: ResponseModel):
try:
return client.get_response(request.surveyId, request.responseId)
return client.get_response(request.surveyId, request.responseId, request.raw)
except error.QualtricsError as e:
raise HTTPException(status_code=400, detail=e.args)

Expand Down Expand Up @@ -171,6 +172,11 @@ async def session(request: SessionModel):
raise HTTPException(status_code=400, detail=e.args)


@router.get("/contact/{contactId}")
async def contact(contactId: str):
return client.get_contact_by_id(contactId)


@router.get("/contact/{contactId}/responseIds")
async def dist(contactId: str):
return client.get_responseIds_by_contact(contactId)
Expand Down
5 changes: 4 additions & 1 deletion qualtrix/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ def get_link(target_survey_id: str, distribution_id: str):
return link


def get_response(survey_id: str, response_id: str):
def get_response(survey_id: str, response_id: str, raw: bool):
for i in range(settings.RETRY_ATTEMPTS):
r = requests.get(
settings.BASE_URL + f"/surveys/{survey_id}/responses/{response_id}",
Expand Down Expand Up @@ -466,6 +466,9 @@ def get_response(survey_id: str, response_id: str):

survey_answers["response"] = answer

if raw:
survey_answers["raw"] = response

return survey_answers


Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
fastapi==0.109.2
uvicorn==0.27.0.post1
fastapi==0.110.1
uvicorn==0.29.0
starlette-prometheus==0.9.0
google-api-python-client==2.116.0
google-auth-httplib2==0.2.0
Expand Down