Revise contacts and email tools
All checks were successful
Build And Test / publish (push) Successful in 48s
All checks were successful
Build And Test / publish (push) Successful in 48s
This commit is contained in:
@@ -114,12 +114,13 @@ class ContactsService:
|
||||
|
||||
def list_contacts(
|
||||
self,
|
||||
addressbook_id: str,
|
||||
addressbook_id: Optional[str] = None,
|
||||
search: Optional[str] = None,
|
||||
limit: int = 100,
|
||||
offset: int = 0,
|
||||
) -> ContactList:
|
||||
client = self._get_client()
|
||||
addressbook_id = self._resolve_addressbook_id(addressbook_id)
|
||||
|
||||
# Build URL
|
||||
addressbook_url = self._build_url(addressbook_id)
|
||||
@@ -188,8 +189,9 @@ class ContactsService:
|
||||
offset=offset,
|
||||
)
|
||||
|
||||
def get_contact(self, addressbook_id: str, contact_id: str) -> Optional[Contact]:
|
||||
def get_contact(self, contact_id: str, addressbook_id: Optional[str] = None) -> Optional[Contact]:
|
||||
client = self._get_client()
|
||||
addressbook_id = self._resolve_addressbook_id(addressbook_id)
|
||||
|
||||
# Build URL
|
||||
contact_url = self._build_url(contact_id)
|
||||
@@ -206,7 +208,7 @@ class ContactsService:
|
||||
|
||||
def create_contact(
|
||||
self,
|
||||
addressbook_id: str,
|
||||
addressbook_id: Optional[str] = None,
|
||||
first_name: Optional[str] = None,
|
||||
last_name: Optional[str] = None,
|
||||
display_name: Optional[str] = None,
|
||||
@@ -219,6 +221,7 @@ class ContactsService:
|
||||
birthday: Optional[str] = None,
|
||||
) -> Contact:
|
||||
client = self._get_client()
|
||||
addressbook_id = self._resolve_addressbook_id(addressbook_id)
|
||||
|
||||
# Create vCard
|
||||
vcard = vobject.vCard()
|
||||
@@ -311,8 +314,8 @@ class ContactsService:
|
||||
|
||||
def update_contact(
|
||||
self,
|
||||
addressbook_id: str,
|
||||
contact_id: str,
|
||||
addressbook_id: Optional[str] = None,
|
||||
first_name: Optional[str] = None,
|
||||
last_name: Optional[str] = None,
|
||||
display_name: Optional[str] = None,
|
||||
@@ -324,7 +327,7 @@ class ContactsService:
|
||||
notes: Optional[str] = None,
|
||||
) -> Optional[Contact]:
|
||||
# Get existing contact
|
||||
existing = self.get_contact(addressbook_id, contact_id)
|
||||
existing = self.get_contact(contact_id, addressbook_id)
|
||||
if not existing:
|
||||
return None
|
||||
|
||||
@@ -342,12 +345,13 @@ class ContactsService:
|
||||
}
|
||||
|
||||
# Delete and recreate (simpler than partial update)
|
||||
self.delete_contact(addressbook_id, contact_id)
|
||||
self.delete_contact(contact_id, addressbook_id)
|
||||
return self.create_contact(addressbook_id, **updated_data)
|
||||
|
||||
def delete_contact(self, addressbook_id: str, contact_id: str) -> OperationResult:
|
||||
def delete_contact(self, contact_id: str, addressbook_id: Optional[str] = None) -> OperationResult:
|
||||
try:
|
||||
client = self._get_client()
|
||||
addressbook_id = self._resolve_addressbook_id(addressbook_id)
|
||||
|
||||
# Build URL
|
||||
contact_url = self._build_url(contact_id)
|
||||
@@ -481,3 +485,10 @@ class ContactsService:
|
||||
notes=notes,
|
||||
birthday=birthday,
|
||||
)
|
||||
|
||||
def _resolve_addressbook_id(self, addressbook_id: Optional[str]) -> str:
|
||||
if addressbook_id:
|
||||
return addressbook_id
|
||||
if self.settings.contacts_addressbook_id:
|
||||
return self.settings.contacts_addressbook_id
|
||||
raise ValueError("CONTACTS_ADDRESSBOOK_ID must be set to use contacts tools")
|
||||
|
||||
Reference in New Issue
Block a user