garf-core 0.1.0__tar.gz → 0.1.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: garf-core
3
- Version: 0.1.0
3
+ Version: 0.1.1
4
4
  Summary: Abstracts fetching data from API based on provided SQL-like query.
5
5
  Author-email: "Google Inc. (gTech gPS CSE team)" <no-reply@google.com>, Andrei Markin <andrey.markin.ppc@gmail.com>
6
6
  License: Apache 2.0
@@ -12,4 +12,4 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
- __version__ = '0.1.0'
15
+ __version__ = '0.1.1'
@@ -20,6 +20,8 @@ from __future__ import annotations
20
20
 
21
21
  import logging
22
22
  import os
23
+ from collections.abc import Sequence
24
+ from typing import Any
23
25
 
24
26
  from garf_core import (
25
27
  api_clients,
@@ -36,7 +38,7 @@ class FakeApiReportFetcher(report_fetcher.ApiReportFetcher):
36
38
 
37
39
  def __init__(
38
40
  self,
39
- data: list[dict[str, parsers.ApiRowElement]] | None = None,
41
+ api_client: api_clients.FakeApiClient | None = None,
40
42
  parser: parsers.BaseParser = parsers.DictParser,
41
43
  query_specification_builder: query_editor.QuerySpecification = (
42
44
  query_editor.QuerySpecification
@@ -46,29 +48,33 @@ class FakeApiReportFetcher(report_fetcher.ApiReportFetcher):
46
48
  json_location: str | os.PathLike[str] | None = None,
47
49
  **kwargs: str,
48
50
  ) -> None:
49
- if not data and not (
51
+ if not api_client and not (
50
52
  data_location := json_location or csv_location or data_location
51
53
  ):
52
54
  raise report_fetcher.ApiReportFetcherError(
53
55
  'Missing fake data for the fetcher.'
54
56
  )
55
- api_client = (
56
- api_clients.FakeApiClient(data)
57
- if data
58
- else api_clients.FakeApiClient.from_file(data_location)
59
- )
57
+ if not api_client:
58
+ api_client = api_clients.FakeApiClient.from_file(data_location)
60
59
  super().__init__(api_client, parser, query_specification_builder, **kwargs)
61
60
 
61
+ @classmethod
62
+ def from_data(cls, data: Sequence[dict[str, Any]]) -> FakeApiReportFetcher:
63
+ """Initializes FakeApiReportFetcher from a sequence of data."""
64
+ return FakeApiReportFetcher(
65
+ api_client=api_clients.FakeApiClient(results=data)
66
+ )
67
+
62
68
  @classmethod
63
69
  def from_csv(
64
70
  cls, file_location: str | os.PathLike[str]
65
71
  ) -> FakeApiReportFetcher:
66
- """Initialized FakeApiReportFetcher from a csv file."""
72
+ """Initializes FakeApiReportFetcher from a csv file."""
67
73
  return FakeApiReportFetcher(csv_location=file_location)
68
74
 
69
75
  @classmethod
70
76
  def from_json(
71
77
  cls, file_location: str | os.PathLike[str]
72
78
  ) -> FakeApiReportFetcher:
73
- """Initialized FakeApiReportFetcher from a json file."""
79
+ """Initializes FakeApiReportFetcher from a json file."""
74
80
  return FakeApiReportFetcher(json_location=file_location)
@@ -40,11 +40,12 @@ class RestApiReportFetcher(report_fetcher.ApiReportFetcher):
40
40
 
41
41
  def __init__(
42
42
  self,
43
- endpoint: str,
43
+ api_client: api_clients.RestApiClient | None = None,
44
44
  parser: parsers.BaseParser = parsers.DictParser,
45
45
  query_specification_builder: query_editor.QuerySpecification = (
46
46
  query_editor.QuerySpecification
47
47
  ),
48
+ endpoint: str | None = None,
48
49
  **kwargs: str,
49
50
  ) -> None:
50
51
  """Instantiates RestApiReportFetcher.
@@ -54,5 +55,17 @@ class RestApiReportFetcher(report_fetcher.ApiReportFetcher):
54
55
  parser: Type of parser to convert API response.
55
56
  query_specification_builder: Class to perform query parsing.
56
57
  """
57
- api_client = api_clients.RestApiClient(endpoint)
58
+ if not api_client and not endpoint:
59
+ raise report_fetcher.ApiReportFetcherError(
60
+ 'Missing api_client or endpoint for the fetcher.'
61
+ )
62
+ if not api_client:
63
+ api_client = api_clients.RestApiClient(endpoint)
58
64
  super().__init__(api_client, parser, query_specification_builder, **kwargs)
65
+
66
+ @classmethod
67
+ def from_endpoint(cls, endpoint: str) -> RestApiReportFetcher:
68
+ """Initializes RestApiReportFetcher: from an API endpoint."""
69
+ return RestApiReportFetcher(
70
+ api_client=api_clients.RestApiClient(endpoint=endpoint)
71
+ )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: garf-core
3
- Version: 0.1.0
3
+ Version: 0.1.1
4
4
  Summary: Abstracts fetching data from API based on provided SQL-like query.
5
5
  Author-email: "Google Inc. (gTech gPS CSE team)" <no-reply@google.com>, Andrei Markin <andrey.markin.ppc@gmail.com>
6
6
  License: Apache 2.0
File without changes
File without changes
File without changes
File without changes