|
| 1 | +# This file was auto-generated by Fern from our API Definition. |
| 2 | + |
| 3 | +from ..core.client_wrapper import SyncClientWrapper |
| 4 | +import typing |
| 5 | +from ..core.request_options import RequestOptions |
| 6 | +from ..types.subscription import Subscription |
| 7 | +from ..core.unchecked_base_model import construct_type |
| 8 | +from ..errors.unprocessable_entity_error import UnprocessableEntityError |
| 9 | +from ..types.http_validation_error import HttpValidationError |
| 10 | +from json.decoder import JSONDecodeError |
| 11 | +from ..core.api_error import ApiError |
| 12 | +from ..types.user import User |
| 13 | +from ..core.client_wrapper import AsyncClientWrapper |
| 14 | + |
| 15 | + |
| 16 | +class UserClient: |
| 17 | + def __init__(self, *, client_wrapper: SyncClientWrapper): |
| 18 | + self._client_wrapper = client_wrapper |
| 19 | + |
| 20 | + def get_subscription(self, *, request_options: typing.Optional[RequestOptions] = None) -> Subscription: |
| 21 | + """ |
| 22 | + Gets extended information about the users subscription |
| 23 | +
|
| 24 | + Parameters |
| 25 | + ---------- |
| 26 | + request_options : typing.Optional[RequestOptions] |
| 27 | + Request-specific configuration. |
| 28 | +
|
| 29 | + Returns |
| 30 | + ------- |
| 31 | + Subscription |
| 32 | + Successful Response |
| 33 | +
|
| 34 | + Examples |
| 35 | + -------- |
| 36 | + from neuralaudio import NeuralAudio |
| 37 | +
|
| 38 | + client = NeuralAudio( |
| 39 | + api_key="YOUR_API_KEY", |
| 40 | + ) |
| 41 | + client.user.get_subscription() |
| 42 | + """ |
| 43 | + _response = self._client_wrapper.httpx_client.request( |
| 44 | + "v1/user/subscription", |
| 45 | + method="GET", |
| 46 | + request_options=request_options, |
| 47 | + ) |
| 48 | + try: |
| 49 | + if 200 <= _response.status_code < 300: |
| 50 | + return typing.cast( |
| 51 | + Subscription, |
| 52 | + construct_type( |
| 53 | + type_=Subscription, # type: ignore |
| 54 | + object_=_response.json(), |
| 55 | + ), |
| 56 | + ) |
| 57 | + if _response.status_code == 422: |
| 58 | + raise UnprocessableEntityError( |
| 59 | + typing.cast( |
| 60 | + HttpValidationError, |
| 61 | + construct_type( |
| 62 | + type_=HttpValidationError, # type: ignore |
| 63 | + object_=_response.json(), |
| 64 | + ), |
| 65 | + ) |
| 66 | + ) |
| 67 | + _response_json = _response.json() |
| 68 | + except JSONDecodeError: |
| 69 | + raise ApiError(status_code=_response.status_code, body=_response.text) |
| 70 | + raise ApiError(status_code=_response.status_code, body=_response_json) |
| 71 | + |
| 72 | + def get(self, *, request_options: typing.Optional[RequestOptions] = None) -> User: |
| 73 | + """ |
| 74 | + Gets information about the user |
| 75 | +
|
| 76 | + Parameters |
| 77 | + ---------- |
| 78 | + request_options : typing.Optional[RequestOptions] |
| 79 | + Request-specific configuration. |
| 80 | +
|
| 81 | + Returns |
| 82 | + ------- |
| 83 | + User |
| 84 | + Successful Response |
| 85 | +
|
| 86 | + Examples |
| 87 | + -------- |
| 88 | + from neuralaudio import NeuralAudio |
| 89 | +
|
| 90 | + client = NeuralAudio( |
| 91 | + api_key="YOUR_API_KEY", |
| 92 | + ) |
| 93 | + client.user.get() |
| 94 | + """ |
| 95 | + _response = self._client_wrapper.httpx_client.request( |
| 96 | + "v1/user", |
| 97 | + method="GET", |
| 98 | + request_options=request_options, |
| 99 | + ) |
| 100 | + try: |
| 101 | + if 200 <= _response.status_code < 300: |
| 102 | + return typing.cast( |
| 103 | + User, |
| 104 | + construct_type( |
| 105 | + type_=User, # type: ignore |
| 106 | + object_=_response.json(), |
| 107 | + ), |
| 108 | + ) |
| 109 | + if _response.status_code == 422: |
| 110 | + raise UnprocessableEntityError( |
| 111 | + typing.cast( |
| 112 | + HttpValidationError, |
| 113 | + construct_type( |
| 114 | + type_=HttpValidationError, # type: ignore |
| 115 | + object_=_response.json(), |
| 116 | + ), |
| 117 | + ) |
| 118 | + ) |
| 119 | + _response_json = _response.json() |
| 120 | + except JSONDecodeError: |
| 121 | + raise ApiError(status_code=_response.status_code, body=_response.text) |
| 122 | + raise ApiError(status_code=_response.status_code, body=_response_json) |
| 123 | + |
| 124 | + |
| 125 | +class AsyncUserClient: |
| 126 | + def __init__(self, *, client_wrapper: AsyncClientWrapper): |
| 127 | + self._client_wrapper = client_wrapper |
| 128 | + |
| 129 | + async def get_subscription(self, *, request_options: typing.Optional[RequestOptions] = None) -> Subscription: |
| 130 | + """ |
| 131 | + Gets extended information about the users subscription |
| 132 | +
|
| 133 | + Parameters |
| 134 | + ---------- |
| 135 | + request_options : typing.Optional[RequestOptions] |
| 136 | + Request-specific configuration. |
| 137 | +
|
| 138 | + Returns |
| 139 | + ------- |
| 140 | + Subscription |
| 141 | + Successful Response |
| 142 | +
|
| 143 | + Examples |
| 144 | + -------- |
| 145 | + import asyncio |
| 146 | +
|
| 147 | + from neuralaudio import AsyncNeuralAudio |
| 148 | +
|
| 149 | + client = AsyncNeuralAudio( |
| 150 | + api_key="YOUR_API_KEY", |
| 151 | + ) |
| 152 | +
|
| 153 | +
|
| 154 | + async def main() -> None: |
| 155 | + await client.user.get_subscription() |
| 156 | +
|
| 157 | +
|
| 158 | + asyncio.run(main()) |
| 159 | + """ |
| 160 | + _response = await self._client_wrapper.httpx_client.request( |
| 161 | + "v1/user/subscription", |
| 162 | + method="GET", |
| 163 | + request_options=request_options, |
| 164 | + ) |
| 165 | + try: |
| 166 | + if 200 <= _response.status_code < 300: |
| 167 | + return typing.cast( |
| 168 | + Subscription, |
| 169 | + construct_type( |
| 170 | + type_=Subscription, # type: ignore |
| 171 | + object_=_response.json(), |
| 172 | + ), |
| 173 | + ) |
| 174 | + if _response.status_code == 422: |
| 175 | + raise UnprocessableEntityError( |
| 176 | + typing.cast( |
| 177 | + HttpValidationError, |
| 178 | + construct_type( |
| 179 | + type_=HttpValidationError, # type: ignore |
| 180 | + object_=_response.json(), |
| 181 | + ), |
| 182 | + ) |
| 183 | + ) |
| 184 | + _response_json = _response.json() |
| 185 | + except JSONDecodeError: |
| 186 | + raise ApiError(status_code=_response.status_code, body=_response.text) |
| 187 | + raise ApiError(status_code=_response.status_code, body=_response_json) |
| 188 | + |
| 189 | + async def get(self, *, request_options: typing.Optional[RequestOptions] = None) -> User: |
| 190 | + """ |
| 191 | + Gets information about the user |
| 192 | +
|
| 193 | + Parameters |
| 194 | + ---------- |
| 195 | + request_options : typing.Optional[RequestOptions] |
| 196 | + Request-specific configuration. |
| 197 | +
|
| 198 | + Returns |
| 199 | + ------- |
| 200 | + User |
| 201 | + Successful Response |
| 202 | +
|
| 203 | + Examples |
| 204 | + -------- |
| 205 | + import asyncio |
| 206 | +
|
| 207 | + from neuralaudio import AsyncNeuralAudio |
| 208 | +
|
| 209 | + client = AsyncNeuralAudio( |
| 210 | + api_key="YOUR_API_KEY", |
| 211 | + ) |
| 212 | +
|
| 213 | +
|
| 214 | + async def main() -> None: |
| 215 | + await client.user.get() |
| 216 | +
|
| 217 | +
|
| 218 | + asyncio.run(main()) |
| 219 | + """ |
| 220 | + _response = await self._client_wrapper.httpx_client.request( |
| 221 | + "v1/user", |
| 222 | + method="GET", |
| 223 | + request_options=request_options, |
| 224 | + ) |
| 225 | + try: |
| 226 | + if 200 <= _response.status_code < 300: |
| 227 | + return typing.cast( |
| 228 | + User, |
| 229 | + construct_type( |
| 230 | + type_=User, # type: ignore |
| 231 | + object_=_response.json(), |
| 232 | + ), |
| 233 | + ) |
| 234 | + if _response.status_code == 422: |
| 235 | + raise UnprocessableEntityError( |
| 236 | + typing.cast( |
| 237 | + HttpValidationError, |
| 238 | + construct_type( |
| 239 | + type_=HttpValidationError, # type: ignore |
| 240 | + object_=_response.json(), |
| 241 | + ), |
| 242 | + ) |
| 243 | + ) |
| 244 | + _response_json = _response.json() |
| 245 | + except JSONDecodeError: |
| 246 | + raise ApiError(status_code=_response.status_code, body=_response.text) |
| 247 | + raise ApiError(status_code=_response.status_code, body=_response_json) |
0 commit comments