Skip to content

Commit

Permalink
fixing small types (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
pedroimpulcetto authored Apr 22, 2024
1 parent ce11336 commit 7245692
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 35 deletions.
5 changes: 4 additions & 1 deletion resend/api_keys/_api_key.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from typing import Any, Dict


class ApiKey:
id: str
"""
Expand All @@ -23,7 +26,7 @@ def __init__(self, id: str, token: str, name: str, created_at: str):
self.created_at = created_at

@staticmethod
def new_from_request(val) -> "ApiKey":
def new_from_request(val: Dict[Any, Any]) -> "ApiKey":
"""Creates a new ApiKey object from the
JSON response from the API.
Expand Down
7 changes: 5 additions & 2 deletions resend/audiences/_audience.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from typing import Any, Dict


class Audience:
id: str
"""
Expand All @@ -16,14 +19,14 @@ class Audience:
Wether the audience was deleted. Only returned on the "remove" call
"""

def __init__(self, id, name, created_at, deleted=False):
def __init__(self, id: str, name: str, created_at: str, deleted: bool = False):
self.id = id
self.name = name
self.created_at = created_at
self.deleted = deleted

@staticmethod
def new_from_request(val) -> "Audience":
def new_from_request(val: Dict[Any, Any]) -> "Audience":
"""Creates a new Audience object from the
JSON response from the API.
Expand Down
5 changes: 4 additions & 1 deletion resend/contacts/_contact.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from typing import Any, Dict


class Contact:
id: str
"""
Expand Down Expand Up @@ -47,7 +50,7 @@ def __init__(
self.deleted = deleted

@staticmethod
def new_from_request(val) -> "Contact":
def new_from_request(val: Dict[Any, Any]) -> "Contact":
"""Creates a new Contact object from the
JSON response from the API.
Expand Down
5 changes: 4 additions & 1 deletion resend/contacts/_contacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ def list(cls, audience_id: str) -> List[Contact]:
List all contacts for the provided audience.
see more: https://resend.com/docs/api-reference/contacts/list-contacts
Args:
audience_id (str): The audience ID
Returns:
List[Contact]: A list of contact objects
"""
Expand All @@ -112,7 +115,7 @@ def list(cls, audience_id: str) -> List[Contact]:
)

@classmethod
def get(cls, id, audience_id: str) -> Contact:
def get(cls, id: str, audience_id: str) -> Contact:
"""
Get a contact.
see more: https://resend.com/docs/api-reference/contacts/get-contact
Expand Down
19 changes: 14 additions & 5 deletions resend/domains/_domain.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import List
from typing import Any, Dict, List, Union

from resend.domains._record import Record

Expand All @@ -24,7 +24,7 @@ class Domain:
"""
The region where emails will be sent from. Possible values: us-east-1' | 'eu-west-1' | 'sa-east-1' | 'ap-northeast-1'
"""
records: List[Record]
records: Union[List[Record], None]
"""
The list of domain records
"""
Expand All @@ -33,17 +33,26 @@ class Domain:
Wether the domain is deleted or not
"""

def __init__(self, id, name, region, created_at, status, records, deleted=False):
def __init__(
self,
id: str,
name: str,
region: str,
created_at: str,
status: str,
records: Union[List[Record], None],
deleted: bool = False,
):
self.id = id
self.name = name
self.region = region
self.created_at = created_at
self.status = status
self.region = region
self.records = records
self.deleted = deleted

@staticmethod
def new_from_request(val) -> "Domain":
def new_from_request(val: Dict[Any, Any]) -> "Domain":
"""Creates a new Domain object from the
JSON response from the API.
Expand Down
16 changes: 14 additions & 2 deletions resend/domains/_record.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from typing import Any, Dict


class Record:
record: str
"""
Expand Down Expand Up @@ -28,7 +31,16 @@ class Record:
The domain record priority.
"""

def __init__(self, record, name, type, ttl, status, value, priority):
def __init__(
self,
record: str,
name: str,
type: str,
ttl: str,
status: str,
value: str,
priority: int,
):
self.record = record
self.name = name
self.type = type
Expand All @@ -38,7 +50,7 @@ def __init__(self, record, name, type, ttl, status, value, priority):
self.priority = priority

@staticmethod
def new_from_request(val) -> "Record":
def new_from_request(val: Dict[Any, Any]) -> "Record":
return Record(
record=val["record"] if "record" in val else None,
name=val["name"] if "name" in val else None,
Expand Down
26 changes: 13 additions & 13 deletions resend/emails/_email.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import List, Union
from typing import Any, Dict, List, Union


class Email:
Expand Down Expand Up @@ -50,17 +50,17 @@ class Email:

def __init__(
self,
id,
to,
sender,
created_at,
subject,
html,
text,
bcc,
cc,
reply_to,
last_event,
id: str,
to: Union[List[str], str],
sender: str,
created_at: str,
subject: str,
html: str,
text: str,
bcc: Union[List[str], str],
cc: Union[List[str], str],
reply_to: Union[List[str], str],
last_event: str,
):
self.id = id
self.to = to
Expand All @@ -75,7 +75,7 @@ def __init__(
self.last_event = last_event

@staticmethod
def new_from_request(val) -> "Email":
def new_from_request(val: Dict[Any, Any]) -> "Email":
"""Creates a new Email object from the
JSON response from the API.
Expand Down
18 changes: 9 additions & 9 deletions resend/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ class MissingRequiredFieldsError(ResendError):

def __init__(
self,
message,
error_type,
code,
message: str,
error_type: str,
code: str,
):
default_message = """
The request body is missing one or more required fields."""
Expand All @@ -127,7 +127,7 @@ def __init__(

ResendError.__init__(
self,
code=code or 422,
code=code or "422",
message=message,
suggested_action=suggested_action,
error_type=error_type,
Expand All @@ -139,9 +139,9 @@ class ApplicationError(ResendError):

def __init__(
self,
message,
error_type,
code,
message: str,
error_type: str,
code: str,
):
default_message = """
Something went wrong."""
Expand All @@ -153,7 +153,7 @@ def __init__(

ResendError.__init__(
self,
code=code or 500,
code=code or "500",
message=message,
suggested_action=suggested_action,
error_type=error_type,
Expand All @@ -170,7 +170,7 @@ def __init__(
}


def raise_for_code_and_type(code: str, error_type: str, message: str) -> ResendError:
def raise_for_code_and_type(code: str, error_type: str, message: str) -> None:
"""Raise the appropriate error based on the code and type.
Args:
Expand Down
2 changes: 1 addition & 1 deletion resend/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def __get_headers(self) -> Dict:
"User-Agent": f"resend-python:{get_version()}",
}

def make_request(self, url: str):
def make_request(self, url: str) -> requests.Response:
"""make_request is a helper function that makes the actual
HTTP request to the Resend API.
Expand Down

0 comments on commit 7245692

Please sign in to comment.