2
2
3
3
import typing
4
4
from ..core .client_wrapper import SyncClientWrapper
5
+ from .raw_client import RawAnalyticsClient
5
6
from ..types .analytics_query import AnalyticsQuery
6
7
from ..core .request_options import RequestOptions
7
8
from ..types .analytics_query_result import AnalyticsQueryResult
8
- from ..core .serialization import convert_and_respect_annotation_metadata
9
- from ..core .unchecked_base_model import construct_type
10
- from json .decoder import JSONDecodeError
11
- from ..core .api_error import ApiError
12
9
from ..core .client_wrapper import AsyncClientWrapper
10
+ from .raw_client import AsyncRawAnalyticsClient
13
11
14
12
# this is used as the default value for optional parameters
15
13
OMIT = typing .cast (typing .Any , ...)
16
14
17
15
18
16
class AnalyticsClient :
19
17
def __init__ (self , * , client_wrapper : SyncClientWrapper ):
20
- self ._client_wrapper = client_wrapper
18
+ self ._raw_client = RawAnalyticsClient (client_wrapper = client_wrapper )
19
+
20
+ @property
21
+ def with_raw_response (self ) -> RawAnalyticsClient :
22
+ """
23
+ Retrieves a raw implementation of this client that returns raw responses.
24
+
25
+ Returns
26
+ -------
27
+ RawAnalyticsClient
28
+ """
29
+ return self ._raw_client
21
30
22
31
def get (
23
32
self , * , queries : typing .Sequence [AnalyticsQuery ], request_options : typing .Optional [RequestOptions ] = None
@@ -36,38 +45,24 @@ def get(
36
45
typing.List[AnalyticsQueryResult]
37
46
38
47
"""
39
- _response = self ._client_wrapper .httpx_client .request (
40
- "analytics" ,
41
- method = "POST" ,
42
- json = {
43
- "queries" : convert_and_respect_annotation_metadata (
44
- object_ = queries , annotation = typing .Sequence [AnalyticsQuery ], direction = "write"
45
- ),
46
- },
47
- headers = {
48
- "content-type" : "application/json" ,
49
- },
50
- request_options = request_options ,
51
- omit = OMIT ,
52
- )
53
- try :
54
- if 200 <= _response .status_code < 300 :
55
- return typing .cast (
56
- typing .List [AnalyticsQueryResult ],
57
- construct_type (
58
- type_ = typing .List [AnalyticsQueryResult ], # type: ignore
59
- object_ = _response .json (),
60
- ),
61
- )
62
- _response_json = _response .json ()
63
- except JSONDecodeError :
64
- raise ApiError (status_code = _response .status_code , body = _response .text )
65
- raise ApiError (status_code = _response .status_code , body = _response_json )
48
+ response = self ._raw_client .get (queries = queries , request_options = request_options )
49
+ return response .data
66
50
67
51
68
52
class AsyncAnalyticsClient :
69
53
def __init__ (self , * , client_wrapper : AsyncClientWrapper ):
70
- self ._client_wrapper = client_wrapper
54
+ self ._raw_client = AsyncRawAnalyticsClient (client_wrapper = client_wrapper )
55
+
56
+ @property
57
+ def with_raw_response (self ) -> AsyncRawAnalyticsClient :
58
+ """
59
+ Retrieves a raw implementation of this client that returns raw responses.
60
+
61
+ Returns
62
+ -------
63
+ AsyncRawAnalyticsClient
64
+ """
65
+ return self ._raw_client
71
66
72
67
async def get (
73
68
self , * , queries : typing .Sequence [AnalyticsQuery ], request_options : typing .Optional [RequestOptions ] = None
@@ -86,30 +81,5 @@ async def get(
86
81
typing.List[AnalyticsQueryResult]
87
82
88
83
"""
89
- _response = await self ._client_wrapper .httpx_client .request (
90
- "analytics" ,
91
- method = "POST" ,
92
- json = {
93
- "queries" : convert_and_respect_annotation_metadata (
94
- object_ = queries , annotation = typing .Sequence [AnalyticsQuery ], direction = "write"
95
- ),
96
- },
97
- headers = {
98
- "content-type" : "application/json" ,
99
- },
100
- request_options = request_options ,
101
- omit = OMIT ,
102
- )
103
- try :
104
- if 200 <= _response .status_code < 300 :
105
- return typing .cast (
106
- typing .List [AnalyticsQueryResult ],
107
- construct_type (
108
- type_ = typing .List [AnalyticsQueryResult ], # type: ignore
109
- object_ = _response .json (),
110
- ),
111
- )
112
- _response_json = _response .json ()
113
- except JSONDecodeError :
114
- raise ApiError (status_code = _response .status_code , body = _response .text )
115
- raise ApiError (status_code = _response .status_code , body = _response_json )
84
+ response = await self ._raw_client .get (queries = queries , request_options = request_options )
85
+ return response .data
0 commit comments