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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃帀 Survey Monkey: Improve 'check' using '/users/me' API call #7868

Merged
merged 7 commits into from
Nov 18, 2021
Merged
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"sourceDefinitionId": "badc5925-0485-42be-8caa-b34096cb71b5",
"name": "Survey Monkey",
"dockerRepository": "airbyte/source-surveymonkey",
"dockerImageTag": "0.1.3",
"dockerImageTag": "0.1.4",
"documentationUrl": "https://docs.airbyte.io/integrations/sources/surveymonkey"
}
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@
- name: Survey Monkey
sourceDefinitionId: badc5925-0485-42be-8caa-b34096cb71b5
dockerRepository: airbyte/source-surveymonkey
dockerImageTag: 0.1.3
dockerImageTag: 0.1.4
documentationUrl: https://docs.airbyte.io/integrations/sources/surveymonkey
sourceType: api
- name: Tempo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ RUN pip install .
ENV AIRBYTE_ENTRYPOINT "python /airbyte/integration_code/main.py"
ENTRYPOINT ["python", "/airbyte/integration_code/main.py"]

LABEL io.airbyte.version=0.1.3
LABEL io.airbyte.version=0.1.4
LABEL io.airbyte.name=airbyte/source-surveymonkey
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from typing import Any, List, Mapping, Tuple

import pendulum
import requests
from airbyte_cdk.logger import AirbyteLogger
from airbyte_cdk.models import SyncMode
from airbyte_cdk.sources import AbstractSource
from airbyte_cdk.sources.streams import Stream
from airbyte_cdk.sources.streams.http.auth import TokenAuthenticator
Expand All @@ -15,13 +15,30 @@


class SourceSurveymonkey(AbstractSource):

SCOPES = {
"collectors_read",
"contacts_read",
"groups_read",
"library_read",
"responses_read",
"responses_read_detail",
"roles_read",
"surveys_read",
"users_read",
"webhooks_read",
"workgroups_members_read",
"workgroups_read",
"workgroups_shares_read",
}

def check_connection(self, logger: AirbyteLogger, config: Mapping[str, Any]) -> Tuple[bool, Any]:
url = "https://api.surveymonkey.com/v3/users/me"
authenticator = self.get_authenticator(config)
try:
authenticator = self.get_authenticator(config)
start_date = pendulum.parse(config["start_date"])
stream = Surveys(authenticator=authenticator, start_date=start_date)
records = stream.read_records(sync_mode=SyncMode.full_refresh)
next(records)
response = requests.get(url=url, headers=authenticator.get_auth_header())
response.raise_for_status()
self._check_scopes(response.json())
return True, None
except Exception as e:
return False, repr(e)
Expand All @@ -36,3 +53,10 @@ def streams(self, config: Mapping[str, Any]) -> List[Stream]:
def get_authenticator(config: Mapping[str, Any]):
token = config["access_token"]
return TokenAuthenticator(token=token)

@classmethod
def _check_scopes(cls, response_json):
granted_scopes = response_json["scopes"]["granted"]
missed_scopes = cls.SCOPES - set(granted_scopes)
if missed_scopes:
raise Exception("missed required scopes: " + ", ".join(missed_scopes))
antixar marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions docs/integrations/sources/surveymonkey.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ Please read this [docs](https://developer.surveymonkey.com/api/v3/#getting-start

| Version | Date | Pull Request | Subject |
| :--- | :--- | :--- | :--- |
| 0.1.4 | 2021-11-11 | [7868](https://github.com/airbytehq/airbyte/pull/7868) | Improve 'check' using '/users/me' API call |
| 0.1.3 | 2021-11-01 | [7433](https://github.com/airbytehq/airbyte/pull/7433) | Remove unsused oAuth flow parameters |
| 0.1.2 | 2021-10-27 | [7433](https://github.com/airbytehq/airbyte/pull/7433) | Add OAuth support |
| 0.1.1 | 2021-09-10 | [5983](https://github.com/airbytehq/airbyte/pull/5983) | Fix caching for gzip compressed http response |
Expand Down