Skip to content

Commit

Permalink
Refactor schema loading and property handling in KlaviyoStream (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
butkeraites-hotglue authored Dec 6, 2024
1 parent 48a23a0 commit 01d9042
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
15 changes: 5 additions & 10 deletions tap_klaviyo/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,9 @@ def get_abs_path(self, path):
return os.path.join(os.path.dirname(os.path.realpath(__file__)), path)

def load_schema(self, name):
return json.load(open(self.get_abs_path('schemas/{}.json'.format(name))))
schema_path = self.get_abs_path(f'schemas/{name}.json')
with open(schema_path, 'r') as schema_file:
return json.load(schema_file)

def _fill_missing_properties(self, property_list):
try:
Expand Down Expand Up @@ -233,22 +235,15 @@ def get_schema(self) -> dict:
properties.append(
th.Property(name, self.get_jsonschema_type(record[name]))
)
# if the rep_key is not at a header level add updated as default
if (
self.replication_key is not None
and self.replication_key not in record.keys()
):
properties.append(
th.Property(self.replication_key, th.DateTimeType)
)
# Return the list as a JSON Schema dictionary object
property_list = th.PropertiesList(*properties).to_dict()
else:
property_list = th.PropertiesList(
th.Property("id", th.StringType),
th.Property(self.replication_key, th.DateTimeType),
).to_dict()
property_list = self._fill_missing_properties(property_list)
if self.replication_key is not None:
property_list["properties"].update(th.Property(self.replication_key,th.DateTimeType).to_dict())
return property_list

@cached_property
Expand Down
2 changes: 1 addition & 1 deletion tap_klaviyo/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,4 @@ def get_url_params(
if self.replication_key and start_date:
start_date = start_date.strftime("%Y-%m-%dT%H:%M:%SZ")
params["filter"] = f"greater-or-equal({self.replication_key},{start_date})"
return params
return params

0 comments on commit 01d9042

Please sign in to comment.