# -*- coding: utf-8 -*-"""Short.io Domain API implementation.This module provides classes and methods for interacting with the Short.io Domain-relatedAPI endpoints. It includes the Domain model class and API methods for retrieving domaininformation."""importtypingasTfromrequestsimportResponsefrom.argimportNA,rm_nafrom.constantsimportDEFAULT_RAISE_FOR_STATUSfrom.modelimportDomainifT.TYPE_CHECKING:# pragma: no coverfrom.clientimportClient
[docs]classDomainMixin:""" Mixin class providing Domain-related API methods for the Client. """
[docs]deflist_domains(self:"Client",limit:T.Optional[int]=NA,offset:T.Optional[int]=NA,no_team_id:T.Optional[bool]=NA,pattern:T.Optional[str]=NA,team_id:T.Optional[str]=NA,raise_for_status:bool=DEFAULT_RAISE_FOR_STATUS,)->tuple[Response,list[Domain]]:""" Retrieve a list of all domains with optional filtering. Ref: - https://developers.short.io/reference/get_api-domains """url=f"{self.endpoint}/api/domains"params={"limit":limit,"offset":offset,"noTeamId":no_team_id,"pattern":pattern,"teamId":team_id,}params=rm_na(**params)response=self.http_get(url=url,params=params,)ifraise_for_status:response.raise_for_status()domain_list=[Domain(_data=dct)fordctinresponse.json()]returnresponse,domain_list
[docs]defget_domain(self:"Client",domain_id:int,raise_for_status:bool=DEFAULT_RAISE_FOR_STATUS,)->tuple[Response,T.Optional[Domain]]:""" Retrieve a specific domain by its ID. Ref: - https://developers.short.io/reference/get_domains-domainid """url=f"{self.endpoint}/domains/{domain_id}"response=self.http_get(url=url,)ifraise_for_status:response.raise_for_status()ifresponse.status_code==404:domain=Noneelse:domain=Domain(_data=response.json())returnresponse,domain
[docs]defget_domain_by_hostname(self:"Client",hostname:str,raise_for_status:bool=DEFAULT_RAISE_FOR_STATUS,)->T.Tuple[Response,T.Optional[Domain]]:""" Find a domain by its hostname. This method lists all domains and finds the one matching the specified hostname. This is a convenience method that combines :meth:`list_domains` and filtering. """response,domain_list=self.list_domains(raise_for_status=raise_for_status)fordomainindomain_list:ifdomain.hostname==hostname:returnresponse,domainreturnresponse,None