package amo import "surdeus.su/core/amo/api" import "surdeus.su/core/amo/leads" import "surdeus.su/core/ss/urlenc" import "errors" import "fmt" // Get list of leads. func (client *Client) GetLeads( opts ...urlenc.Builder, ) ([]leads.Lead, error) { res := fmt.Sprintf( "/api/v4/leads?%s", urlenc.Join(opts...).Encode(), ) ret := []leads.Lead{} for { var lds leads.Leads err := client.API.Get(res, &lds) if err != nil { if errors.Is(err, api.ErrNoContent) { break } return nil, err } ret = append(ret, lds.Embedded.Leads...) if lds.Links.Next.Href == "" { break } res = lds.Links.Next.Href } return ret, nil } // Get lead with the specified ID. func (client *Client) GetLead( leadID int, opts ...urlenc.Builder, ) (*leads.Lead, error) { deal := new(leads.Lead) resource := fmt.Sprintf( "/api/v4/leads/%d?%s", leadID, urlenc.Join(opts...).Encode(), ) err := client.API.Get(resource, deal) return deal, err } func (client *Client) UpdateLead( lead *leads.Lead, ) error { return client.updateEntity("/api/v4/leads", lead.ID, lead) }