Skip to content

Commit

Permalink
add raw response endpoint (#110)
Browse files Browse the repository at this point in the history
* add raw response endpoint

* bump python unit test version
  • Loading branch information
dzaslavskiy authored Apr 19, 2024
1 parent bbf0f9f commit 918c473
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
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

0 comments on commit 918c473

Please sign in to comment.