1- from typing import (
2- Any ,
3- )
1+ from typing import Any
42
53from easypost .constant import NO_USER_FOUND
64from easypost .easypost_object import convert_to_easypost_object
75from easypost .errors import FilteringError
86from easypost .models import ApiKey
9- from easypost .requestor import (
10- RequestMethod ,
11- Requestor ,
12- )
7+ from easypost .requestor import RequestMethod , Requestor
138from easypost .services .base_service import BaseService
149
1510
@@ -18,14 +13,6 @@ def __init__(self, client):
1813 self ._client = client
1914 self ._model_class = ApiKey .__name__
2015
21- def all (self ) -> dict [str , Any ]:
22- """Retrieve a list of all API keys."""
23- url = "/api_keys"
24-
25- response = Requestor (self ._client ).request (method = RequestMethod .GET , url = url )
26-
27- return convert_to_easypost_object (response = response )
28-
2916 def retrieve_api_keys_for_user (self , id : str ) -> list [ApiKey ]:
3017 """Retrieve a list of API keys (works for the authenticated User or a child User)."""
3118 api_keys = self .all ()
@@ -41,3 +28,40 @@ def retrieve_api_keys_for_user(self, id: str) -> list[ApiKey]:
4128 return child .keys
4229
4330 raise FilteringError (message = NO_USER_FOUND )
31+
32+ def all (self ) -> dict [str , Any ]:
33+ """Retrieve a list of all API keys."""
34+ url = "/api_keys"
35+
36+ response = Requestor (self ._client ).request (method = RequestMethod .GET , url = url )
37+
38+ return convert_to_easypost_object (response = response )
39+
40+ def create (self , mode : str ) -> ApiKey :
41+ """Create an API key for a child or referral customer user."""
42+ url = "/api_keys"
43+ params = {"mode" : mode }
44+
45+ response = Requestor (self ._client ).request (method = RequestMethod .POST , url = url , params = params )
46+
47+ return convert_to_easypost_object (response = response )
48+
49+ def delete (self , id : str ) -> None :
50+ """Delete an API key for a child or referral customer user."""
51+ self ._delete_resource (self ._model_class , id )
52+
53+ def enable (self , id : str ) -> ApiKey :
54+ """Enable a child or referral customer API key."""
55+ url = f"/api_keys/{ id } /enable"
56+
57+ response = Requestor (self ._client ).request (method = RequestMethod .POST , url = url )
58+
59+ return convert_to_easypost_object (response = response )
60+
61+ def disable (self , id : str ) -> ApiKey :
62+ """Disable a child or referral customer API key."""
63+ url = f"/api_keys/{ id } /disable"
64+
65+ response = Requestor (self ._client ).request (method = RequestMethod .POST , url = url )
66+
67+ return convert_to_easypost_object (response = response )
0 commit comments