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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🎉 Source Snapchat Marketing: support oauth #7811

Merged
merged 13 commits into from
Nov 19, 2021
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@
- name: Snapchat Marketing
sourceDefinitionId: 200330b2-ea62-4d11-ac6d-cfe3e3f8ab2b
dockerRepository: airbyte/source-snapchat-marketing
dockerImageTag: 0.1.2
dockerImageTag: 0.1.3
documentationUrl: https://docs.airbyte.io/integrations/sources/snapchat-marketing
sourceType: api
- name: Snowflake
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.2
LABEL io.airbyte.version=0.1.3
LABEL io.airbyte.name=airbyte/source-snapchat-marketing
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,8 @@ class IncrementalSnapchatMarketingStream(SnapchatMarketingStream, ABC):
last_slice = None
current_slice = None
first_run = True
initial_state = None
max_state = None

def stream_slices(self, **kwargs) -> Iterable[Optional[Mapping[str, Any]]]:
stream_state = kwargs.get("stream_state")
self.initial_state = stream_state.get(self.cursor_field) if stream_state else self.start_date
self.max_state = self.initial_state
depends_on_stream_config = {"authenticator": self.authenticator, "start_date": self.start_date}
stream_slices = get_depend_on_ids(self.depends_on_stream, depends_on_stream_config, self.slice_key_name)

Expand Down Expand Up @@ -228,13 +223,9 @@ def get_updated_state(self, current_stream_state: MutableMapping[str, Any], late
Thus all the slices data are compared to the initial state, but only on the last one we write it to the stream state.
This approach gives us the maximum state value of all the records and we exclude the state updates between slice processing
"""

if self.first_run:
self.first_run = False
return {self.cursor_field: self.initial_state}
else:
self.max_state = max(self.max_state, latest_record[self.cursor_field])
return {self.cursor_field: self.max_state if self.current_slice == self.last_slice else self.initial_state}
if not current_stream_state:
current_stream_state = {self.cursor_field: self.start_date}
return {self.cursor_field: max(latest_record.get(self.cursor_field, ""), current_stream_state.get(self.cursor_field, ""))}
Copy link
Contributor

Choose a reason for hiding this comment

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

does max work with empty string?

Copy link
Contributor Author

@annalvova05 annalvova05 Nov 18, 2021

Choose a reason for hiding this comment

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

yes. In case,
current_stream_state: {'updated_at': '2021-06-11T09:44:42.583Z'} and
latest_record.get(self.cursor_field, "") = "" max returns '2021-06-11T09:44:42.583Z'


def read_records(
self, stream_state: Mapping[str, Any] = None, stream_slice: Mapping[str, Any] = None, **kwargs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@
"default": "1970-01-01",
"pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$"
}
},
"authSpecification": {
"auth_type": "oauth2.0",
"oauth2Specification": {
"rootObject": [],
"oauthFlowInitParameters": [["client_id"], ["client_secret"]],
"oauthFlowOutputParameters": [["refresh_token"]]
}
}
}
}
5 changes: 3 additions & 2 deletions docs/integrations/sources/snapchat-marketing.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ Snapchat Marketing API has limitations to 1000 items per page

| Version | Date | Pull Request | Subject |
| :--- | :--- | :--- | :--- |
| 0.1.1 | 2021-11-08 | [7499](https://github.com/airbytehq/airbyte/pull/7499) | Remove base-python dependencies |
| 0.1.0 | 2021-07-26 | [4843](https://github.com/airbytehq/airbyte/pull/4843) | Initial release supporting the Snapchat Marketing API |
| 0.1.3 | 2021-11-10 | [7811](https://github.com/airbytehq/airbyte/pull/7811) | Add oauth2.0, fix stream_state |
| 0.1.2 | 2021-11-08 | [7499](https://github.com/airbytehq/airbyte/pull/7499) | Remove base-python dependencies |
| 0.1.1 | 2021-07-29 | [5072](https://github.com/airbytehq/airbyte/pull/5072) | Fix bug with incorrect stream\_state value |
| 0.1.0 | 2021-07-26 | [4843](https://github.com/airbytehq/airbyte/pull/4843) | Initial release supporting the Snapchat Marketing API |

1 change: 0 additions & 1 deletion tools/bin/ci_credentials.sh
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,6 @@ read_secrets source-shortio "$SOURCE_SHORTIO_TEST_CREDS"
read_secrets source-slack "$SOURCE_SLACK_TEST_CREDS"
read_secrets source-slack "$SOURCE_SLACK_OAUTH_TEST_CREDS" "config_oauth.json"
read_secrets source-smartsheets "$SMARTSHEETS_TEST_CREDS"
read_secrets source-snapchat-marketing "$SOURCE_SNAPCHAT_MARKETING_CREDS"
read_secrets source-snowflake "$SNOWFLAKE_INTEGRATION_TEST_CREDS" "config.json"
read_secrets source-square "$SOURCE_SQUARE_CREDS"
read_secrets source-strava "$SOURCE_STRAVA_TEST_CREDS"
Expand Down