22
33import typing
44from ..core .client_wrapper import SyncClientWrapper
5+ from .raw_client import RawAnalyticsClient
56from ..types .analytics_query import AnalyticsQuery
67from ..core .request_options import RequestOptions
78from ..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
129from ..core .client_wrapper import AsyncClientWrapper
10+ from .raw_client import AsyncRawAnalyticsClient
1311
1412# this is used as the default value for optional parameters
1513OMIT = typing .cast (typing .Any , ...)
1614
1715
1816class AnalyticsClient :
1917 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
2130
2231 def get (
2332 self , * , queries : typing .Sequence [AnalyticsQuery ], request_options : typing .Optional [RequestOptions ] = None
@@ -36,38 +45,24 @@ def get(
3645 typing.List[AnalyticsQueryResult]
3746
3847 """
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
6650
6751
6852class AsyncAnalyticsClient :
6953 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
7166
7267 async def get (
7368 self , * , queries : typing .Sequence [AnalyticsQuery ], request_options : typing .Optional [RequestOptions ] = None
@@ -86,30 +81,5 @@ async def get(
8681 typing.List[AnalyticsQueryResult]
8782
8883 """
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