Source code for q2_cores.models

from typing import Any, Dict, Optional, Union
from enum import Enum

from q2_sdk.models.demographic import (
    Address as SDKAddress,
    AddressType as SDKAddressType,
    Phone as SDKPhone,
    PhoneType,
)
from q2_sdk.models.recursive_encoder import JsonSerializable


[docs] class BaseSubAccountDetails: """ Holds AccountID and Account Description information """ def __init__(self, account_id: str, account_desc: str): self.account_id = account_id self.account_desc = account_desc
class RecordType: DOMESTIC = "Domestic" INTERNATIONAL = "International" class CountryCodeType: ISOCODE = "IsoCode" ISOCODEA2 = "IsoCodeA2" ISOCODEA3 = "IsoCodeA3"
[docs] class Country(JsonSerializable): """Country class""" def __init__( self, country_code: Optional[str], country_abb: Optional[str], country_code_type: Optional[CountryCodeType], dial_code: Optional[str] = None, ): self.country_code = country_code self.country_abb = country_abb self.country_code_type = country_code_type self.dial_code = dial_code def __repr__(self): return self.country_abb def __eq__(self, other): return vars(self) == vars(other) def __hash__(self): return hash(( self.country_code, self.country_code, self.country_code_type, self.dial_code, ))
[docs] class State(JsonSerializable): """State class""" def __init__(self, state_code: str, state_abb: str): self.state_code: str = state_code self.state_abb: str = state_abb def __repr__(self): return self.state_abb def __eq__(self, other): return vars(self) == vars(other) def __hash__(self): return hash((self.state_code, self.state_abb))
[docs] class AddressType(SDKAddressType): PRIMARY = "Primary" ALTERNATE = "Alternate" MAILING = "Mailing"
[docs] class Address(SDKAddress): def __init__( self, address_1: Optional[str], address_2: Optional[str], city: Optional[str], province: Optional[str], state: Optional[State], zipcode: Optional[str], postal_code: Optional[str], country: Optional[Country], address_type: Optional[AddressType], record_type: Union[RecordType, str, None] = RecordType.DOMESTIC, address_expiration_date: Optional[str] = None, is_primary: Optional[bool] = None, provider_data: Dict[str, Any] = None, ): super().__init__( address_1=address_1, address_2=address_2, city=city, state=state, zipcode=zipcode, address_type=address_type, province=province, country=country, ) self.state = state self.country = country self.postal_code = postal_code self.address_expiration_date = address_expiration_date self.record_type = record_type self.is_primary = is_primary self.provider_data = provider_data or {} def __eq__(self, other): return vars(self) == vars(other) def __hash__(self): return hash(( self.address_1, self.address_2, self.city, self.state, self.zipcode, self.province, self.postal_code, self.country, self.record_type, self.address_type, self.address_expiration_date, )) def __json__(self): return vars(self)
[docs] class ExtendedPhoneType(PhoneType): """Enum for Q2 Phone Types PERSONAL = 'Home' BUSINESS = 'Business' CELL = 'Mobile' """ OTHER = "Other"
[docs] class Phone(SDKPhone): def __init__( self, area_code: str, phone_number: str, phone_type: PhoneType, country: Union[Country, str, None] = None, record_type: Union[RecordType, str, None] = RecordType.DOMESTIC, extension: str = "", provider_data: Dict[str, Any] = None, ): super().__init__( area_code=area_code, phone_number=phone_number, extension=extension, phone_type=phone_type, ) self.country = country self.record_type = record_type self.provider_data = provider_data or {}
[docs] @staticmethod def build_from_str(phone_str: str, phone_type: PhoneType): """ Takes a string of numbers in several formats and returns a Phone instance """ if not phone_str: return None extension = "" if "x" in phone_str: phone_str, extension = phone_str.split("x") phone_num = "".join([x for x in phone_str if x.isdigit()]) return Phone( phone_num[:3], phone_num[3:], phone_type, record_type=RecordType.DOMESTIC, extension=extension, )
def __eq__(self, other): return vars(self) == vars(other) def __hash__(self): return hash(( self.area_code, self.phone_number, self.type, self.extension, self.record_type, ))
[docs] class ContactMethod(Enum): EMAIL = "E" SMS = "S" PUSH = "P" HNO = "H"
[docs] class AlertStatus(Enum): QUEUED = "Q" SUCCESS = "S" FAIL = "F"
class Alert: def __init__( self, alert_id: int = 0, contact_method: ContactMethod = ContactMethod.EMAIL, contact_value: str = "", message: str = "", status: AlertStatus = AlertStatus.QUEUED, ) -> None: self.alert_id = alert_id self.contact_method = contact_method self.contact_value = contact_value self.message = message self.status = status def __str__(self) -> str: message = self.message.strip().replace("\n", "\\n") return ( f"{self.__class__.__name__}(" f"id={self.alert_id}, " f"contact_method='{self.contact_method.value}', " f"contact_value='{self.contact_value}', " f"message='{message}', " f"status='{self.status.name}'" f")" )