package amo import "surdeus.su/core/amo/contacts" import "surdeus.su/core/ss/urlenc" import "errors" import "surdeus.su/core/amo/api" import "fmt" func (client *Client) GetContact( contactId int, opts ...urlenc.Builder, ) (*contacts.Contact, error) { deal := new(contacts.Contact) res := fmt.Sprintf( "/api/v4/contacts/%d?%s", contactId, urlenc.Join(opts...).Encode(), ) err := client.API.Get(res, deal) if err != nil { return nil, err } return deal, nil } // Get list of contacts. func (client *Client) GetContacts( opts ...urlenc.Builder, ) ([]contacts.Contact, error) { res := fmt.Sprintf( "/api/v4/contacts?%s", urlenc.Join(opts...).Encode(), ) ret := []contacts.Contact{} for { var cts contacts.Contacts err := client.API.Get(res, &cts) if err != nil { if errors.Is(err, api.ErrNoContent) { break } return nil, err } ret = append(ret, cts.Embedded.Contacts...) if cts.Links.Next.Href == "" { break } res = cts.Links.Next.Href } return ret, nil } func (client *Client) UpdateContact(contact *contacts.Contact) error { return client.updateEntity( "/api/v4/contacts", contact.Id, contact, ) }