|
5 | 5 | from singer import Transformer, metrics
|
6 | 6 | from singer.utils import strptime_to_utc
|
7 | 7 |
|
8 |
| -from .utils import break_into_intervals |
| 8 | +from tap_zendesk_chat.utils import break_into_intervals |
9 | 9 |
|
10 | 10 | LOGGER = singer.get_logger()
|
11 | 11 |
|
@@ -142,20 +142,21 @@ def _pull(self, ctx, chat_type, ts_field, full_sync, schema: Dict, stream_metada
|
142 | 142 | for start_dt, end_dt in break_into_intervals(interval_days, start_time, ctx.now):
|
143 | 143 | while True:
|
144 | 144 | if next_url:
|
145 |
| - search_resp = ctx.client.request(self.tap_stream_id, url=next_url) |
| 145 | + search_resp = ctx.client.request("incremental/" + self.tap_stream_id, url=next_url) |
146 | 146 | else:
|
147 |
| - params = {"q": f"type:{chat_type} AND {ts_field}:[{start_dt.isoformat()} TO {end_dt.isoformat()}]"} |
148 |
| - search_resp = ctx.client.request(self.tap_stream_id, params=params, url_extra="/search") |
| 147 | + # params = {"q": f"type:{chat_type} AND {ts_field}:[{start_dt.isoformat()} TO {end_dt.isoformat()}]"} |
| 148 | + params = {"start_time": int(start_dt.timestamp()), "fields": "chats(*)"} |
| 149 | + search_resp = ctx.client.request("incremental/" + self.tap_stream_id, params=params) |
149 | 150 |
|
150 |
| - next_url = search_resp["next_url"] |
| 151 | + next_url = search_resp["next_page"] |
151 | 152 | ctx.set_bookmark(url_offset_key, next_url)
|
152 | 153 | ctx.write_state()
|
153 |
| - chats = self._bulk_chats(ctx, [r["id"] for r in search_resp["results"]]) |
| 154 | + chats = search_resp.get("chats", []) |
154 | 155 | if chats:
|
155 | 156 | chats = [transformer.transform(rec, schema, metadata=stream_metadata) for rec in chats]
|
156 | 157 | self.write_page(chats)
|
157 |
| - max_bookmark = max(max_bookmark, *[c[ts_field] for c in chats]) |
158 |
| - if not next_url: |
| 158 | + max_bookmark = max(max_bookmark, *[c[ts_field] for c in chats if c.get(ts_field)]) |
| 159 | + if not chats or not next_url: |
159 | 160 | break
|
160 | 161 | ctx.set_bookmark(ts_bookmark_key, max_bookmark)
|
161 | 162 | ctx.write_state()
|
|
0 commit comments