|
4 | 4 | import re |
5 | 5 | import time |
6 | 6 | import logging |
| 7 | + |
| 8 | +from copy import deepcopy |
7 | 9 | from datetime import datetime |
| 10 | +from httpx import Client |
8 | 11 |
|
| 12 | +from domaintools.constants import OutputFormat, HEADER_ACCEPT_KEY_CSV_FORMAT |
9 | 13 | from domaintools.exceptions import ( |
10 | 14 | BadRequestException, |
11 | 15 | InternalServerErrorException, |
|
18 | 22 | ) |
19 | 23 | from domaintools.utils import get_feeds_products_list |
20 | 24 |
|
21 | | -from httpx import Client |
22 | 25 |
|
23 | 26 | try: # pragma: no cover |
24 | 27 | from collections.abc import MutableMapping, MutableSequence |
@@ -90,6 +93,18 @@ def _make_request(self): |
90 | 93 | patch_data = self.kwargs.copy() |
91 | 94 | patch_data.update(self.api.extra_request_params) |
92 | 95 | return session.patch(url=self.url, json=patch_data) |
| 96 | + elif self.product in get_feeds_products_list(): |
| 97 | + parameters = deepcopy(self.kwargs) |
| 98 | + parameters.pop("output_format", None) |
| 99 | + parameters.pop( |
| 100 | + "format", None |
| 101 | + ) # For some unknownn reasons, even if "format" is not included in the cli params for feeds endpoint, it is being populated thus we need to remove it. Happens only if using CLI. |
| 102 | + headers = {} |
| 103 | + if self.kwargs.get("output_format", OutputFormat.JSONL.value) == OutputFormat.CSV.value: |
| 104 | + parameters["headers"] = int(bool(self.kwargs.get("headers", False))) |
| 105 | + headers["accept"] = HEADER_ACCEPT_KEY_CSV_FORMAT |
| 106 | + |
| 107 | + return session.get(url=self.url, params=parameters, headers=headers, **self.api.extra_request_params) |
93 | 108 | else: |
94 | 109 | return session.get(url=self.url, params=self.kwargs, **self.api.extra_request_params) |
95 | 110 |
|
@@ -259,6 +274,32 @@ def json(self): |
259 | 274 | **self.kwargs, |
260 | 275 | ) |
261 | 276 |
|
| 277 | + @property |
| 278 | + def jsonl(self): |
| 279 | + self.kwargs.pop("format", None) |
| 280 | + return self.__class__( |
| 281 | + format="jsonl", |
| 282 | + product=self.product, |
| 283 | + url=self.url, |
| 284 | + items_path=self.items_path, |
| 285 | + response_path=self.response_path, |
| 286 | + api=self.api, |
| 287 | + **self.kwargs, |
| 288 | + ) |
| 289 | + |
| 290 | + @property |
| 291 | + def csv(self): |
| 292 | + self.kwargs.pop("format", None) |
| 293 | + return self.__class__( |
| 294 | + format="csv", |
| 295 | + product=self.product, |
| 296 | + url=self.url, |
| 297 | + items_path=self.items_path, |
| 298 | + response_path=self.response_path, |
| 299 | + api=self.api, |
| 300 | + **self.kwargs, |
| 301 | + ) |
| 302 | + |
262 | 303 | @property |
263 | 304 | def xml(self): |
264 | 305 | self.kwargs.pop("format", None) |
|
0 commit comments