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

馃悰 Source Delighted: Fix pagination for survey_responses, bounces and unsubscribes streams #9275

Merged
merged 4 commits into from
Jan 4, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -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.0
LABEL io.airbyte.version=0.1.1
LABEL io.airbyte.name=airbyte/source-delighted
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ tests:
- config_path: "secrets/config.json"
configured_catalog_path: "integration_tests/configured_catalog.json"
empty_streams: ["bounces"]
incremental: # TODO if your connector does not implement incremental sync, remove this block
incremental:
- config_path: "secrets/config.json"
configured_catalog_path: "integration_tests/configured_catalog.json"
future_state_path: "integration_tests/abnormal_state.json"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,21 @@
"type": ["null", "integer"]
},
"person_properties": {
"type": "object"
"type": ["object", "null"],
"properties": {
"Delighted Source": {
"type": ["null", "string"]
},
"Delighted Device Type": {
"type": ["null", "string"]
},
"Delighted Operating System": {
"type": ["null", "string"]
},
"Delighted Browser": {
"type": ["null", "string"]
}
}
},
"notes": {
"type": "array",
Expand Down Expand Up @@ -102,19 +116,5 @@
"required": ["id", "value", "question"]
Zirochkaa marked this conversation as resolved.
Show resolved Hide resolved
}
}
},
"required": [
"id",
"person",
"survey_type",
"score",
"comment",
"permalink",
"created_at",
"updated_at",
"person_properties",
"notes",
"tags",
"additional_answers"
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class DelightedStream(HttpStream, ABC):

# Page size
limit = 100
page = 1

# Define primary key to all streams as primary key
primary_key = "id"
Expand All @@ -32,12 +33,10 @@ def __init__(self, since: int, **kwargs):
self.since = since

def next_page_token(self, response: requests.Response) -> Optional[Mapping[str, Any]]:
# Getting next page link
next_page = response.links.get("next", None)
if next_page:
return dict(parse_qsl(urlparse(next_page.get("url")).query))
else:
return None
response_data = response.json()
if response_data and len(response_data) == self.limit:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can response_data be not an array?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it'll always an array.

self.page += 1
return {"page": self.page}

def request_params(
self, stream_state: Mapping[str, Any], stream_slice: Mapping[str, any] = None, next_page_token: Mapping[str, Any] = None
Expand All @@ -49,8 +48,7 @@ def request_params(
return params

def parse_response(self, response: requests.Response, **kwargs) -> Iterable[Mapping]:
records = response.json()
yield from records
yield from response.json()


class IncrementalDelightedStream(DelightedStream, ABC):
Expand All @@ -77,38 +75,38 @@ def request_params(self, stream_state=None, **kwargs):


class People(IncrementalDelightedStream):
def path(
self, stream_state: Mapping[str, Any] = None, stream_slice: Mapping[str, Any] = None, next_page_token: Mapping[str, Any] = None
) -> str:
def path(self, **kwargs) -> str:
return "people.json"

def next_page_token(self, response: requests.Response) -> Optional[Mapping[str, Any]]:
# Getting next page link
next_page = response.links.get("next", None)
if next_page:
return {"page_info": dict(parse_qsl(urlparse(next_page.get("url")).query)).get("page_info")}
else:
return None
Zirochkaa marked this conversation as resolved.
Show resolved Hide resolved


class Unsubscribes(IncrementalDelightedStream):
cursor_field = "unsubscribed_at"
primary_key = "person_id"

def path(
self, stream_state: Mapping[str, Any] = None, stream_slice: Mapping[str, Any] = None, next_page_token: Mapping[str, Any] = None
) -> str:
def path(self, **kwargs) -> str:
return "unsubscribes.json"


class Bounces(IncrementalDelightedStream):
cursor_field = "bounced_at"
primary_key = "person_id"

def path(
self, stream_state: Mapping[str, Any] = None, stream_slice: Mapping[str, Any] = None, next_page_token: Mapping[str, Any] = None
) -> str:
def path(self, **kwargs) -> str:
return "bounces.json"


class SurveyResponses(IncrementalDelightedStream):
cursor_field = "updated_at"

def path(
self, stream_state: Mapping[str, Any] = None, stream_slice: Mapping[str, Any] = None, next_page_token: Mapping[str, Any] = None
) -> str:
def path(self, **kwargs) -> str:
return "survey_responses.json"

def request_params(self, stream_state=None, **kwargs):
Expand Down Expand Up @@ -148,4 +146,9 @@ def check_connection(self, logger, config) -> Tuple[bool, any]:
def streams(self, config: Mapping[str, Any]) -> List[Stream]:
auth = self._get_authenticator(config)
args = {"authenticator": auth, "since": config["since"]}
return [People(**args), Unsubscribes(**args), Bounces(**args), SurveyResponses(**args)]
return [
Bounces(**args),
People(**args),
SurveyResponses(**args),
Unsubscribes(**args),
]
1 change: 1 addition & 0 deletions docs/integrations/sources/delighted.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,5 @@ This connector supports `API PASSWORD` as the authentication method.

| Version | Date | Pull Request | Subject |
| :--- | :--- | :--- | :--- |
| 0.1.1 | 2022-01-04 | [9275](https://github.com/airbytehq/airbyte/pull/9275) | Fix pagination handling for `survey_responses`, `bounces` and `unsubscribes` streams |
Zirochkaa marked this conversation as resolved.
Show resolved Hide resolved
| 0.1.0 | 2021-10-27 | [4551](https://github.com/airbytehq/airbyte/pull/4551) | Add Delighted source connector |