Skip to content

Commit 8455b91

Browse files
authored
refactor: change from sync to bulk endpoints for transactions_lines and gl_accounts. (#294)
* refactor: change from sync to bulk endpoints for `transactions_lines` and `gl_accounts`. all other streams will be full load. this will allow us to have more control over the start timestamp and it will now include all data, also deleted records. * remove import * account for none start date * change strftime place * fix f string * fix if statement * fix linting * last linting
1 parent 9746ddf commit 8455b91

File tree

3 files changed

+11
-54
lines changed

3 files changed

+11
-54
lines changed

tap_exact/client.py

Lines changed: 3 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,13 @@
1111
import requests
1212
import xmltodict
1313
from lxml import etree
14-
from pendulum import parse
1514
from singer_sdk.helpers.jsonpath import extract_jsonpath
1615
from singer_sdk.pagination import BaseOffsetPaginator
1716
from singer_sdk.streams import RESTStream
1817

1918
from tap_exact.auth import ExactAuthenticator
2019

2120
if typing.TYPE_CHECKING:
22-
from datetime import datetime
23-
2421
from requests import Response
2522

2623
TPageToken = typing.TypeVar("TPageToken")
@@ -100,22 +97,14 @@ def authenticator(self) -> _Auth:
10097
"""
10198
return ExactAuthenticator(self)
10299

103-
def get_starting_time(self, context: dict) -> datetime:
104-
"""Return the starting timestamp for the stream."""
105-
start_date = self.config.get("start_date")
106-
if start_date:
107-
start_date = parse(self.config.get("start_date"))
108-
replication_key = self.get_starting_timestamp(context)
109-
return replication_key or start_date
110-
111100
def get_url_params(self, context: dict | None, next_page_token: str) -> dict[str, Any]:
112101
"""Return a dictionary of parameters to use in the API request."""
113102
params: dict = {}
114103
if self.select:
115104
params["$select"] = self.select
116-
start_date = self.get_starting_time(context).strftime("%Y-%m-%dT%H:%M:%S")
117-
if self.replication_key:
118-
date_filter = f"Modified gt datetime'{start_date}'"
105+
start_date = self.get_starting_timestamp(context)
106+
if start_date is not None:
107+
date_filter = f"Modified gt datetime'{start_date.strftime('%Y-%m-%dT%H:%M:%S')}'"
119108
params["$filter"] = date_filter
120109
if next_page_token:
121110
params["$skiptoken"] = next_page_token
@@ -191,31 +180,3 @@ def post_process(
191180
def select(self) -> str:
192181
"""Return the select query parameter."""
193182
return ",".join(self.schema["properties"].keys())
194-
195-
196-
class ExactSyncStream(ExactStream):
197-
"""Exact sync stream class."""
198-
199-
def get_new_paginator(self) -> BaseOffsetPaginator:
200-
"""Create a new pagination helper instance."""
201-
return ExactPaginator(self, start_value=None, page_size=1000)
202-
203-
def get_starting_time(self, context: str) -> int:
204-
"""Return the starting timestamp for the stream."""
205-
state = self.get_context_state(context)
206-
rep_key = None
207-
if "replication_key_value" in state:
208-
rep_key = state["replication_key_value"]
209-
return rep_key or 1
210-
211-
def get_url_params(self, context: dict | None, next_page_token: int) -> dict[str, Any]:
212-
"""Return a dictionary of parameters to use in the API request."""
213-
params: dict = {}
214-
if self.select:
215-
params["$select"] = self.select
216-
start_timestamp = self.get_starting_time(context)
217-
date_filter = f"Timestamp gt {start_timestamp}" if start_timestamp == 1 else f"Timestamp gt {start_timestamp}L"
218-
params["$filter"] = date_filter
219-
if next_page_token:
220-
params["$skiptoken"] = next_page_token
221-
return params

tap_exact/schemas.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
)
1212

1313
transaction_lines_schema = PropertiesList(
14-
Property("Timestamp", IntegerType),
1514
Property("Account", StringType),
1615
Property("AccountCode", StringType),
1716
Property("AccountName", StringType),
@@ -85,7 +84,6 @@
8584
).to_dict()
8685

8786
gl_accounts_schema = PropertiesList(
88-
Property("Timestamp", IntegerType),
8987
Property("AllowCostsInSales", BooleanType),
9088
Property("AssimilatedVATBox", IntegerType),
9189
Property("BalanceSide", StringType),
@@ -131,7 +129,6 @@
131129
).to_dict()
132130

133131
gl_classifications_schema = PropertiesList(
134-
Property("Timestamp", IntegerType),
135132
Property("Abstract", BooleanType),
136133
Property("Balance", StringType),
137134
Property("Code", StringType),

tap_exact/streams.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import typing as t
66

7-
from tap_exact.client import ExactStream, ExactSyncStream
7+
from tap_exact.client import ExactStream
88
from tap_exact.schemas import (
99
assets_schema,
1010
gl_account_classification_mappings_schema,
@@ -14,33 +14,32 @@
1414
)
1515

1616

17-
class TransactionLinesStream(ExactSyncStream):
17+
class TransactionLinesStream(ExactStream):
1818
"""Define TransactionLines stream."""
1919

2020
name = "transaction_lines"
21-
path = "/sync/Financial/TransactionLines"
21+
path = "/bulk/Financial/TransactionLines"
2222
primary_keys: t.ClassVar[list[str]] = ["ID", "Division"]
23-
replication_key: t.ClassVar[str] = "Timestamp"
23+
replication_key: t.ClassVar[str] = "Modified"
2424
schema = transaction_lines_schema # pyright: ignore[reportAssignmentType]
2525

2626

27-
class GLAccountsStream(ExactSyncStream):
27+
class GLAccountsStream(ExactStream):
2828
"""Define GLAccounts stream."""
2929

3030
name = "gl_accounts"
31-
path = "/sync/Financial/GLAccounts"
31+
path = "/bulk/Financial/GLAccounts"
3232
primary_keys: t.ClassVar[list[str]] = ["ID", "Division"]
33-
replication_key: t.ClassVar[str] = "Timestamp"
33+
replication_key: t.ClassVar[str] = "Modified"
3434
schema = gl_accounts_schema # pyright: ignore[reportAssignmentType]
3535

3636

37-
class GLClassificationsStream(ExactSyncStream):
37+
class GLClassificationsStream(ExactStream):
3838
"""Define GLClassifications stream."""
3939

4040
name = "gl_classifications"
4141
path = "/sync/Financial/GLClassifications"
4242
primary_keys: t.ClassVar[list[str]] = ["ID", "Division"]
43-
replication_key: t.ClassVar[str] = "Timestamp"
4443
schema = gl_classifications_schema # pyright: ignore[reportAssignmentType]
4544

4645

0 commit comments

Comments
 (0)