Skip to content

Commit

Permalink
馃帀 Source SurveyMonkey: add OAuth support (#7433)
Browse files Browse the repository at this point in the history
* Add OAuth support

* Upd changelog

* Upd spec
  • Loading branch information
gaart committed Oct 31, 2021
1 parent 8d95cb8 commit 74c78b9
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 12 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.0",
"dockerImageTag": "0.1.2",
"documentationUrl": "https://docs.airbyte.io/integrations/sources/surveymonkey"
}
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@
- name: Survey Monkey
sourceDefinitionId: badc5925-0485-42be-8caa-b34096cb71b5
dockerRepository: airbyte/source-surveymonkey
dockerImageTag: 0.1.0
dockerImageTag: 0.1.2
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.1
LABEL io.airbyte.version=0.1.2
LABEL io.airbyte.name=airbyte/source-surveymonkey
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
class SourceSurveymonkey(AbstractSource):
def check_connection(self, logger: AirbyteLogger, config: Mapping[str, Any]) -> Tuple[bool, Any]:
try:
authenticator = TokenAuthenticator(token=config["access_token"])
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)
Expand All @@ -27,7 +27,17 @@ def check_connection(self, logger: AirbyteLogger, config: Mapping[str, Any]) ->
return False, repr(e)

def streams(self, config: Mapping[str, Any]) -> List[Stream]:
authenticator = TokenAuthenticator(token=config["access_token"])
authenticator = self.get_authenticator(config)
start_date = pendulum.parse(config["start_date"])
args = {"authenticator": authenticator, "start_date": start_date}
return [Surveys(**args), SurveyPages(**args), SurveyQuestions(**args), SurveyResponses(**args)]

@staticmethod
def get_authenticator(config: Mapping[str, Any]):
# backward compatibility
if config.get("access_token"):
token = config.get("access_token")
else:
token = config.get("credentials", {}).get("access_token")

return TokenAuthenticator(token=token)
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"documentationUrl": "https://docs.airbyte.io/integrations/sources/surveymonkey",
"connectionSpecification": {
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "PostHog Spec",
"title": "SurveyMonkey Spec",
"type": "object",
"required": ["start_date", "access_token"],
"additionalProperties": false,
"required": ["start_date"],
"additionalProperties": true,
"properties": {
"start_date": {
"title": "Start Date",
Expand All @@ -14,11 +14,77 @@
"pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z?$",
"examples": ["2021-01-01T00:00:00Z"]
},
"access_token": {
"type": "string",
"airbyte_secret": true,
"description": "API Token. See the <a href=\"https://docs.airbyte.io/integrations/sources/surveymonkey\">docs</a> for information on how to generate this key."
"credentials": {
"type": "object",
"title": "Authentication Type",
"oneOf": [
{
"title": "Authenticate via OAuth",
"type": "object",
"required": [
"client_id",
"client_secret",
"access_token",
"auth_type"
],
"properties": {
"auth_type": {
"type": "string",
"const": "OAuth",
"enum": ["OAuth"],
"default": "OAuth",
"order": 0
},
"client_id": {
"title": "Client ID",
"type": "string",
"description": "The Client ID of your developer application",
"airbyte_secret": true
},
"client_secret": {
"title": "Client Secret",
"type": "string",
"description": "The client secret of your developer application",
"airbyte_secret": true
},
"access_token": {
"title": "Access Token",
"type": "string",
"description": "An access token generated using the above client ID and secret",
"airbyte_secret": true
}
}
},
{
"type": "object",
"title": "Token Authentication",
"additionalProperties": false,
"required": ["access_token", "auth_type"],
"properties": {
"auth_type": {
"type": "string",
"const": "Token",
"enum": ["Token"],
"default": "Token",
"order": 0
},
"access_token": {
"type": "string",
"airbyte_secret": true,
"description": "API Token. See the <a href=\"https://docs.airbyte.io/integrations/sources/surveymonkey\">docs</a> for information on how to generate this key."
}
}
}
]
}
}
},
"authSpecification": {
"auth_type": "oauth2.0",
"oauth2Specification": {
"rootObject": ["credentials", 0],
"oauthFlowInitParameters": [["client_id"], ["client_secret"]],
"oauthFlowOutputParameters": [["access_token"]]
}
}
}
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.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 |
| 0.1.0 | 2021-07-06 | [4097](https://github.com/airbytehq/airbyte/pull/4097) | Initial Release |

0 comments on commit 74c78b9

Please sign in to comment.