Skip to content

Commit

Permalink
🎉 Survey Monkey: Improve 'check' using '/users/me' API call (#7868)
Browse files Browse the repository at this point in the history
* Improve 'check' using '/users/me' API call

Signed-off-by: Sergey Chvalyuk <grubberr@gmail.com>
  • Loading branch information
grubberr authored Nov 18, 2021
1 parent 46e1f65 commit b76d155
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 11 deletions.
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 @@ -5660,7 +5660,7 @@
supportsNormalization: false
supportsDBT: false
supported_destination_sync_modes: []
- dockerImage: "airbyte/source-surveymonkey:0.1.3"
- dockerImage: "airbyte/source-surveymonkey:0.1.4"
spec:
documentationUrl: "https://docs.airbyte.io/integrations/sources/surveymonkey"
connectionSpecification:
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,14 +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)
return True, None
response = requests.get(url=url, headers=authenticator.get_auth_header())
response.raise_for_status()
return self._check_scopes(response.json())
except Exception as e:
return False, repr(e)

Expand All @@ -36,3 +52,11 @@ 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:
return False, "missed required scopes: " + ", ".join(missed_scopes)
return True, None
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

0 comments on commit b76d155

Please sign in to comment.