From 918c473512c0fbb56505dea7f71ad9a4fe4fbbbb Mon Sep 17 00:00:00 2001 From: dzaslavskiy Date: Fri, 19 Apr 2024 12:27:07 -0400 Subject: [PATCH] add raw response endpoint (#110) * add raw response endpoint * bump python unit test version --- .github/workflows/unit-tests.yaml | 4 ++-- qualtrix/api.py | 8 +++++++- qualtrix/client.py | 5 ++++- requirements.txt | 4 ++-- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/.github/workflows/unit-tests.yaml b/.github/workflows/unit-tests.yaml index f49395e..3f805b8 100644 --- a/.github/workflows/unit-tests.yaml +++ b/.github/workflows/unit-tests.yaml @@ -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 diff --git a/qualtrix/api.py b/qualtrix/api.py index 75a3156..bb276cd 100644 --- a/qualtrix/api.py +++ b/qualtrix/api.py @@ -25,6 +25,7 @@ class SurveyModel(BaseModel): class ResponseModel(SurveyModel): responseId: str + raw: bool | None = False class SessionModel(SurveyModel): @@ -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) @@ -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) diff --git a/qualtrix/client.py b/qualtrix/client.py index 43e5e74..3cdb9c5 100644 --- a/qualtrix/client.py +++ b/qualtrix/client.py @@ -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}", @@ -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 diff --git a/requirements.txt b/requirements.txt index 18d2af1..35678ee 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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