1- from typing import Callable , List , Optional , TypedDict , Union
1+ from typing import Callable , List , Optional , TypedDict
22
33from typing_extensions import NotRequired , Required , Unpack
44
@@ -47,9 +47,9 @@ class Vanity(Resource):
4747 class VanityAttributes (TypedDict ):
4848 """Vanity attributes."""
4949
50- path : str
50+ path : Required [ str ]
5151 content_guid : Required [str ]
52- created_time : str
52+ created_time : Required [ str ]
5353
5454 def __init__ (
5555 self ,
@@ -123,7 +123,7 @@ class VanityMixin(Resource):
123123 class HasGuid (TypedDict ):
124124 """Has a guid."""
125125
126- guid : str
126+ guid : Required [ str ]
127127
128128 def __init__ (self , / , params : ResourceParameters , ** kwargs : Unpack [HasGuid ]):
129129 super ().__init__ (params , ** kwargs )
@@ -135,38 +135,38 @@ def _endpoint(self):
135135 return self .params .url + f"v1/content/{ self ._content_guid } /vanity"
136136
137137 @property
138- def vanity (self ) -> Optional [Vanity ]:
138+ def vanity (self ) -> Optional [str ]:
139139 """Get the vanity."""
140140 if self ._vanity :
141- return self ._vanity
141+ return self ._vanity [ "path" ]
142142
143143 try :
144144 self ._vanity = self .find_vanity ()
145- self ._vanity ._after_destroy = self .reset_vanity
146- return self ._vanity
145+ return self ._vanity ["path" ]
147146 except ClientError as e :
148147 if e .http_status == 404 :
149148 return None
150149 raise e
151150
152151 @vanity .setter
153- def vanity (self , value : Union [ str , "CreateVanityRequest" ] ) -> None :
152+ def vanity (self , value : str ) -> None :
154153 """Set the vanity.
155154
156155 Parameters
157156 ----------
158- value : str or CreateVanityRequest
159- The value can be a str or a CreateVanityRequest. If provided as a string, it is the vanity path.
157+ value : str
158+ The vanity path.
159+
160+ Note
161+ ----
162+ This action requires owner or administrator privileges.
160163
161164 See Also
162165 --------
163166 create_vanity
164167 """
165- if isinstance (value , str ):
166- self .create_vanity (path = value )
167- elif isinstance (value , dict ):
168- self .create_vanity (** value )
169- self .reset_vanity ()
168+ self ._vanity = self .create_vanity (path = value )
169+ self ._vanity ._after_destroy = self .reset_vanity
170170
171171 @vanity .deleter
172172 def vanity (self ) -> None :
@@ -178,7 +178,7 @@ def vanity(self) -> None:
178178
179179 Note
180180 ----
181- This action requires administrator privileges.
181+ This action requires owner or administrator privileges.
182182
183183 See Also
184184 --------
@@ -196,32 +196,39 @@ def reset_vanity(self) -> None:
196196 self ._vanity = None
197197
198198 class CreateVanityRequest (TypedDict , total = False ):
199- """A request schema for creating a vanity.
200-
201- Attributes
202- ----------
203- path : str
204- The path for the vanity.
205- force : bool
206- Whether to force the creation of the vanity.
207- """
199+ """A request schema for creating a vanity."""
208200
209201 path : Required [str ]
202+ """The vanity path (.e.g, 'my-dashboard')"""
203+
210204 force : NotRequired [bool ]
205+ """Whether to force creation of the vanity"""
211206
212- def create_vanity (self , ** kwargs : Unpack [CreateVanityRequest ]) -> None :
207+ def create_vanity (self , ** kwargs : Unpack [CreateVanityRequest ]) -> Vanity :
213208 """Create a vanity.
214209
215210 Parameters
216211 ----------
217212 path : str, required
218213 The path for the vanity.
219214 force : bool, not required
220- Whether to force the creation of the vanity, default False
215+ Whether to force the creation of the vanity. When True, any other vanity with the same path will be deleted.
216+
217+ Warnings
218+ --------
219+ If setting force=True, the destroy operation performed on the other vanity is irreversible.
221220 """
222- self .params .session .put (self ._endpoint , json = kwargs )
221+ response = self .params .session .put (self ._endpoint , json = kwargs )
222+ result = response .json ()
223+ return Vanity (self .params , ** result )
223224
224- def find_vanity (self ):
225+ def find_vanity (self ) -> Vanity :
226+ """Find the vanity.
227+
228+ Returns
229+ -------
230+ Vanity
231+ """
225232 response = self .params .session .get (self ._endpoint )
226233 result = response .json ()
227- return Vanity (self .params , ** result )
234+ return Vanity (self .params , after_destroy = self . reset_vanity , ** result )
0 commit comments