From 6e82c1e5cb41c2a91f13f96de2805ba8345901b3 Mon Sep 17 00:00:00 2001 From: Hellow <74311245+HeIIow2@users.noreply.github.com> Date: Tue, 12 Sep 2023 18:21:30 +0200 Subject: [PATCH] feat: added contact collection in the artist --- src/music_kraken/objects/contact.py | 37 +++++++++++++++++++++++++ src/music_kraken/utils/enums/contact.py | 7 +++++ 2 files changed, 44 insertions(+) create mode 100644 src/music_kraken/objects/contact.py create mode 100644 src/music_kraken/utils/enums/contact.py diff --git a/src/music_kraken/objects/contact.py b/src/music_kraken/objects/contact.py new file mode 100644 index 0000000..cdad4da --- /dev/null +++ b/src/music_kraken/objects/contact.py @@ -0,0 +1,37 @@ +from typing import Optional, List, Tuple + +from ..utils.enums.contact import ContactMethod +from .parents import DatabaseObject + + +class Contact(DatabaseObject): + COLLECTION_ATTRIBUTES = tuple() + SIMPLE_ATTRIBUTES = { + "contact_method": None, + "value": None, + } + + @property + def indexing_values(self) -> List[Tuple[str, object]]: + return [ + ('id', self.id), + ('value', self.value), + ] + + def __init__(self, contact_method: ContactMethod, value: str) -> None: + self.contact_method: ContactMethod = contact_method + self.value: str = value + + @classmethod + def match_url(cls, url: str) -> Optional["Contact"]: + url = url.strip() + + if url.startswith("mailto:"): + return cls(ContactMethod.EMAIL, url.replace("mailto:", "", 1)) + + if url.startswith("tel:"): + return cls(ContactMethod.PHONE, url.replace("tel:", "", 1)) + + if url.startswith("fax:"): + return cls(ContactMethod.FAX, url.replace("fax:", "", 1)) + diff --git a/src/music_kraken/utils/enums/contact.py b/src/music_kraken/utils/enums/contact.py new file mode 100644 index 0000000..938c801 --- /dev/null +++ b/src/music_kraken/utils/enums/contact.py @@ -0,0 +1,7 @@ +from enum import Enum + + +class ContactMethod(Enum): + EMAIL = "email" + PHONE = "phone" + FAX = "fax"