|
1 | 1 | # This file was auto-generated by Fern from our API Definition. |
2 | 2 |
|
| 3 | +import typing |
| 4 | +from json.decoder import JSONDecodeError |
| 5 | + |
| 6 | +from ...core.api_error import ApiError |
3 | 7 | from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper |
| 8 | +from ...core.http_response import AsyncHttpResponse, HttpResponse |
| 9 | +from ...core.pydantic_utilities import parse_obj_as |
| 10 | +from ...core.request_options import RequestOptions |
| 11 | +from ...errors.bad_request_error import BadRequestError |
| 12 | +from ...errors.unauthorized_error import UnauthorizedError |
| 13 | +from ...errors.unprocessable_entity_error import UnprocessableEntityError |
| 14 | +from ...types.error_body import ErrorBody |
| 15 | +from ...types.restore_streaks_response import RestoreStreaksResponse |
| 16 | + |
| 17 | +# this is used as the default value for optional parameters |
| 18 | +OMIT = typing.cast(typing.Any, ...) |
4 | 19 |
|
5 | 20 |
|
6 | 21 | class RawStreaksClient: |
7 | 22 | def __init__(self, *, client_wrapper: SyncClientWrapper): |
8 | 23 | self._client_wrapper = client_wrapper |
9 | 24 |
|
| 25 | + def restore( |
| 26 | + self, *, user_ids: typing.Sequence[str], request_options: typing.Optional[RequestOptions] = None |
| 27 | + ) -> HttpResponse[RestoreStreaksResponse]: |
| 28 | + """ |
| 29 | + Restore streaks for multiple users to the maximum length in the last 90 days (in the case of daily streaks), one year (in the case of weekly streaks), or two years (in the case of monthly streaks). |
| 30 | +
|
| 31 | + Parameters |
| 32 | + ---------- |
| 33 | + user_ids : typing.Sequence[str] |
| 34 | + Array of user IDs to restore streaks for. Maximum 100 users per request. |
| 35 | +
|
| 36 | + request_options : typing.Optional[RequestOptions] |
| 37 | + Request-specific configuration. |
| 38 | +
|
| 39 | + Returns |
| 40 | + ------- |
| 41 | + HttpResponse[RestoreStreaksResponse] |
| 42 | + Successful operation |
| 43 | + """ |
| 44 | + _response = self._client_wrapper.httpx_client.request( |
| 45 | + "streaks/restore", |
| 46 | + base_url=self._client_wrapper.get_environment().admin, |
| 47 | + method="POST", |
| 48 | + json={ |
| 49 | + "userIds": user_ids, |
| 50 | + }, |
| 51 | + headers={ |
| 52 | + "content-type": "application/json", |
| 53 | + }, |
| 54 | + request_options=request_options, |
| 55 | + omit=OMIT, |
| 56 | + ) |
| 57 | + try: |
| 58 | + if 200 <= _response.status_code < 300: |
| 59 | + _data = typing.cast( |
| 60 | + RestoreStreaksResponse, |
| 61 | + parse_obj_as( |
| 62 | + type_=RestoreStreaksResponse, # type: ignore |
| 63 | + object_=_response.json(), |
| 64 | + ), |
| 65 | + ) |
| 66 | + return HttpResponse(response=_response, data=_data) |
| 67 | + if _response.status_code == 400: |
| 68 | + raise BadRequestError( |
| 69 | + headers=dict(_response.headers), |
| 70 | + body=typing.cast( |
| 71 | + ErrorBody, |
| 72 | + parse_obj_as( |
| 73 | + type_=ErrorBody, # type: ignore |
| 74 | + object_=_response.json(), |
| 75 | + ), |
| 76 | + ), |
| 77 | + ) |
| 78 | + if _response.status_code == 401: |
| 79 | + raise UnauthorizedError( |
| 80 | + headers=dict(_response.headers), |
| 81 | + body=typing.cast( |
| 82 | + ErrorBody, |
| 83 | + parse_obj_as( |
| 84 | + type_=ErrorBody, # type: ignore |
| 85 | + object_=_response.json(), |
| 86 | + ), |
| 87 | + ), |
| 88 | + ) |
| 89 | + if _response.status_code == 422: |
| 90 | + raise UnprocessableEntityError( |
| 91 | + headers=dict(_response.headers), |
| 92 | + body=typing.cast( |
| 93 | + ErrorBody, |
| 94 | + parse_obj_as( |
| 95 | + type_=ErrorBody, # type: ignore |
| 96 | + object_=_response.json(), |
| 97 | + ), |
| 98 | + ), |
| 99 | + ) |
| 100 | + _response_json = _response.json() |
| 101 | + except JSONDecodeError: |
| 102 | + raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) |
| 103 | + raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) |
| 104 | + |
10 | 105 |
|
11 | 106 | class AsyncRawStreaksClient: |
12 | 107 | def __init__(self, *, client_wrapper: AsyncClientWrapper): |
13 | 108 | self._client_wrapper = client_wrapper |
| 109 | + |
| 110 | + async def restore( |
| 111 | + self, *, user_ids: typing.Sequence[str], request_options: typing.Optional[RequestOptions] = None |
| 112 | + ) -> AsyncHttpResponse[RestoreStreaksResponse]: |
| 113 | + """ |
| 114 | + Restore streaks for multiple users to the maximum length in the last 90 days (in the case of daily streaks), one year (in the case of weekly streaks), or two years (in the case of monthly streaks). |
| 115 | +
|
| 116 | + Parameters |
| 117 | + ---------- |
| 118 | + user_ids : typing.Sequence[str] |
| 119 | + Array of user IDs to restore streaks for. Maximum 100 users per request. |
| 120 | +
|
| 121 | + request_options : typing.Optional[RequestOptions] |
| 122 | + Request-specific configuration. |
| 123 | +
|
| 124 | + Returns |
| 125 | + ------- |
| 126 | + AsyncHttpResponse[RestoreStreaksResponse] |
| 127 | + Successful operation |
| 128 | + """ |
| 129 | + _response = await self._client_wrapper.httpx_client.request( |
| 130 | + "streaks/restore", |
| 131 | + base_url=self._client_wrapper.get_environment().admin, |
| 132 | + method="POST", |
| 133 | + json={ |
| 134 | + "userIds": user_ids, |
| 135 | + }, |
| 136 | + headers={ |
| 137 | + "content-type": "application/json", |
| 138 | + }, |
| 139 | + request_options=request_options, |
| 140 | + omit=OMIT, |
| 141 | + ) |
| 142 | + try: |
| 143 | + if 200 <= _response.status_code < 300: |
| 144 | + _data = typing.cast( |
| 145 | + RestoreStreaksResponse, |
| 146 | + parse_obj_as( |
| 147 | + type_=RestoreStreaksResponse, # type: ignore |
| 148 | + object_=_response.json(), |
| 149 | + ), |
| 150 | + ) |
| 151 | + return AsyncHttpResponse(response=_response, data=_data) |
| 152 | + if _response.status_code == 400: |
| 153 | + raise BadRequestError( |
| 154 | + headers=dict(_response.headers), |
| 155 | + body=typing.cast( |
| 156 | + ErrorBody, |
| 157 | + parse_obj_as( |
| 158 | + type_=ErrorBody, # type: ignore |
| 159 | + object_=_response.json(), |
| 160 | + ), |
| 161 | + ), |
| 162 | + ) |
| 163 | + if _response.status_code == 401: |
| 164 | + raise UnauthorizedError( |
| 165 | + headers=dict(_response.headers), |
| 166 | + body=typing.cast( |
| 167 | + ErrorBody, |
| 168 | + parse_obj_as( |
| 169 | + type_=ErrorBody, # type: ignore |
| 170 | + object_=_response.json(), |
| 171 | + ), |
| 172 | + ), |
| 173 | + ) |
| 174 | + if _response.status_code == 422: |
| 175 | + raise UnprocessableEntityError( |
| 176 | + headers=dict(_response.headers), |
| 177 | + body=typing.cast( |
| 178 | + ErrorBody, |
| 179 | + parse_obj_as( |
| 180 | + type_=ErrorBody, # type: ignore |
| 181 | + object_=_response.json(), |
| 182 | + ), |
| 183 | + ), |
| 184 | + ) |
| 185 | + _response_json = _response.json() |
| 186 | + except JSONDecodeError: |
| 187 | + raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) |
| 188 | + raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) |
0 commit comments