-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
281 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,9 +7,6 @@ | |
|
||
|
||
class ApiKeys: | ||
""" | ||
Api Keys module | ||
""" | ||
|
||
class CreateApiKeyRequestParams(TypedDict): | ||
name: str | ||
|
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
from typing import List | ||
from resend.domains._record import Record | ||
|
||
|
||
class Domain: | ||
id: str | ||
""" | ||
The domain ID | ||
""" | ||
name: str | ||
""" | ||
The domain name | ||
""" | ||
created_at: str | ||
""" | ||
When domain was created | ||
""" | ||
status: str | ||
""" | ||
Status of the domain: not_started, etc.. | ||
""" | ||
region: str | ||
""" | ||
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] | ||
""" | ||
The list of domain records | ||
""" | ||
deleted: bool | ||
""" | ||
Wether the domain is deleted or not | ||
""" | ||
|
||
def __init__( | ||
self, id, name, region, created_at, | ||
status, records, deleted=False): | ||
self.id = id | ||
self.name = name | ||
self.created_at = created_at | ||
self.status = status | ||
self.region = region | ||
self.records = records | ||
self.deleted = deleted | ||
|
||
@staticmethod | ||
def new_from_request(val) -> "Domain": | ||
domain = Domain( | ||
id=val["id"] if "id" in val else None, | ||
name=val["name"] if "name" in val else None, | ||
region=val["region"] if "region" in val else None, | ||
created_at=val["created_at"] if "created_at" in val else None, | ||
status=val["status"] if "status" in val else None, | ||
records = [Record.new_from_request(record) for record in val["records"]] if "records" in val else None, | ||
deleted=val["deleted"] if "deleted" in val else None, | ||
) | ||
return domain |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
from typing import List, Any, Dict, Optional, cast | ||
|
||
from typing_extensions import TypedDict | ||
from resend import request | ||
from resend.domains._domain import Domain | ||
|
||
class Domains: | ||
|
||
class UpdateDomainRequestParams(TypedDict): | ||
id: str | ||
""" | ||
The domain ID. | ||
""" | ||
click_tracking: bool | ||
""" | ||
Track clicks within the body of each HTML email. | ||
""" | ||
open_tracking: bool | ||
""" | ||
Track the open rate of each email. | ||
""" | ||
|
||
class CreateDomainRequestParams(TypedDict): | ||
name: str | ||
""" | ||
The domain name. | ||
""" | ||
region: str | ||
""" | ||
The region where emails will be sent from. | ||
Possible values: us-east-1' | 'eu-west-1' | 'sa-east-1' | 'ap-northeast-1' | ||
""" | ||
|
||
@classmethod | ||
def create(cls, params: CreateDomainRequestParams = {}) -> Domain: | ||
""" | ||
Create a domain through the Resend Email API. | ||
see more: https://resend.com/docs/api-reference/domains/create-domain | ||
""" | ||
path = "/domains" | ||
return Domain.new_from_request( | ||
request.Request( | ||
path=path, params=cast(Dict[Any, Any], params), verb="post" | ||
).perform() | ||
) | ||
|
||
@classmethod | ||
def update(cls, params: UpdateDomainRequestParams = {}) -> Domain: | ||
""" | ||
Update an existing domain. | ||
see more: https://resend.com/docs/api-reference/domains/update-domain | ||
""" | ||
path = f"/domains/{params['id']}" | ||
return Domain.new_from_request( | ||
request.Request(path=path, params=params, verb="patch").perform() | ||
) | ||
|
||
@classmethod | ||
def get(cls, domain_id: str = "") -> Domain: | ||
""" | ||
Retrieve a single domain for the authenticated user. | ||
see more: https://resend.com/docs/api-reference/domains/get-domain | ||
""" | ||
path = f"/domains/{domain_id}" | ||
return Domain.new_from_request( | ||
request.Request(path=path, params={}, verb="get").perform() | ||
) | ||
|
||
@classmethod | ||
def list(cls) -> List[Domain]: | ||
""" | ||
Retrieve a list of domains for the authenticated user. | ||
see more: https://resend.com/docs/api-reference/domains/list-domains | ||
""" | ||
path = "/domains" | ||
resp = request.Request(path=path, params={}, verb="get").perform() | ||
return [Domain.new_from_request(val) for val in resp['data']] | ||
|
||
@classmethod | ||
def remove(cls, domain_id: str = "") -> Domain: | ||
""" | ||
Remove an existing domain. | ||
see more: https://resend.com/docs/api-reference/domains/remove-domain | ||
""" | ||
path = f"/domains/{domain_id}" | ||
return Domain.new_from_request( | ||
request.Request(path=path, params={}, verb="delete").perform() | ||
) | ||
|
||
@classmethod | ||
def verify(cls, domain_id: str = "" ) -> Domain: | ||
""" | ||
Verify an existing domain. | ||
see more: https://resend.com/docs/api-reference/domains/verify-domain | ||
""" | ||
path = f"/domains/{domain_id}/verify" | ||
return Domain.new_from_request( | ||
request.Request(path=path, params={}, verb="post").perform() | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
class Record: | ||
record: str | ||
""" | ||
The domain record type, ie: SPF. | ||
""" | ||
name: str | ||
""" | ||
The domain record name. | ||
""" | ||
type: str | ||
""" | ||
The domain record type, ie: MX. | ||
""" | ||
ttl: str | ||
""" | ||
The domain record time to live. | ||
""" | ||
status: str | ||
""" | ||
The domain record status: not_started, etc.. | ||
""" | ||
value: str | ||
""" | ||
The domain record value. | ||
""" | ||
priority: int | ||
""" | ||
The domain record priority. | ||
""" | ||
|
||
def __init__( | ||
self, record, name, type, ttl, | ||
status, value, priority): | ||
self.record = record | ||
self.name = name | ||
self.type = type | ||
self.ttl = ttl | ||
self.status = status | ||
self.value = value | ||
self.priority = priority | ||
|
||
@staticmethod | ||
def new_from_request(val) -> "Record": | ||
return Record( | ||
record=val["record"] if "record" in val else None, | ||
name=val["name"] if "name" in val else None, | ||
type=val["type"] if "type" in val else None, | ||
ttl=val["ttl"] if "ttl" in val else None, | ||
status=val["status"] if "status" in val else None, | ||
value=val["value"] if "value" in val else None, | ||
priority=val["priority"] if "priority" in val else None, | ||
) |
Oops, something went wrong.