|
| 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.points_summary_response import PointsSummaryResponse |
| 7 | +from ..core.pydantic_utilities import parse_obj_as |
| 8 | +from ..errors.unauthorized_error import UnauthorizedError |
| 9 | +from ..types.error_body import ErrorBody |
| 10 | +from ..errors.not_found_error import NotFoundError |
| 11 | +from json.decoder import JSONDecodeError |
| 12 | +from ..core.api_error import ApiError |
| 13 | +from ..types.points_trigger_response import PointsTriggerResponse |
| 14 | +from ..core.client_wrapper import AsyncClientWrapper |
| 15 | + |
| 16 | + |
| 17 | +class PointsClient: |
| 18 | + def __init__(self, *, client_wrapper: SyncClientWrapper): |
| 19 | + self._client_wrapper = client_wrapper |
| 20 | + |
| 21 | + def summary( |
| 22 | + self, *, request_options: typing.Optional[RequestOptions] = None |
| 23 | + ) -> PointsSummaryResponse: |
| 24 | + """ |
| 25 | + Get a breakdown of the number of users with points in each range. |
| 26 | +
|
| 27 | + Parameters |
| 28 | + ---------- |
| 29 | + request_options : typing.Optional[RequestOptions] |
| 30 | + Request-specific configuration. |
| 31 | +
|
| 32 | + Returns |
| 33 | + ------- |
| 34 | + PointsSummaryResponse |
| 35 | + Successful operation |
| 36 | +
|
| 37 | + Examples |
| 38 | + -------- |
| 39 | + from trophy import TrophyApi |
| 40 | +
|
| 41 | + client = TrophyApi( |
| 42 | + api_key="YOUR_API_KEY", |
| 43 | + ) |
| 44 | + client.points.summary() |
| 45 | + """ |
| 46 | + _response = self._client_wrapper.httpx_client.request( |
| 47 | + "points/summary", |
| 48 | + method="GET", |
| 49 | + request_options=request_options, |
| 50 | + ) |
| 51 | + try: |
| 52 | + if 200 <= _response.status_code < 300: |
| 53 | + return typing.cast( |
| 54 | + PointsSummaryResponse, |
| 55 | + parse_obj_as( |
| 56 | + type_=PointsSummaryResponse, # type: ignore |
| 57 | + object_=_response.json(), |
| 58 | + ), |
| 59 | + ) |
| 60 | + if _response.status_code == 401: |
| 61 | + raise UnauthorizedError( |
| 62 | + typing.cast( |
| 63 | + ErrorBody, |
| 64 | + parse_obj_as( |
| 65 | + type_=ErrorBody, # type: ignore |
| 66 | + object_=_response.json(), |
| 67 | + ), |
| 68 | + ) |
| 69 | + ) |
| 70 | + if _response.status_code == 404: |
| 71 | + raise NotFoundError( |
| 72 | + typing.cast( |
| 73 | + ErrorBody, |
| 74 | + parse_obj_as( |
| 75 | + type_=ErrorBody, # type: ignore |
| 76 | + object_=_response.json(), |
| 77 | + ), |
| 78 | + ) |
| 79 | + ) |
| 80 | + _response_json = _response.json() |
| 81 | + except JSONDecodeError: |
| 82 | + raise ApiError(status_code=_response.status_code, body=_response.text) |
| 83 | + raise ApiError(status_code=_response.status_code, body=_response_json) |
| 84 | + |
| 85 | + def triggers( |
| 86 | + self, *, request_options: typing.Optional[RequestOptions] = None |
| 87 | + ) -> typing.List[PointsTriggerResponse]: |
| 88 | + """ |
| 89 | + Get all points triggers. |
| 90 | +
|
| 91 | + Parameters |
| 92 | + ---------- |
| 93 | + request_options : typing.Optional[RequestOptions] |
| 94 | + Request-specific configuration. |
| 95 | +
|
| 96 | + Returns |
| 97 | + ------- |
| 98 | + typing.List[PointsTriggerResponse] |
| 99 | + Successful operation |
| 100 | +
|
| 101 | + Examples |
| 102 | + -------- |
| 103 | + from trophy import TrophyApi |
| 104 | +
|
| 105 | + client = TrophyApi( |
| 106 | + api_key="YOUR_API_KEY", |
| 107 | + ) |
| 108 | + client.points.triggers() |
| 109 | + """ |
| 110 | + _response = self._client_wrapper.httpx_client.request( |
| 111 | + "points/triggers", |
| 112 | + method="GET", |
| 113 | + request_options=request_options, |
| 114 | + ) |
| 115 | + try: |
| 116 | + if 200 <= _response.status_code < 300: |
| 117 | + return typing.cast( |
| 118 | + typing.List[PointsTriggerResponse], |
| 119 | + parse_obj_as( |
| 120 | + type_=typing.List[PointsTriggerResponse], # type: ignore |
| 121 | + object_=_response.json(), |
| 122 | + ), |
| 123 | + ) |
| 124 | + if _response.status_code == 401: |
| 125 | + raise UnauthorizedError( |
| 126 | + typing.cast( |
| 127 | + ErrorBody, |
| 128 | + parse_obj_as( |
| 129 | + type_=ErrorBody, # type: ignore |
| 130 | + object_=_response.json(), |
| 131 | + ), |
| 132 | + ) |
| 133 | + ) |
| 134 | + _response_json = _response.json() |
| 135 | + except JSONDecodeError: |
| 136 | + raise ApiError(status_code=_response.status_code, body=_response.text) |
| 137 | + raise ApiError(status_code=_response.status_code, body=_response_json) |
| 138 | + |
| 139 | + |
| 140 | +class AsyncPointsClient: |
| 141 | + def __init__(self, *, client_wrapper: AsyncClientWrapper): |
| 142 | + self._client_wrapper = client_wrapper |
| 143 | + |
| 144 | + async def summary( |
| 145 | + self, *, request_options: typing.Optional[RequestOptions] = None |
| 146 | + ) -> PointsSummaryResponse: |
| 147 | + """ |
| 148 | + Get a breakdown of the number of users with points in each range. |
| 149 | +
|
| 150 | + Parameters |
| 151 | + ---------- |
| 152 | + request_options : typing.Optional[RequestOptions] |
| 153 | + Request-specific configuration. |
| 154 | +
|
| 155 | + Returns |
| 156 | + ------- |
| 157 | + PointsSummaryResponse |
| 158 | + Successful operation |
| 159 | +
|
| 160 | + Examples |
| 161 | + -------- |
| 162 | + import asyncio |
| 163 | +
|
| 164 | + from trophy import AsyncTrophyApi |
| 165 | +
|
| 166 | + client = AsyncTrophyApi( |
| 167 | + api_key="YOUR_API_KEY", |
| 168 | + ) |
| 169 | +
|
| 170 | +
|
| 171 | + async def main() -> None: |
| 172 | + await client.points.summary() |
| 173 | +
|
| 174 | +
|
| 175 | + asyncio.run(main()) |
| 176 | + """ |
| 177 | + _response = await self._client_wrapper.httpx_client.request( |
| 178 | + "points/summary", |
| 179 | + method="GET", |
| 180 | + request_options=request_options, |
| 181 | + ) |
| 182 | + try: |
| 183 | + if 200 <= _response.status_code < 300: |
| 184 | + return typing.cast( |
| 185 | + PointsSummaryResponse, |
| 186 | + parse_obj_as( |
| 187 | + type_=PointsSummaryResponse, # type: ignore |
| 188 | + object_=_response.json(), |
| 189 | + ), |
| 190 | + ) |
| 191 | + if _response.status_code == 401: |
| 192 | + raise UnauthorizedError( |
| 193 | + typing.cast( |
| 194 | + ErrorBody, |
| 195 | + parse_obj_as( |
| 196 | + type_=ErrorBody, # type: ignore |
| 197 | + object_=_response.json(), |
| 198 | + ), |
| 199 | + ) |
| 200 | + ) |
| 201 | + if _response.status_code == 404: |
| 202 | + raise NotFoundError( |
| 203 | + typing.cast( |
| 204 | + ErrorBody, |
| 205 | + parse_obj_as( |
| 206 | + type_=ErrorBody, # type: ignore |
| 207 | + object_=_response.json(), |
| 208 | + ), |
| 209 | + ) |
| 210 | + ) |
| 211 | + _response_json = _response.json() |
| 212 | + except JSONDecodeError: |
| 213 | + raise ApiError(status_code=_response.status_code, body=_response.text) |
| 214 | + raise ApiError(status_code=_response.status_code, body=_response_json) |
| 215 | + |
| 216 | + async def triggers( |
| 217 | + self, *, request_options: typing.Optional[RequestOptions] = None |
| 218 | + ) -> typing.List[PointsTriggerResponse]: |
| 219 | + """ |
| 220 | + Get all points triggers. |
| 221 | +
|
| 222 | + Parameters |
| 223 | + ---------- |
| 224 | + request_options : typing.Optional[RequestOptions] |
| 225 | + Request-specific configuration. |
| 226 | +
|
| 227 | + Returns |
| 228 | + ------- |
| 229 | + typing.List[PointsTriggerResponse] |
| 230 | + Successful operation |
| 231 | +
|
| 232 | + Examples |
| 233 | + -------- |
| 234 | + import asyncio |
| 235 | +
|
| 236 | + from trophy import AsyncTrophyApi |
| 237 | +
|
| 238 | + client = AsyncTrophyApi( |
| 239 | + api_key="YOUR_API_KEY", |
| 240 | + ) |
| 241 | +
|
| 242 | +
|
| 243 | + async def main() -> None: |
| 244 | + await client.points.triggers() |
| 245 | +
|
| 246 | +
|
| 247 | + asyncio.run(main()) |
| 248 | + """ |
| 249 | + _response = await self._client_wrapper.httpx_client.request( |
| 250 | + "points/triggers", |
| 251 | + method="GET", |
| 252 | + request_options=request_options, |
| 253 | + ) |
| 254 | + try: |
| 255 | + if 200 <= _response.status_code < 300: |
| 256 | + return typing.cast( |
| 257 | + typing.List[PointsTriggerResponse], |
| 258 | + parse_obj_as( |
| 259 | + type_=typing.List[PointsTriggerResponse], # type: ignore |
| 260 | + object_=_response.json(), |
| 261 | + ), |
| 262 | + ) |
| 263 | + if _response.status_code == 401: |
| 264 | + raise UnauthorizedError( |
| 265 | + typing.cast( |
| 266 | + ErrorBody, |
| 267 | + parse_obj_as( |
| 268 | + type_=ErrorBody, # type: ignore |
| 269 | + object_=_response.json(), |
| 270 | + ), |
| 271 | + ) |
| 272 | + ) |
| 273 | + _response_json = _response.json() |
| 274 | + except JSONDecodeError: |
| 275 | + raise ApiError(status_code=_response.status_code, body=_response.text) |
| 276 | + raise ApiError(status_code=_response.status_code, body=_response_json) |
0 commit comments