garf-core 0.0.6__py3-none-any.whl → 0.0.8__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 +44 -12
- {garf_core-0.0.6.dist-info → garf_core-0.0.8.dist-info}/METADATA +1 -1
- garf_core-0.0.8.dist-info/RECORD +13 -0
- garf_core-0.0.8.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.8.dist-info}/WHEEL +0 -0
- {garf_core-0.0.6.dist-info → garf_core-0.0.8.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
@@ -38,21 +38,30 @@ class ApiReportFetcher:
|
|
38
38
|
|
39
39
|
Attributes:
|
40
40
|
api_client: a client used for connecting to API.
|
41
|
+
parser: Type of parser to convert API response.
|
42
|
+
query_specification_builder: Class to perform query parsing.
|
41
43
|
"""
|
42
44
|
|
43
45
|
def __init__(
|
44
46
|
self,
|
45
47
|
api_client: api_clients.BaseApiClient,
|
46
48
|
parser: parsers.BaseParser = parsers.ListParser,
|
49
|
+
query_specification_builder: query_editor.QuerySpecification = (
|
50
|
+
query_editor.QuerySpecification
|
51
|
+
),
|
52
|
+
**kwargs: str,
|
47
53
|
) -> None:
|
48
54
|
"""Instantiates ApiReportFetcher based on provided api client.
|
49
55
|
|
50
56
|
Args:
|
51
57
|
api_client: Instantiated api client.
|
52
|
-
parser:
|
58
|
+
parser: Type of parser to convert API response.
|
59
|
+
query_specification_builder: Class to perform query parsing.
|
53
60
|
"""
|
54
61
|
self.api_client = api_client
|
55
62
|
self.parser = parser()
|
63
|
+
self.query_specification_builder = query_specification_builder
|
64
|
+
self.query_args = kwargs
|
56
65
|
|
57
66
|
async def afetch(
|
58
67
|
self,
|
@@ -63,12 +72,12 @@ class ApiReportFetcher:
|
|
63
72
|
"""Asynchronously fetches data from API based on query_specification.
|
64
73
|
|
65
74
|
Args:
|
66
|
-
|
67
|
-
|
68
|
-
|
75
|
+
query_specification: Query text that will be passed to API
|
76
|
+
alongside column_names, customizers and virtual columns.
|
77
|
+
args: Arguments that need to be passed to the query.
|
69
78
|
|
70
79
|
Returns:
|
71
|
-
|
80
|
+
GarfReport with results of query execution.
|
72
81
|
"""
|
73
82
|
return self.fetch(query_specification, args, **kwargs)
|
74
83
|
|
@@ -81,19 +90,19 @@ class ApiReportFetcher:
|
|
81
90
|
"""Fetches data from API based on query_specification.
|
82
91
|
|
83
92
|
Args:
|
84
|
-
|
85
|
-
|
86
|
-
|
93
|
+
query_specification: Query text that will be passed to API
|
94
|
+
alongside column_names, customizers and virtual columns.
|
95
|
+
args: Arguments that need to be passed to the query.
|
87
96
|
|
88
97
|
Returns:
|
89
|
-
|
98
|
+
GarfReport with results of query execution.
|
90
99
|
|
91
100
|
Raises:
|
92
|
-
|
93
|
-
|
101
|
+
GarfExecutorException:
|
102
|
+
When customer_ids are not provided or API returned error.
|
94
103
|
"""
|
95
104
|
if not isinstance(query_specification, query_editor.QuerySpecification):
|
96
|
-
query_specification =
|
105
|
+
query_specification = self.query_specification_builder(
|
97
106
|
text=str(query_specification),
|
98
107
|
args=args,
|
99
108
|
)
|
@@ -103,3 +112,26 @@ class ApiReportFetcher:
|
|
103
112
|
return report.GarfReport(
|
104
113
|
results=parsed_response, column_names=query.column_names
|
105
114
|
)
|
115
|
+
|
116
|
+
|
117
|
+
class RestApiReportFetcher(ApiReportFetcher):
|
118
|
+
"""Fetches data from an REST API endpoint.
|
119
|
+
|
120
|
+
Attributes:
|
121
|
+
api_client: Initialized RestApiClient.
|
122
|
+
parser: Type of parser to convert API response.
|
123
|
+
"""
|
124
|
+
|
125
|
+
def __init__(
|
126
|
+
self,
|
127
|
+
endpoint: str,
|
128
|
+
parser: parsers.BaseParser = parsers.DictParser,
|
129
|
+
) -> None:
|
130
|
+
"""Instantiates RestApiReportFetcher.
|
131
|
+
|
132
|
+
Args:
|
133
|
+
endpoint: URL of API endpoint.
|
134
|
+
parser: Type of parser to convert API response.
|
135
|
+
"""
|
136
|
+
self.api_client = api_clients.RestApiClient(endpoint)
|
137
|
+
self.parser = parser()
|
@@ -0,0 +1,13 @@
|
|
1
|
+
garf_core/__init__.py,sha256=-2NI7Qm5ndrlcaz3itBBuFXOKu4anul2TdJro2G5oRo,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=j1ewWoUvnEGM5vmWihFJ7vSVVEG1t2yzapKhylc-7eQ,4157
|
9
|
+
garf_core-0.0.8.dist-info/METADATA,sha256=Ap-TAWp1wzDtXO6WPUBE1ajGnzQ_YMUIRiIhZbzLcm8,2334
|
10
|
+
garf_core-0.0.8.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
11
|
+
garf_core-0.0.8.dist-info/entry_points.txt,sha256=ODxSZXwWEIXQAjRwBQsBJ6GYw8oPK6DYTo0oDVkKCpo,39
|
12
|
+
garf_core-0.0.8.dist-info/top_level.txt,sha256=Gj-Zp7fM2turGut5vTJuo5xEcKfow7cTLX3y3WFfNgA,10
|
13
|
+
garf_core-0.0.8.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
|