garf-core 0.0.6__py3-none-any.whl → 0.0.7__py3-none-any.whl
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.
- garf_core/__init__.py +1 -1
- garf_core/api_clients.py +26 -1
- garf_core/report_fetcher.py +26 -1
- {garf_core-0.0.6.dist-info → garf_core-0.0.7.dist-info}/METADATA +1 -1
- garf_core-0.0.7.dist-info/RECORD +13 -0
- garf_core-0.0.7.dist-info/entry_points.txt +2 -0
- garf_core-0.0.6.dist-info/RECORD +0 -12
- {garf_core-0.0.6.dist-info → garf_core-0.0.7.dist-info}/WHEEL +0 -0
- {garf_core-0.0.6.dist-info → garf_core-0.0.7.dist-info}/top_level.txt +0 -0
garf_core/__init__.py
CHANGED
garf_core/api_clients.py
CHANGED
@@ -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
|
|
garf_core/report_fetcher.py
CHANGED
@@ -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:
|
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()
|
@@ -0,0 +1,13 @@
|
|
1
|
+
garf_core/__init__.py,sha256=YXfq75YjkKDgNZM8YGRyE5aGGLa3MUVQasljixjp-70,598
|
2
|
+
garf_core/api_clients.py,sha256=FKmwts_QBV_E4aTmrnsZtow0CmSExLibfeSkMSrudU0,2235
|
3
|
+
garf_core/base_query.py,sha256=uEhKP56wcFtMiSwYOxoZ0q7OEvURGVOeRdpSYjxWLho,1201
|
4
|
+
garf_core/exceptions.py,sha256=4qvNN-8GqbbVsrLKxJwBeX1FUtWpKbhUWyvm7anD3iE,1916
|
5
|
+
garf_core/parsers.py,sha256=Y4wwpDXRZky7LBTBklvzk-aDNxgRL5RJg52rSdH5t9Q,2928
|
6
|
+
garf_core/query_editor.py,sha256=EzwjFnbje-RcP9VwWQwzCpy8lipt4tph3Kv6q5Lly5o,15994
|
7
|
+
garf_core/report.py,sha256=xlkZ44cdT_uGENuNeGwy69h7XLtwjdUjyPw3S1m-zc8,17852
|
8
|
+
garf_core/report_fetcher.py,sha256=g2bmqq8m3XxrWh1tDJ7ZO6iCys34mX8Dm55ZaT_36TI,3813
|
9
|
+
garf_core-0.0.7.dist-info/METADATA,sha256=gn0SYdh11jDgZKJJW4m1bD6TfYM90mbq-lqOWm7kQR4,2334
|
10
|
+
garf_core-0.0.7.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
11
|
+
garf_core-0.0.7.dist-info/entry_points.txt,sha256=ODxSZXwWEIXQAjRwBQsBJ6GYw8oPK6DYTo0oDVkKCpo,39
|
12
|
+
garf_core-0.0.7.dist-info/top_level.txt,sha256=Gj-Zp7fM2turGut5vTJuo5xEcKfow7cTLX3y3WFfNgA,10
|
13
|
+
garf_core-0.0.7.dist-info/RECORD,,
|
garf_core-0.0.6.dist-info/RECORD
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
garf_core/__init__.py,sha256=iynLwCh4JRTAmiLLrvX9e13zb6jgue4iR-IL7LOKZTw,598
|
2
|
-
garf_core/api_clients.py,sha256=sBiOfPllrSewV6Ul4uaHhdmgTHQ_l5M7sZHW1z4kNik,1568
|
3
|
-
garf_core/base_query.py,sha256=uEhKP56wcFtMiSwYOxoZ0q7OEvURGVOeRdpSYjxWLho,1201
|
4
|
-
garf_core/exceptions.py,sha256=4qvNN-8GqbbVsrLKxJwBeX1FUtWpKbhUWyvm7anD3iE,1916
|
5
|
-
garf_core/parsers.py,sha256=Y4wwpDXRZky7LBTBklvzk-aDNxgRL5RJg52rSdH5t9Q,2928
|
6
|
-
garf_core/query_editor.py,sha256=EzwjFnbje-RcP9VwWQwzCpy8lipt4tph3Kv6q5Lly5o,15994
|
7
|
-
garf_core/report.py,sha256=xlkZ44cdT_uGENuNeGwy69h7XLtwjdUjyPw3S1m-zc8,17852
|
8
|
-
garf_core/report_fetcher.py,sha256=x6Hry0PfOWJ8Rwz-yjncj2xO8bDiwkyKrvtX-3VjLVk,3175
|
9
|
-
garf_core-0.0.6.dist-info/METADATA,sha256=O-0SL-Nsbxh8WFIeQC5hqlpUh8ZGd9_lZ5FPC2CLGWw,2334
|
10
|
-
garf_core-0.0.6.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
11
|
-
garf_core-0.0.6.dist-info/top_level.txt,sha256=Gj-Zp7fM2turGut5vTJuo5xEcKfow7cTLX3y3WFfNgA,10
|
12
|
-
garf_core-0.0.6.dist-info/RECORD,,
|
File without changes
|
File without changes
|