garf-core 0.0.6__tar.gz → 0.0.7__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.2
2
2
  Name: garf-core
3
- Version: 0.0.6
3
+ Version: 0.0.7
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>
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.0.6'
15
+ __version__ = '0.0.7'
@@ -19,6 +19,7 @@ import abc
19
19
  import dataclasses
20
20
  from collections.abc import Sequence
21
21
 
22
+ import requests
22
23
  from typing_extensions import override
23
24
 
24
25
 
@@ -34,16 +35,40 @@ class GarfApiResponse:
34
35
  results: list
35
36
 
36
37
 
38
+ class GarfApiError(Exception):
39
+ """API specific exception."""
40
+
41
+
37
42
  class BaseClient(abc.ABC):
38
43
  """Base API client class."""
39
44
 
40
45
  @abc.abstractmethod
41
46
  def get_response(
42
- self, request: GarfApiRequest = GarfApiRequest()
47
+ self, request: GarfApiRequest = GarfApiRequest(), **kwargs: str
43
48
  ) -> GarfApiResponse:
44
49
  """Method for getting response."""
45
50
 
46
51
 
52
+ class RestApiClient(BaseClient):
53
+ """Specifies REST client."""
54
+
55
+ OK = 200
56
+
57
+ def __init__(self, endpoint: str, **kwargs: str) -> None:
58
+ """Initializes RestApiClient."""
59
+ self.endpoint = endpoint
60
+ self.query_args = kwargs
61
+
62
+ @override
63
+ def get_response(
64
+ self, request: GarfApiRequest = GarfApiRequest(), **kwargs: str
65
+ ) -> GarfApiResponse:
66
+ response = requests.get(f'{self.endpoint}/{request.resource_name}')
67
+ if response.status_code == self.OK:
68
+ return GarfApiResponse(response.json())
69
+ raise GarfApiError('Failed to get data from API')
70
+
71
+
47
72
  class FakeApiClient(BaseClient):
48
73
  """Fake class for specifying API client."""
49
74
 
@@ -44,15 +44,17 @@ class ApiReportFetcher:
44
44
  self,
45
45
  api_client: api_clients.BaseApiClient,
46
46
  parser: parsers.BaseParser = parsers.ListParser,
47
+ **kwargs: str,
47
48
  ) -> None:
48
49
  """Instantiates ApiReportFetcher based on provided api client.
49
50
 
50
51
  Args:
51
52
  api_client: Instantiated api client.
52
- parser: Parser.
53
+ parser: Type of parser to convert API response.
53
54
  """
54
55
  self.api_client = api_client
55
56
  self.parser = parser()
57
+ self.query_args = kwargs
56
58
 
57
59
  async def afetch(
58
60
  self,
@@ -103,3 +105,26 @@ class ApiReportFetcher:
103
105
  return report.GarfReport(
104
106
  results=parsed_response, column_names=query.column_names
105
107
  )
108
+
109
+
110
+ class RestApiReportFetcher(ApiReportFetcher):
111
+ """Fetches data from an REST API endpoint.
112
+
113
+ Attributes:
114
+ api_client: Initialized RestApiClient.
115
+ parser: Type of parser to convert API response.
116
+ """
117
+
118
+ def __init__(
119
+ self,
120
+ endpoint: str,
121
+ parser: parsers.BaseParser = parsers.DictParser,
122
+ ) -> None:
123
+ """Instantiates RestApiReportFetcher.
124
+
125
+ Args:
126
+ endpoint: URL of API endpoint.
127
+ parser: Type of parser to convert API response.
128
+ """
129
+ self.api_client = api_clients.RestApiClient(endpoint)
130
+ self.parser = parser()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: garf-core
3
- Version: 0.0.6
3
+ Version: 0.0.7
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>
6
6
  License: Apache 2.0
@@ -11,5 +11,6 @@ garf_core/report_fetcher.py
11
11
  garf_core.egg-info/PKG-INFO
12
12
  garf_core.egg-info/SOURCES.txt
13
13
  garf_core.egg-info/dependency_links.txt
14
+ garf_core.egg-info/entry_points.txt
14
15
  garf_core.egg-info/requires.txt
15
16
  garf_core.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ [garf]
2
+ rest = garf_core.report_fetcher
@@ -33,6 +33,9 @@ dynamic=["version"]
33
33
  [tool.setuptools.dynamic]
34
34
  version = {attr = "garf_core.__version__"}
35
35
 
36
+ [project.entry-points.garf]
37
+ rest = "garf_core.report_fetcher"
38
+
36
39
  [project.optional-dependencies]
37
40
  pandas=[
38
41
  "pandas",
File without changes
File without changes
File without changes