Skip to content

Commit

Permalink
Merge pull request #3 from drish/rename
Browse files Browse the repository at this point in the history
renamed to resend
  • Loading branch information
Derich Pacheco authored Jan 17, 2023
2 parents d3006f8 + f1564f7 commit 513f463
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 56 deletions.
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
# Klotty Python SDK
# Resend Python SDK

[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
![Build](https://github.com/drish/klotty-py/actions/workflows/test.yaml/badge.svg)
[![codecov](https://codecov.io/gh/drish/klotty-py/branch/main/graph/badge.svg?token=GGD39PPFM0)](https://codecov.io/gh/drish/klotty-py)
![Build](https://github.com/drish/resend-py/actions/workflows/test.yaml/badge.svg)
[![codecov](https://codecov.io/gh/drish/resend-py/branch/main/graph/badge.svg?token=GGD39PPFM0)](https://codecov.io/gh/drish/resend-py)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
[![PyPI](https://img.shields.io/pypi/v/klotty)](https://pypi.org/project/klotty/)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/klotty)](https://pypi.org/project/klotty)
[![PyPI](https://img.shields.io/pypi/v/resend)](https://pypi.org/project/resend/)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/resend)](https://pypi.org/project/resend)
---

## Installation

To install Klotty Python SDK, simply execute the following command in a terminal:
To install Resend Python SDK, simply execute the following command in a terminal:

```
pip install klotty
pip install resend
```

## Setup

First, you need to get an API key, which is available in the [Klotty Dashboard](https://klotty.com).
First, you need to get an API key, which is available in the [Resend Dashboard](https://resend.com).

```py
from klotty import Klotty
from resend import Resend

client = Klotty(api_key="kl_123")
client = Resend(api_key="kl_123")
```

## Example

```py
from klotty import Klotty
from resend import Resend

client = Klotty(api_key=os.environ["KLOTTY_API_KEY"])
client = Resend(api_key=os.environ["RESEND_API_KEY"])

client.send_email(
to="[email protected]",
Expand Down
4 changes: 0 additions & 4 deletions klotty/__init__.py

This file was deleted.

4 changes: 4 additions & 0 deletions resend/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from .api import Resend
from .version import get_version

__all__ = ["get_version", "Resend"]
10 changes: 5 additions & 5 deletions klotty/api.py → resend/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@

import requests

from klotty.exceptions import raise_for_code_and_type
from resend.exceptions import raise_for_code_and_type

from .version import get_version


class Klotty:
"""Klotty SDK main client class
class Resend:
"""Resend SDK main client class
Raises:
ValueError: raises ValueError when api key is
"""

base_url: str = "https://api.klotty.com"
base_url: str = "https://api.resend.com"
timeout_ms: int = 60_000

def __init__(self, api_key: str):
if not api_key:
raise ValueError("Klotty API Key is required.")
raise ValueError("Resend API Key is required.")
self.__api_key = api_key

def __get_headers(self) -> Dict:
Expand Down
38 changes: 19 additions & 19 deletions klotty/exceptions.py → resend/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
"""Klotty Exceptions module.
"""Resend Exceptions module.
This module defines the base types for platform-wide error
codes as outlined in https://klotty.com/docs/errors.
codes as outlined in https://resend.com/docs/errors.
"""


from typing import Dict


class KlottyError(Exception):
"""Base class for all errors raised by Klotty SDK.
class ResendError(Exception):
"""Base class for all errors raised by Resend SDK.
This is the parent class of all exceptions (server side)
raised by the Klotty SDK. Developers can simply catch
raised by the Resend SDK. Developers can simply catch
this class and inspect its `code` to implement more specific
error handling. Note that for some client-side errors ie:
some method argument missing, a ValueError would be raised.
Expand All @@ -21,7 +21,7 @@ class KlottyError(Exception):
attributed to that Error.
message: A human-readable error message string.
suggested_action: A suggested action path to help the user.
error_type: Maps to the `type` field from the Klotty API
error_type: Maps to the `type` field from the Resend API
"""

def __init__(
Expand All @@ -37,8 +37,8 @@ def __init__(
self.error_type = error_type


class MissingApiKeyError(KlottyError):
"""see https://klotty.com/docs/errors"""
class MissingApiKeyError(ResendError):
"""see https://resend.com/docs/errors"""

def __init__(
self,
Expand All @@ -49,7 +49,7 @@ def __init__(
suggested_action = """Include the following header
Authorization: Bearer YOUR_API_KEY in the request."""

KlottyError.__init__(
ResendError.__init__(
self,
message="Missing API key in the authorization header.",
suggested_action=suggested_action,
Expand All @@ -58,8 +58,8 @@ def __init__(
)


class InvalidApiKeyError(KlottyError):
"""see https://klotty.com/docs/errors"""
class InvalidApiKeyError(ResendError):
"""see https://resend.com/docs/errors"""

def __init__(
self,
Expand All @@ -69,7 +69,7 @@ def __init__(
):
suggested_action = """Generate a new API key in the dashboard."""

KlottyError.__init__(
ResendError.__init__(
self,
message=message,
suggested_action=suggested_action,
Expand All @@ -78,8 +78,8 @@ def __init__(
)


class MissingRequiredFieldsError(KlottyError):
"""see https://klotty.com/docs/errors"""
class MissingRequiredFieldsError(ResendError):
"""see https://resend.com/docs/errors"""

def __init__(
self,
Expand All @@ -96,7 +96,7 @@ def __init__(
if message != "":
message = default_message

KlottyError.__init__(
ResendError.__init__(
self,
code=code or 422,
message=message,
Expand All @@ -105,19 +105,19 @@ def __init__(
)


ERRORS: Dict[str, Dict[str, KlottyError]] = {
ERRORS: Dict[str, Dict[str, ResendError]] = {
"422": {"missing_required_fields": MissingRequiredFieldsError},
"401": {"missing_api_key": MissingApiKeyError},
"403": {"invalid_api_key": InvalidApiKeyError},
}


def raise_for_code_and_type(code, error_type, message: str) -> KlottyError:
def raise_for_code_and_type(code, error_type, message: str) -> ResendError:

# Handle the case where the error might be unknown
if ERRORS.get(code).get(error_type) is None:
raise KlottyError()
raise ResendError()

# Raise error from errors list
error: KlottyError = ERRORS.get(code).get(error_type)
error: ResendError = ERRORS.get(code).get(error_type)
raise error(code=code, message=message, error_type=error_type)
File renamed without changes.
File renamed without changes.
10 changes: 5 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@

from setuptools import setup

from klotty.version import get_version
from resend.version import get_version

install_requires = open("requirements.txt").readlines()

setup(
name="klotty",
name="resend",
version=get_version(),
description="Klotty Python SDK",
description="Resend Python SDK",
long_description=open("README.md", encoding="utf8").read(),
long_description_content_type="text/markdown",
author="Derich Pacheco",
author_email="[email protected]",
url="https://github.com/drish/klotty-py",
packages=["klotty"],
url="https://github.com/drish/resend-py",
packages=["resend"],
include_package_data=True,
install_requires=install_requires,
zip_safe=False,
Expand Down
18 changes: 9 additions & 9 deletions tests/api_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@

import pytest

from klotty import Klotty
from klotty.exceptions import MissingRequiredFieldsError
from resend import Resend
from resend.exceptions import MissingRequiredFieldsError


class TestKlotty(unittest.TestCase):
class TestResend(unittest.TestCase):
def test_invalid_api_key(self):
with pytest.raises(ValueError):
Klotty(api_key="")
Resend(api_key="")

def test_invalid_send_email_args(self):
with pytest.raises(ValueError):
client = Klotty(api_key="kl_123")
client = Resend(api_key="kl_123")
client.send_email(
sender="",
to="[email protected]",
Expand All @@ -23,7 +23,7 @@ def test_invalid_send_email_args(self):
)

with pytest.raises(ValueError):
client = Klotty(api_key="kl_123")
client = Resend(api_key="kl_123")
client.send_email(
sender="[email protected]",
to="",
Expand All @@ -32,7 +32,7 @@ def test_invalid_send_email_args(self):
)

with pytest.raises(ValueError):
client = Klotty(api_key="kl_123")
client = Resend(api_key="kl_123")
client.send_email(
sender="[email protected]",
to="[email protected]",
Expand All @@ -41,7 +41,7 @@ def test_invalid_send_email_args(self):
)

def test_request_missing_fields(self):
patcher = patch("klotty.Klotty._make_request")
patcher = patch("resend.Resend._make_request")
mock = patcher.start()
mock.status_code = 422
m = MagicMock()
Expand All @@ -60,7 +60,7 @@ def mock_json():
mock.return_value = m

with pytest.raises(MissingRequiredFieldsError) as e:
client = Klotty(api_key="kl_123")
client = Resend(api_key="kl_123")
client.send_email(
to="[email protected]",
sender="[email protected]",
Expand Down
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ deps =
{[base]deps}

commands =
pytest --cov=klotty --cov-report=xml \
pytest --cov=resend --cov-report=xml \
--doctest-modules \
{posargs:tests}

Expand All @@ -46,4 +46,4 @@ deps =
pep8-naming

commands =
flake8 klotty/ tests/
flake8 resend/ tests/

0 comments on commit 513f463

Please sign in to comment.