-
Notifications
You must be signed in to change notification settings - Fork 6
/
client.py
2375 lines (2057 loc) · 76.2 KB
/
client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# This file was auto-generated by Fern from our API Definition.
import typing
from ..core.client_wrapper import SyncClientWrapper
from ..core.request_options import RequestOptions
from ..types.paginated_users_response import PaginatedUsersResponse
from ..core.pydantic_utilities import parse_obj_as
from ..errors.unprocessable_entity_error import UnprocessableEntityError
from ..types.http_validation_error import HttpValidationError
from json.decoder import JSONDecodeError
from ..core.api_error import ApiError
from ..types.client_facing_user_key import ClientFacingUserKey
from ..errors.bad_request_error import BadRequestError
from ..types.metrics_result import MetricsResult
from ..types.user_sign_in_token_response import UserSignInTokenResponse
from ..core.jsonable_encoder import jsonable_encoder
from ..types.client_facing_provider_with_status import ClientFacingProviderWithStatus
from ..types.client_facing_user import ClientFacingUser
from ..types.user_success_response import UserSuccessResponse
from ..types.user_info import UserInfo
from ..types.responsible_relationship import ResponsibleRelationship
from ..types.vital_core_schemas_db_schemas_lab_test_insurance_person_details import (
VitalCoreSchemasDbSchemasLabTestInsurancePersonDetails,
)
from ..types.guarantor_details import GuarantorDetails
from ..types.client_facing_insurance import ClientFacingInsurance
from ..types.address import Address
from ..types.providers import Providers
from ..types.user_refresh_success_response import UserRefreshSuccessResponse
from ..core.client_wrapper import AsyncClientWrapper
# this is used as the default value for optional parameters
OMIT = typing.cast(typing.Any, ...)
class UserClient:
def __init__(self, *, client_wrapper: SyncClientWrapper):
self._client_wrapper = client_wrapper
def get_all(
self,
*,
offset: typing.Optional[int] = None,
limit: typing.Optional[int] = None,
request_options: typing.Optional[RequestOptions] = None,
) -> PaginatedUsersResponse:
"""
GET All users for team.
Parameters
----------
offset : typing.Optional[int]
limit : typing.Optional[int]
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
PaginatedUsersResponse
Successful Response
Examples
--------
from vital import Vital
client = Vital(
api_key="YOUR_API_KEY",
)
client.user.get_all()
"""
_response = self._client_wrapper.httpx_client.request(
"v2/user",
method="GET",
params={
"offset": offset,
"limit": limit,
},
request_options=request_options,
)
try:
if 200 <= _response.status_code < 300:
return typing.cast(
PaginatedUsersResponse,
parse_obj_as(
type_=PaginatedUsersResponse, # type: ignore
object_=_response.json(),
),
)
if _response.status_code == 422:
raise UnprocessableEntityError(
typing.cast(
HttpValidationError,
parse_obj_as(
type_=HttpValidationError, # type: ignore
object_=_response.json(),
),
)
)
_response_json = _response.json()
except JSONDecodeError:
raise ApiError(status_code=_response.status_code, body=_response.text)
raise ApiError(status_code=_response.status_code, body=_response_json)
def create(
self,
*,
client_user_id: str,
fallback_time_zone: typing.Optional[str] = OMIT,
fallback_birth_date: typing.Optional[str] = OMIT,
ingestion_start: typing.Optional[str] = OMIT,
ingestion_end: typing.Optional[str] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> ClientFacingUserKey:
"""
POST Create a Vital user given a client_user_id and returns the user_id.
Parameters
----------
client_user_id : str
A unique ID representing the end user. Typically this will be a user ID from your application. Personally identifiable information, such as an email address or phone number, should not be used in the client_user_id.
fallback_time_zone : typing.Optional[str]
Fallback time zone of the user, in the form of a valid IANA tzdatabase identifier (e.g., `Europe/London` or `America/Los_Angeles`).
Used when pulling data from sources that are completely time zone agnostic (e.g., all time is relative to UTC clock, without any time zone attributions on data points).
fallback_birth_date : typing.Optional[str]
Fallback date of birth of the user, in YYYY-mm-dd format. Used for calculating max heartrate for providers that don not provide users' age.
ingestion_start : typing.Optional[str]
Starting bound for user data ingestion. Data older than this date will not be ingested.
ingestion_end : typing.Optional[str]
Ending bound for user data ingestion. Data from this date or later will not be ingested and the connection will be deregistered.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
ClientFacingUserKey
Successful Response
Examples
--------
from vital import Vital
client = Vital(
api_key="YOUR_API_KEY",
)
client.user.create(
client_user_id="client_user_id",
)
"""
_response = self._client_wrapper.httpx_client.request(
"v2/user",
method="POST",
json={
"client_user_id": client_user_id,
"fallback_time_zone": fallback_time_zone,
"fallback_birth_date": fallback_birth_date,
"ingestion_start": ingestion_start,
"ingestion_end": ingestion_end,
},
request_options=request_options,
omit=OMIT,
)
try:
if 200 <= _response.status_code < 300:
return typing.cast(
ClientFacingUserKey,
parse_obj_as(
type_=ClientFacingUserKey, # type: ignore
object_=_response.json(),
),
)
if _response.status_code == 400:
raise BadRequestError(
typing.cast(
typing.Optional[typing.Any],
parse_obj_as(
type_=typing.Optional[typing.Any], # type: ignore
object_=_response.json(),
),
)
)
if _response.status_code == 422:
raise UnprocessableEntityError(
typing.cast(
HttpValidationError,
parse_obj_as(
type_=HttpValidationError, # type: ignore
object_=_response.json(),
),
)
)
_response_json = _response.json()
except JSONDecodeError:
raise ApiError(status_code=_response.status_code, body=_response.text)
raise ApiError(status_code=_response.status_code, body=_response_json)
def get_team_metrics(self, *, request_options: typing.Optional[RequestOptions] = None) -> MetricsResult:
"""
GET metrics for team.
Parameters
----------
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
MetricsResult
Successful Response
Examples
--------
from vital import Vital
client = Vital(
api_key="YOUR_API_KEY",
)
client.user.get_team_metrics()
"""
_response = self._client_wrapper.httpx_client.request(
"v2/user/metrics",
method="GET",
request_options=request_options,
)
try:
if 200 <= _response.status_code < 300:
return typing.cast(
MetricsResult,
parse_obj_as(
type_=MetricsResult, # type: ignore
object_=_response.json(),
),
)
_response_json = _response.json()
except JSONDecodeError:
raise ApiError(status_code=_response.status_code, body=_response.text)
raise ApiError(status_code=_response.status_code, body=_response_json)
def get_user_sign_in_token(
self, user_id: str, *, request_options: typing.Optional[RequestOptions] = None
) -> UserSignInTokenResponse:
"""
Parameters
----------
user_id : str
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
UserSignInTokenResponse
Successful Response
Examples
--------
from vital import Vital
client = Vital(
api_key="YOUR_API_KEY",
)
client.user.get_user_sign_in_token(
user_id="user_id",
)
"""
_response = self._client_wrapper.httpx_client.request(
f"v2/user/{jsonable_encoder(user_id)}/sign_in_token",
method="POST",
request_options=request_options,
)
try:
if 200 <= _response.status_code < 300:
return typing.cast(
UserSignInTokenResponse,
parse_obj_as(
type_=UserSignInTokenResponse, # type: ignore
object_=_response.json(),
),
)
if _response.status_code == 422:
raise UnprocessableEntityError(
typing.cast(
HttpValidationError,
parse_obj_as(
type_=HttpValidationError, # type: ignore
object_=_response.json(),
),
)
)
_response_json = _response.json()
except JSONDecodeError:
raise ApiError(status_code=_response.status_code, body=_response.text)
raise ApiError(status_code=_response.status_code, body=_response_json)
def get_connected_providers(
self, user_id: str, *, request_options: typing.Optional[RequestOptions] = None
) -> typing.Dict[str, typing.List[ClientFacingProviderWithStatus]]:
"""
GET Users connected providers
Parameters
----------
user_id : str
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
typing.Dict[str, typing.List[ClientFacingProviderWithStatus]]
Successful Response
Examples
--------
from vital import Vital
client = Vital(
api_key="YOUR_API_KEY",
)
client.user.get_connected_providers(
user_id="user_id",
)
"""
_response = self._client_wrapper.httpx_client.request(
f"v2/user/providers/{jsonable_encoder(user_id)}",
method="GET",
request_options=request_options,
)
try:
if 200 <= _response.status_code < 300:
return typing.cast(
typing.Dict[str, typing.List[ClientFacingProviderWithStatus]],
parse_obj_as(
type_=typing.Dict[str, typing.List[ClientFacingProviderWithStatus]], # type: ignore
object_=_response.json(),
),
)
if _response.status_code == 422:
raise UnprocessableEntityError(
typing.cast(
HttpValidationError,
parse_obj_as(
type_=HttpValidationError, # type: ignore
object_=_response.json(),
),
)
)
_response_json = _response.json()
except JSONDecodeError:
raise ApiError(status_code=_response.status_code, body=_response.text)
raise ApiError(status_code=_response.status_code, body=_response_json)
def get(self, user_id: str, *, request_options: typing.Optional[RequestOptions] = None) -> ClientFacingUser:
"""
GET User details given the user_id.
Parameters
----------
user_id : str
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
ClientFacingUser
Successful Response
Examples
--------
from vital import Vital
client = Vital(
api_key="YOUR_API_KEY",
)
client.user.get(
user_id="user_id",
)
"""
_response = self._client_wrapper.httpx_client.request(
f"v2/user/{jsonable_encoder(user_id)}",
method="GET",
request_options=request_options,
)
try:
if 200 <= _response.status_code < 300:
return typing.cast(
ClientFacingUser,
parse_obj_as(
type_=ClientFacingUser, # type: ignore
object_=_response.json(),
),
)
if _response.status_code == 422:
raise UnprocessableEntityError(
typing.cast(
HttpValidationError,
parse_obj_as(
type_=HttpValidationError, # type: ignore
object_=_response.json(),
),
)
)
_response_json = _response.json()
except JSONDecodeError:
raise ApiError(status_code=_response.status_code, body=_response.text)
raise ApiError(status_code=_response.status_code, body=_response_json)
def delete(self, user_id: str, *, request_options: typing.Optional[RequestOptions] = None) -> UserSuccessResponse:
"""
Parameters
----------
user_id : str
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
UserSuccessResponse
Successful Response
Examples
--------
from vital import Vital
client = Vital(
api_key="YOUR_API_KEY",
)
client.user.delete(
user_id="user_id",
)
"""
_response = self._client_wrapper.httpx_client.request(
f"v2/user/{jsonable_encoder(user_id)}",
method="DELETE",
request_options=request_options,
)
try:
if 200 <= _response.status_code < 300:
return typing.cast(
UserSuccessResponse,
parse_obj_as(
type_=UserSuccessResponse, # type: ignore
object_=_response.json(),
),
)
if _response.status_code == 422:
raise UnprocessableEntityError(
typing.cast(
HttpValidationError,
parse_obj_as(
type_=HttpValidationError, # type: ignore
object_=_response.json(),
),
)
)
_response_json = _response.json()
except JSONDecodeError:
raise ApiError(status_code=_response.status_code, body=_response.text)
raise ApiError(status_code=_response.status_code, body=_response_json)
def patch(
self,
user_id: str,
*,
fallback_time_zone: typing.Optional[str] = OMIT,
fallback_birth_date: typing.Optional[str] = OMIT,
ingestion_start: typing.Optional[str] = OMIT,
ingestion_end: typing.Optional[str] = OMIT,
client_user_id: typing.Optional[str] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> None:
"""
Parameters
----------
user_id : str
fallback_time_zone : typing.Optional[str]
Fallback time zone of the user, in the form of a valid IANA tzdatabase identifier (e.g., `Europe/London` or `America/Los_Angeles`).
Used when pulling data from sources that are completely time zone agnostic (e.g., all time is relative to UTC clock, without any time zone attributions on data points).
fallback_birth_date : typing.Optional[str]
Fallback date of birth of the user, in YYYY-mm-dd format. Used for calculating max heartrate for providers that don not provide users' age.
ingestion_start : typing.Optional[str]
Starting bound for user data ingestion. Data older than this date will not be ingested.
ingestion_end : typing.Optional[str]
Ending bound for user data ingestion. Data from this date or later will not be ingested and the connection will be deregistered.
client_user_id : typing.Optional[str]
A unique ID representing the end user. Typically this will be a user ID from your application. Personally identifiable information, such as an email address or phone number, should not be used in the client_user_id.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
None
Examples
--------
from vital import Vital
client = Vital(
api_key="YOUR_API_KEY",
)
client.user.patch(
user_id="user_id",
)
"""
_response = self._client_wrapper.httpx_client.request(
f"v2/user/{jsonable_encoder(user_id)}",
method="PATCH",
json={
"fallback_time_zone": fallback_time_zone,
"fallback_birth_date": fallback_birth_date,
"ingestion_start": ingestion_start,
"ingestion_end": ingestion_end,
"client_user_id": client_user_id,
},
request_options=request_options,
omit=OMIT,
)
try:
if 200 <= _response.status_code < 300:
return
if _response.status_code == 422:
raise UnprocessableEntityError(
typing.cast(
HttpValidationError,
parse_obj_as(
type_=HttpValidationError, # type: ignore
object_=_response.json(),
),
)
)
_response_json = _response.json()
except JSONDecodeError:
raise ApiError(status_code=_response.status_code, body=_response.text)
raise ApiError(status_code=_response.status_code, body=_response_json)
def get_latest_user_info(
self, user_id: str, *, request_options: typing.Optional[RequestOptions] = None
) -> UserInfo:
"""
Parameters
----------
user_id : str
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
UserInfo
Successful Response
Examples
--------
from vital import Vital
client = Vital(
api_key="YOUR_API_KEY",
)
client.user.get_latest_user_info(
user_id="user_id",
)
"""
_response = self._client_wrapper.httpx_client.request(
f"v2/user/{jsonable_encoder(user_id)}/info/latest",
method="GET",
request_options=request_options,
)
try:
if 200 <= _response.status_code < 300:
return typing.cast(
UserInfo,
parse_obj_as(
type_=UserInfo, # type: ignore
object_=_response.json(),
),
)
if _response.status_code == 422:
raise UnprocessableEntityError(
typing.cast(
HttpValidationError,
parse_obj_as(
type_=HttpValidationError, # type: ignore
object_=_response.json(),
),
)
)
_response_json = _response.json()
except JSONDecodeError:
raise ApiError(status_code=_response.status_code, body=_response.text)
raise ApiError(status_code=_response.status_code, body=_response_json)
def create_insurance(
self,
user_id: str,
*,
payor_code: str,
member_id: str,
relationship: ResponsibleRelationship,
insured: VitalCoreSchemasDbSchemasLabTestInsurancePersonDetails,
group_id: typing.Optional[str] = OMIT,
guarantor: typing.Optional[GuarantorDetails] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> ClientFacingInsurance:
"""
Parameters
----------
user_id : str
payor_code : str
member_id : str
relationship : ResponsibleRelationship
insured : VitalCoreSchemasDbSchemasLabTestInsurancePersonDetails
group_id : typing.Optional[str]
guarantor : typing.Optional[GuarantorDetails]
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
ClientFacingInsurance
Successful Response
Examples
--------
from vital import (
Address,
Gender,
ResponsibleRelationship,
Vital,
VitalCoreSchemasDbSchemasLabTestInsurancePersonDetails,
)
client = Vital(
api_key="YOUR_API_KEY",
)
client.user.create_insurance(
user_id="user_id",
payor_code="payor_code",
member_id="member_id",
relationship=ResponsibleRelationship.SELF,
insured=VitalCoreSchemasDbSchemasLabTestInsurancePersonDetails(
first_name="first_name",
last_name="last_name",
gender=Gender.FEMALE,
address=Address(
first_line="first_line",
country="country",
zip="zip",
city="city",
state="state",
),
dob="dob",
email="email",
phone_number="phone_number",
),
)
"""
_response = self._client_wrapper.httpx_client.request(
f"v2/user/{jsonable_encoder(user_id)}/insurance",
method="POST",
json={
"payor_code": payor_code,
"member_id": member_id,
"group_id": group_id,
"relationship": relationship,
"insured": insured,
"guarantor": guarantor,
},
request_options=request_options,
omit=OMIT,
)
try:
if 200 <= _response.status_code < 300:
return typing.cast(
ClientFacingInsurance,
parse_obj_as(
type_=ClientFacingInsurance, # type: ignore
object_=_response.json(),
),
)
if _response.status_code == 422:
raise UnprocessableEntityError(
typing.cast(
HttpValidationError,
parse_obj_as(
type_=HttpValidationError, # type: ignore
object_=_response.json(),
),
)
)
_response_json = _response.json()
except JSONDecodeError:
raise ApiError(status_code=_response.status_code, body=_response.text)
raise ApiError(status_code=_response.status_code, body=_response_json)
def get_latest_insurance(
self, user_id: str, *, request_options: typing.Optional[RequestOptions] = None
) -> ClientFacingInsurance:
"""
Parameters
----------
user_id : str
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
ClientFacingInsurance
Successful Response
Examples
--------
from vital import Vital
client = Vital(
api_key="YOUR_API_KEY",
)
client.user.get_latest_insurance(
user_id="user_id",
)
"""
_response = self._client_wrapper.httpx_client.request(
f"v2/user/{jsonable_encoder(user_id)}/insurance/latest",
method="GET",
request_options=request_options,
)
try:
if 200 <= _response.status_code < 300:
return typing.cast(
ClientFacingInsurance,
parse_obj_as(
type_=ClientFacingInsurance, # type: ignore
object_=_response.json(),
),
)
if _response.status_code == 422:
raise UnprocessableEntityError(
typing.cast(
HttpValidationError,
parse_obj_as(
type_=HttpValidationError, # type: ignore
object_=_response.json(),
),
)
)
_response_json = _response.json()
except JSONDecodeError:
raise ApiError(status_code=_response.status_code, body=_response.text)
raise ApiError(status_code=_response.status_code, body=_response_json)
def upsert_user_info(
self,
user_id: str,
*,
first_name: str,
last_name: str,
email: str,
phone_number: str,
gender: str,
dob: str,
address: Address,
request_options: typing.Optional[RequestOptions] = None,
) -> UserInfo:
"""
Parameters
----------
user_id : str
first_name : str
last_name : str
email : str
phone_number : str
gender : str
dob : str
address : Address
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
UserInfo
Successful Response
Examples
--------
from vital import Address, Vital
client = Vital(
api_key="YOUR_API_KEY",
)
client.user.upsert_user_info(
user_id="user_id",
first_name="first_name",
last_name="last_name",
email="email",
phone_number="phone_number",
gender="gender",
dob="dob",
address=Address(
first_line="first_line",
country="country",
zip="zip",
city="city",
state="state",
),
)
"""
_response = self._client_wrapper.httpx_client.request(
f"v2/user/{jsonable_encoder(user_id)}/info",
method="PATCH",
json={
"first_name": first_name,
"last_name": last_name,
"email": email,
"phone_number": phone_number,
"gender": gender,
"dob": dob,
"address": address,
},
request_options=request_options,
omit=OMIT,
)
try:
if 200 <= _response.status_code < 300:
return typing.cast(
UserInfo,
parse_obj_as(
type_=UserInfo, # type: ignore
object_=_response.json(),
),
)
if _response.status_code == 422:
raise UnprocessableEntityError(
typing.cast(
HttpValidationError,
parse_obj_as(
type_=HttpValidationError, # type: ignore
object_=_response.json(),
),
)
)
_response_json = _response.json()
except JSONDecodeError:
raise ApiError(status_code=_response.status_code, body=_response.text)
raise ApiError(status_code=_response.status_code, body=_response_json)
def get_by_client_user_id(
self, client_user_id: str, *, request_options: typing.Optional[RequestOptions] = None
) -> ClientFacingUser:
"""
GET user_id from client_user_id.
Parameters
----------
client_user_id : str
A unique ID representing the end user. Typically this will be a user ID number from your application. Personally identifiable information, such as an email address or phone number, should not be used in the client_user_id.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
ClientFacingUser
Successful Response
Examples
--------
from vital import Vital
client = Vital(
api_key="YOUR_API_KEY",
)
client.user.get_by_client_user_id(
client_user_id="client_user_id",
)
"""
_response = self._client_wrapper.httpx_client.request(
f"v2/user/resolve/{jsonable_encoder(client_user_id)}",
method="GET",
request_options=request_options,
)
try:
if 200 <= _response.status_code < 300:
return typing.cast(
ClientFacingUser,
parse_obj_as(
type_=ClientFacingUser, # type: ignore
object_=_response.json(),
),
)
if _response.status_code == 422:
raise UnprocessableEntityError(
typing.cast(
HttpValidationError,
parse_obj_as(
type_=HttpValidationError, # type: ignore
object_=_response.json(),
),
)
)
_response_json = _response.json()
except JSONDecodeError:
raise ApiError(status_code=_response.status_code, body=_response.text)
raise ApiError(status_code=_response.status_code, body=_response_json)
def deregister_provider(
self, user_id: str, provider: Providers, *, request_options: typing.Optional[RequestOptions] = None
) -> UserSuccessResponse:
"""
Parameters
----------
user_id : str
provider : Providers
Provider slug. e.g., `oura`, `fitbit`, `garmin`.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
UserSuccessResponse
Successful Response
Examples
--------
from vital import Providers, Vital
client = Vital(
api_key="YOUR_API_KEY",
)
client.user.deregister_provider(
user_id="user_id",
provider=Providers.OURA,
)
"""
_response = self._client_wrapper.httpx_client.request(
f"v2/user/{jsonable_encoder(user_id)}/{jsonable_encoder(provider)}",
method="DELETE",
request_options=request_options,
)
try:
if 200 <= _response.status_code < 300:
return typing.cast(
UserSuccessResponse,
parse_obj_as(
type_=UserSuccessResponse, # type: ignore
object_=_response.json(),
),
)
if _response.status_code == 422:
raise UnprocessableEntityError(
typing.cast(
HttpValidationError,
parse_obj_as(
type_=HttpValidationError, # type: ignore
object_=_response.json(),
),
)
)
_response_json = _response.json()
except JSONDecodeError:
raise ApiError(status_code=_response.status_code, body=_response.text)
raise ApiError(status_code=_response.status_code, body=_response_json)
def undo_delete(
self,
*,