Skip to content

Commit b60d3e7

Browse files
committed
Release 1.0.0: Add DomainType support and update create_email logic
1 parent 3d172a4 commit b60d3e7

File tree

4 files changed

+27
-5
lines changed

4 files changed

+27
-5
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ email = client.create_email(domain="example.com")
8282
email = client.create_email(email="[email protected]")
8383

8484
# Create with domain type preference
85-
email = client.create_email(domain_type="premium")
85+
from tempmail.models import DomainType
86+
email = client.create_email(domain_type=DomainType.PREMIUM)
8687
```
8788

8889
### Listing Domains

tempmail/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Official Temp Mail API (https://temp-mail.io) Wrapper for Python.
33
"""
44

5-
__version__ = "1.0.0b2"
5+
__version__ = "1.0.0"
66

77
from .client import TempMailClient
88
from .models import (

tempmail/client.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from .models import (
1010
RateLimit,
1111
Domain,
12+
DomainType,
1213
EmailAddress,
1314
EmailMessage,
1415
APIErrorResponse,
@@ -107,21 +108,21 @@ def create_email(
107108
self,
108109
email: Optional[str] = None,
109110
domain: Optional[str] = None,
110-
domain_type: Optional[str] = None,
111+
domain_type: Optional[DomainType] = None,
111112
) -> EmailAddress:
112113
"""
113114
Create a new temporary email address.
114115
:param email: Optional specific email address to create
115116
:param domain: Optional domain to use
116-
:param domain_type: Optional domain type (e.g., "public", "custom", "premium")
117+
:param domain_type: an Optional domain type
117118
"""
118119
json_data: Dict[str, Any] = {}
119120
if email:
120121
json_data["email"] = email
121122
if domain:
122123
json_data["domain"] = domain
123124
if domain_type:
124-
json_data["domain_type"] = domain_type
125+
json_data["domain_type"] = domain_type.value
125126

126127
data = self._make_request(
127128
"POST", "/v1/emails", json_data=json_data if json_data else None

tests/test_client.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,26 @@ def test_create_email_success(self, mock_request) -> None:
4949
email: EmailAddress = client.create_email()
5050
assert email == EmailAddress(email="[email protected]", ttl=86400)
5151

52+
@patch("tempmail.client.requests.Session.request")
53+
def test_create_email_premium_domain_type(self, mock_request) -> None:
54+
mock_response = Mock()
55+
mock_response.status_code = 200
56+
mock_response.json.return_value = {"email": "[email protected]", "ttl": 86400}
57+
mock_response.headers = self._rate_limit_headers
58+
mock_request.return_value = mock_response
59+
60+
client: TempMailClient = TempMailClient("test-api-key")
61+
email: EmailAddress = client.create_email(domain_type=DomainType.PREMIUM)
62+
assert email == EmailAddress(email="[email protected]", ttl=86400)
63+
64+
mock_request.assert_called_once_with(
65+
method="POST",
66+
url="https://api.temp-mail.io/v1/emails",
67+
params=None,
68+
json={"domain_type": "premium"},
69+
timeout=30,
70+
)
71+
5272
@patch("tempmail.client.requests.Session.request")
5373
def test_create_email_with_options(self, mock_request):
5474
mock_response = Mock()

0 commit comments

Comments
 (0)