mirror of
https://github.com/kennethreitz/neon-api-python.git
synced 2026-06-05 22:50:18 +00:00
Refactor APIKey and Branch classes
This commit is contained in:
+18
-14
@@ -77,19 +77,19 @@ class APIKey(NeonResource):
|
|||||||
def list(cls, client):
|
def list(cls, client):
|
||||||
"""Get a list of API keys."""
|
"""Get a list of API keys."""
|
||||||
|
|
||||||
r = client.request("GET", "api_keys")
|
obj = client.request("GET", "api_keys")
|
||||||
return [
|
return [
|
||||||
cls(client=client, obj=x, data_model=schema.ApiKeysListResponseItem)
|
cls(client=client, obj=obj, data_model=schema.ApiKeysListResponseItem)
|
||||||
for x in r
|
for obj in obj
|
||||||
]
|
]
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def revoke_request(cls, client, api_key):
|
def revoke_request(cls, client, api_key):
|
||||||
"""Revoke an API key, via object instance."""
|
"""Revoke an API key, via object instance."""
|
||||||
|
|
||||||
r = client.request("DELETE", f"api_keys/{ api_key.obj.id }")
|
obj = client.request("DELETE", f"api_keys/{ api_key.obj.id }")
|
||||||
|
|
||||||
return cls(client=client, obj=r, data_model=schema.ApiKeyRevokeResponse)
|
return cls(client=client, obj=obj, data_model=schema.ApiKeyRevokeResponse)
|
||||||
|
|
||||||
def revoke(self):
|
def revoke(self):
|
||||||
"""Revoke the API key."""
|
"""Revoke the API key."""
|
||||||
@@ -225,18 +225,22 @@ class Branch(NeonResource):
|
|||||||
|
|
||||||
return cls(client=client, obj=r, data_model=schema.BranchResponse)
|
return cls(client=client, obj=r, data_model=schema.BranchResponse)
|
||||||
|
|
||||||
# @classmethod
|
@classmethod
|
||||||
# def get_connection_string(cls, client, project_id: str, branch_id: str):
|
def get_connection_string(cls, client, project_id: str, branch_id: str):
|
||||||
# """Get a connection string for a branch."""
|
"""Get a connection string for a branch."""
|
||||||
|
|
||||||
# # Construct the request path.
|
# Construct the request path.
|
||||||
# r_path = client.url_join("projects", project_id, "branches", branch_id, "connection_string")
|
r_path = client.url_join(
|
||||||
|
"projects", project_id, "branches", branch_id, "connection_string"
|
||||||
|
)
|
||||||
|
|
||||||
# # Make the request.
|
# Make the request.
|
||||||
# obj = client.request("GET", r_path, response_model=schema.BranchConnectionStringResponse)
|
obj = client.request(
|
||||||
|
"GET", r_path, response_model=schema.BranchConnectionStringResponse
|
||||||
|
)
|
||||||
|
|
||||||
# # Deserialize the response.
|
# Deserialize the response.
|
||||||
# return obj.connection_string
|
return obj.connection_string
|
||||||
|
|
||||||
|
|
||||||
class Operation(NeonResource):
|
class Operation(NeonResource):
|
||||||
|
|||||||
Reference in New Issue
Block a user