diff --git a/carddav/carddav.go b/carddav/carddav.go index 9777aca..10a335f 100644 --- a/carddav/carddav.go +++ b/carddav/carddav.go @@ -195,6 +195,7 @@ func (ab *addressBook) GetAddressObject(id string) (carddav.AddressObject, error contact, err := ab.c.GetContact(id) if err != nil { + // TODO: return carddav.ErrNotFound if appropriate return nil, err } diff --git a/protonmail/contacts.go b/protonmail/contacts.go index c6e2ea1..daf30e5 100644 --- a/protonmail/contacts.go +++ b/protonmail/contacts.go @@ -170,11 +170,14 @@ type CreateContactResp struct { } } +func (resp *CreateContactResp) Err() error { + return resp.Response.Err() +} + func (c *Client) CreateContacts(contacts []*Contact) ([]*CreateContactResp, error) { reqData := struct { Contacts []*Contact }{contacts} - req, err := c.newJSONRequest(http.MethodPost, "/contacts", &reqData) if err != nil { return nil, err @@ -190,3 +193,68 @@ func (c *Client) CreateContacts(contacts []*Contact) ([]*CreateContactResp, erro return respData.Responses, nil } + +func (c *Client) UpdateContact(id string, cards []*ContactCard) (*Contact, error) { + reqData := struct { + Cards []*ContactCard + }{cards} + req, err := c.newJSONRequest(http.MethodPut, "/contacts/"+id, &reqData) + if err != nil { + return nil, err + } + + var respData struct { + resp + Contact *Contact + } + if err := c.doJSON(req, &respData); err != nil { + return nil, err + } + + return respData.Contact, nil +} + +type DeleteContactResp struct { + ID string + Response struct { + resp + } +} + +func (resp *DeleteContactResp) Err() error { + return resp.Response.Err() +} + +func (c *Client) DeleteContacts(ids []string) ([]*DeleteContactResp, error) { + reqData := struct { + IDs []string + }{ids} + req, err := c.newJSONRequest(http.MethodPut, "/contacts/delete", &reqData) + if err != nil { + return nil, err + } + + var respData struct { + resp + Responses []*DeleteContactResp + } + if err := c.doJSON(req, &respData); err != nil { + return nil, err + } + + return respData.Responses, nil +} + +func (c *Client) DeleteAllContacts() error { + req, err := c.newRequest(http.MethodDelete, "/contacts", nil) + if err != nil { + return err + } + + var respData resp + if err := c.doJSON(req, &respData); err != nil { + return err + } + + return nil +}