forked from sendgrid/sendgrid-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi_keys.py
More file actions
63 lines (51 loc) · 1.72 KB
/
api_keys.py
File metadata and controls
63 lines (51 loc) · 1.72 KB
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
class APIKeys(object):
"""The API Keys feature allows customers to be able to generate an API Key credential
which can be used for authentication with the SendGrid v3 Web API or the Mail API Endpoint"""
def __init__(self, client, **opts):
"""
Constructs SendGrid APIKeys object.
See https://sendgrid.com/docs/API_Reference/Web_API_v3/API_Keys/index.html
"""
self._name = None
self._base_endpoint = "/v3/api_keys"
self._endpoint = "/v3/api_keys"
self._client = client
@property
def name(self):
return self._name
@name.setter
def name(self, value):
self._name = value
@property
def base_endpoint(self):
return self._base_endpoint
@property
def endpoint(self):
endpoint = self._endpoint
return endpoint
@endpoint.setter
def endpoint(self, value):
self._endpoint = value
@property
def client(self):
return self._client
# Get a list of active API keys
def get(self):
return self.client.get(self)
# Create a new API key with name (string)
def post(self, name):
data = {}
self.name = name
data['name'] = self.name
return self.client.post(self, data)
# Delete a API key
def delete(self, api_key_id):
self.endpoint = self._base_endpoint + "/" + api_key_id
return self.client.delete(self)
# Update a API key's name
def patch(self, api_key_id, name):
data = {}
self.name = name
data['name'] = self.name
self.endpoint = self._base_endpoint + "/" + api_key_id
return self.client.patch(self, data)