File tree Expand file tree Collapse file tree 3 files changed +42
-33
lines changed
Expand file tree Collapse file tree 3 files changed +42
-33
lines changed Original file line number Diff line number Diff line change 1+ class WorkOSBaseResource (object ):
2+ """Representation of a WorkOS Resource as returned through the API.
3+
4+ Attributes:
5+ OBJECT_FIELDS (list): List of fields a Resource is comprised of.
6+ """
7+
8+ OBJECT_FIELDS = []
9+
10+ @classmethod
11+ def construct_from_response (cls , response ):
12+ """Returns an instance of WorkOSBaseResource.
13+
14+ Args:
15+ response (dict): Resource data from a WorkOS API response
16+
17+ Returns:
18+ WorkOSBaseResource: Instance of a WorkOSBaseResource with OBJECT_FIELDS fields set
19+ """
20+ print (response )
21+ obj = cls ()
22+ for field in cls .OBJECT_FIELDS :
23+ setattr (obj , field , response [field ])
24+
25+ return obj
26+
27+ def to_dict (self ):
28+ """Returns a dict representation of the WorkOSBaseResource.
29+
30+ Returns:
31+ dict: A dict representation of the WorkOSBaseResource
32+ """
33+ obj_dict = {}
34+ for field in self .OBJECT_FIELDS :
35+ obj_dict [field ] = getattr (self , field , None )
36+
37+ return obj_dict
Original file line number Diff line number Diff line change 1- class WorkOSProfile (object ):
1+ from workos .resources .base import WorkOSBaseResource
2+
3+ class WorkOSProfile (WorkOSBaseResource ):
24 """Representation of a User Profile as returned by WorkOS through the SSO feature.
35
46 Attributes:
@@ -12,34 +14,4 @@ class WorkOSProfile(object):
1214 "last_name" ,
1315 "connection_type" ,
1416 "idp_id" ,
15- ]
16-
17- @classmethod
18- def construct_from_response (cls , response ):
19- """Returns an instance of WorkOSProfile.
20-
21- Args:
22- response (dict): Response from a WorkOS API request as returned by RequestHelper
23-
24- Returns:
25- WorkOSProfile: The WorkOS profile of a User
26- """
27- profile_data = response ["profile" ]
28-
29- profile = cls ()
30- for field in WorkOSProfile .OBJECT_FIELDS :
31- setattr (profile , field , profile_data [field ])
32-
33- return profile
34-
35- def to_dict (self ):
36- """Returns a dict representation of the WorkOSProfile.
37-
38- Returns:
39- dict: A dict representation of the WorkOSProfile
40- """
41- profile_dict = {}
42- for field in WorkOSProfile .OBJECT_FIELDS :
43- profile_dict [field ] = getattr (self , field , None )
44-
45- return profile_dict
17+ ]
Original file line number Diff line number Diff line change @@ -100,7 +100,7 @@ def get_profile(self, code):
100100 TOKEN_PATH , method = REQUEST_METHOD_POST , params = params
101101 )
102102
103- return WorkOSProfile .construct_from_response (response )
103+ return WorkOSProfile .construct_from_response (response [ "profile" ] )
104104
105105 def promote_draft_connection (self , token ):
106106 """Promote a Draft Connection
You can’t perform that action at this time.
0 commit comments