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 @@ -531,7 +531,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
11 changes: 10 additions & 1 deletion airbyte-config/init/src/main/resources/seed/source_specs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5406,7 +5406,7 @@
supportsNormalization: false
supportsDBT: false
supported_destination_sync_modes: []
- dockerImage: "airbyte/source-snapchat-marketing:0.1.2"
- dockerImage: "airbyte/source-snapchat-marketing:0.1.3"
spec:
documentationUrl: "https://docs.airbyte.io/integrations/sources/snapchat-marketing"
connectionSpecification:
Expand Down Expand Up @@ -5447,6 +5447,15 @@
supportsNormalization: false
supportsDBT: false
supported_destination_sync_modes: []
authSpecification:
auth_type: "oauth2.0"
oauth2Specification:
rootObject: []
oauthFlowInitParameters:
- - "client_id"
- - "client_secret"
oauthFlowOutputParameters:
- - "refresh_token"
- dockerImage: "airbyte/source-snowflake:0.1.2"
spec:
documentationUrl: "https://docs.airbyte.io/integrations/sources/snowflake"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
FROM python:3.7-slim
FROM python:3.7.11-alpine3.14 as base
FROM base as builder

# Bash is installed for more convenient debugging.
RUN apt-get update && apt-get install -y bash && rm -rf /var/lib/apt/lists/*

RUN apk --no-cache upgrade \
&& pip install --upgrade pip \
&& apk --no-cache add tzdata build-base

WORKDIR /airbyte/integration_code
COPY source_snapchat_marketing ./source_snapchat_marketing
COPY main.py ./
COPY setup.py ./
RUN pip install .
RUN pip install --prefix=/install .


FROM base
COPY --from=builder /install /usr/local
# add default timezone settings
COPY --from=builder /usr/share/zoneinfo/Etc/UTC /etc/localtime
RUN echo "Etc/UTC" > /etc/timezone

WORKDIR /airbyte/integration_code
COPY main.py ./
COPY source_snapchat_marketing ./source_snapchat_marketing


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
@@ -1,4 +1,12 @@
#!/usr/bin/env sh
image_name=$(cat acceptance-test-config.yml | grep "connector_image" | head -n 1 | cut -d: -f2-)
# Build latest connector image
echo "try to build: ${image_name}"
docker build . -t ${image_name}

# Pull latest acctest image
docker pull airbyte/source-acceptance-test:latest

docker run --rm -it \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /tmp:/tmp \
Expand Down
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 @@ -34,5 +34,13 @@
"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 @@ -274,7 +274,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