Skip to content

Commit

Permalink
Source Klaviyo: Fix predictive_analytics field in stream profiles (
Browse files Browse the repository at this point in the history
…airbytehq#35637)

Signed-off-by: Artem Inzhyyants <[email protected]>
  • Loading branch information
artem1205 authored Feb 27, 2024
1 parent 21168f9 commit 56d9942
Show file tree
Hide file tree
Showing 9 changed files with 215 additions and 181 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ data:
definitionId: 95e8cffd-b8c4-4039-968e-d32fb4a69bde
connectorBuildOptions:
baseImage: docker.io/airbyte/python-connector-base:1.1.0@sha256:bd98f6505c6764b1b5f99d3aedc23dfc9e9af631a62533f60eb32b1d3dbab20c
dockerImageTag: 2.1.3
dockerImageTag: 2.2.0
dockerRepository: airbyte/source-klaviyo
githubIssueLabel: source-klaviyo
icon: klaviyo.svg
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ requires = [ "poetry-core>=1.0.0",]
build-backend = "poetry.core.masonry.api"

[tool.poetry]
version = "2.1.3"
version = "2.2.0"
name = "source-klaviyo"
description = "Source implementation for Klaviyo."
authors = [ "Airbyte <[email protected]>",]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,81 +56,7 @@
"type": ["null", "object"],
"additionalProperties": true
},
"subscriptions": {
"type": ["null", "object"],
"properties": {
"email": {
"type": ["null", "object"],
"properties": {
"marketing": {
"type": ["null", "object"],
"properties": {
"can_receive_email_marketing": { "type": "boolean" },
"consent": { "type": "string" },
"timestamp": {
"type": ["null", "string"],
"format": "date-time"
},
"last_updated": {
"type": ["null", "string"],
"format": "date-time"
},
"method": { "type": ["null", "string"] },
"method_detail": { "type": ["null", "string"] },
"custom_method_detail": { "type": ["null", "string"] },
"double_optin": { "type": ["null", "boolean"] },
"suppressions": {
"type": ["null", "array"],
"items": {
"type": ["null", "object"],
"properties": {
"reason": { "type": "string" },
"timestamp": {
"type": "string",
"format": "date-time"
}
}
}
},
"list_suppressions": {
"type": ["null", "array"],
"items": {
"type": ["null", "object"],
"properties": {
"list_id": { "type": "string" },
"reason": { "type": "string" },
"timestamp": {
"type": "string",
"format": "date-time"
}
}
}
}
}
}
}
},
"sms": {
"type": ["null", "object"],
"properties": {
"marketing": {
"type": ["null", "object"],
"properties": {
"can_receive_sms_marketing": { "type": "boolean" },
"consent": { "type": "string" },
"consent_timestamp": {
"type": "string",
"format": "date-time"
},
"method": { "type": "string" },
"method_detail": { "type": ["null", "string"] },
"last_updated": { "type": "string", "format": "date-time" }
}
}
}
}
}
},
"subscriptions": { "$ref": "subscriptions.json" },
"predictive_analytics": {
"type": ["null", "object"],
"properties": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,81 +56,7 @@
"type": ["null", "object"],
"additionalProperties": true
},
"subscriptions": {
"type": ["null", "object"],
"properties": {
"email": {
"type": ["null", "object"],
"properties": {
"marketing": {
"type": ["null", "object"],
"properties": {
"can_receive_email_marketing": { "type": "boolean" },
"consent": { "type": "string" },
"timestamp": {
"type": ["null", "string"],
"format": "date-time"
},
"last_updated": {
"type": ["null", "string"],
"format": "date-time"
},
"method": { "type": ["null", "string"] },
"method_detail": { "type": ["null", "string"] },
"custom_method_detail": { "type": ["null", "string"] },
"double_optin": { "type": ["null", "boolean"] },
"suppressions": {
"type": ["null", "array"],
"items": {
"type": ["null", "object"],
"properties": {
"reason": { "type": "string" },
"timestamp": {
"type": "string",
"format": "date-time"
}
}
}
},
"list_suppressions": {
"type": ["null", "array"],
"items": {
"type": ["null", "object"],
"properties": {
"list_id": { "type": "string" },
"reason": { "type": "string" },
"timestamp": {
"type": "string",
"format": "date-time"
}
}
}
}
}
}
}
},
"sms": {
"type": ["null", "object"],
"properties": {
"marketing": {
"type": ["null", "object"],
"properties": {
"can_receive_sms_marketing": { "type": "boolean" },
"consent": { "type": "string" },
"consent_timestamp": {
"type": "string",
"format": "date-time"
},
"method": { "type": "string" },
"method_detail": { "type": ["null", "string"] },
"last_updated": { "type": "string", "format": "date-time" }
}
}
}
}
}
},
"subscriptions": { "$ref": "subscriptions.json" },
"predictive_analytics": {
"type": ["null", "object"],
"properties": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
{
"type": ["null", "object"],
"properties": {
"email": {
"type": ["null", "object"],
"properties": {
"marketing": {
"type": ["null", "object"],
"properties": {
"can_receive_email_marketing": {
"type": "boolean"
},
"consent": {
"type": "string"
},
"timestamp": {
"type": ["null", "string"],
"format": "date-time"
},
"last_updated": {
"type": ["null", "string"],
"format": "date-time"
},
"method": {
"type": ["null", "string"]
},
"method_detail": {
"type": ["null", "string"]
},
"custom_method_detail": {
"type": ["null", "string"]
},
"double_optin": {
"type": ["null", "boolean"]
},
"suppressions": {
"type": ["null", "array"],
"items": {
"type": ["null", "object"],
"properties": {
"reason": {
"type": "string"
},
"timestamp": {
"type": "string",
"format": "date-time"
}
}
}
},
"list_suppressions": {
"type": ["null", "array"],
"items": {
"type": ["null", "object"],
"properties": {
"list_id": {
"type": "string"
},
"reason": {
"type": "string"
},
"timestamp": {
"type": "string",
"format": "date-time"
}
}
}
}
}
}
}
},
"sms": {
"type": ["null", "object"],
"properties": {
"marketing": {
"type": ["null", "object"],
"properties": {
"can_receive_sms_marketing": {
"type": ["null", "boolean"]
},
"consent": {
"type": ["null", "string"]
},
"consent_timestamp": {
"type": ["null", "string"],
"format": "date-time"
},
"method": {
"type": ["null", "string"]
},
"method_detail": {
"type": ["null", "string"]
},
"last_updated": {
"type": ["null", "string"],
"format": "date-time"
},
"timestamp": {
"type": ["null", "string"],
"format": "date-time"
}
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ def next_page_token(self, response: requests.Response) -> Optional[Mapping[str,
return {str(k): str(v) for (k, v) in urllib.parse.parse_qsl(next_url.query)}

def request_params(
self, stream_state: Mapping[str, Any], stream_slice: Mapping[str, Any] = None, next_page_token: Mapping[str, Any] = None
self,
stream_state: Optional[Mapping[str, Any]],
stream_slice: Optional[Mapping[str, Any]] = None,
next_page_token: Optional[Mapping[str, Any]] = None,
) -> MutableMapping[str, Any]:
# If next_page_token is set, all the parameters are already provided
if next_page_token:
Expand Down Expand Up @@ -131,11 +134,16 @@ def cursor_field(self) -> Union[str, List[str]]:
:return str: The name of the cursor field.
"""

def request_params(self, stream_state: Mapping[str, Any] = None, next_page_token: Mapping[str, Any] = None, **kwargs):
def request_params(
self,
stream_state: Optional[Mapping[str, Any]],
stream_slice: Optional[Mapping[str, Any]] = None,
next_page_token: Optional[Mapping[str, Any]] = None,
) -> MutableMapping[str, Any]:
"""Add incremental filters"""

stream_state = stream_state or {}
params = super().request_params(stream_state=stream_state, next_page_token=next_page_token, **kwargs)
params = super().request_params(stream_state=stream_state, stream_slice=stream_slice, next_page_token=next_page_token)

if not params.get("filter"):
stream_state_cursor_value = stream_state.get(self.cursor_field)
Expand Down Expand Up @@ -196,9 +204,14 @@ def cursor_field(self) -> Union[str, List[str]]:
def path(self, **kwargs) -> str:
return self._path

def request_params(self, stream_state: Mapping[str, Any] = None, next_page_token: Mapping[str, Any] = None, **kwargs):
def request_params(
self,
stream_state: Optional[Mapping[str, Any]],
stream_slice: Optional[Mapping[str, Any]] = None,
next_page_token: Optional[Mapping[str, Any]] = None,
) -> MutableMapping[str, Any]:
archived_stream_state = stream_state.get("archived") if stream_state else None
params = super().request_params(archived_stream_state, next_page_token, **kwargs)
params = super().request_params(stream_state=archived_stream_state, stream_slice=stream_slice, next_page_token=next_page_token)
archived_filter = "equals(archived,true)"
if "filter" in params and archived_filter not in params["filter"]:
params["filter"] = f"and({params['filter']},{archived_filter})"
Expand Down Expand Up @@ -253,6 +266,16 @@ class Profiles(IncrementalKlaviyoStream):
def path(self, *args, next_page_token: Optional[Mapping[str, Any]] = None, **kwargs) -> str:
return "profiles"

def request_params(
self,
stream_state: Optional[Mapping[str, Any]],
stream_slice: Optional[Mapping[str, Any]] = None,
next_page_token: Optional[Mapping[str, Any]] = None,
) -> MutableMapping[str, Any]:
params = super().request_params(stream_state=stream_state, stream_slice=stream_slice, next_page_token=next_page_token)
params.update({"additional-fields[profile]": "predictive_analytics"})
return params


class Campaigns(ArchivedRecordsMixin, IncrementalKlaviyoStream):
"""Docs: https://developers.klaviyo.com/en/v2023-06-15/reference/get_campaigns"""
Expand Down
Loading

0 comments on commit 56d9942

Please sign in to comment.