package amo import "surdeus.su/core/ss/urlenc" import "surdeus.su/core/amo/companies" import "surdeus.su/core/amo/api" import "errors" import "fmt" func (client *Client) GetCompany( companyID int, opts ...urlenc.Builder, ) (*Company, error) { deal := new(companies.Company) resource := fmt.Sprintf( "/api/v4/companies/%d?%s", companyID, urlenc.Join(opts...), ) err := client.API.Get(resource, deal) if err != nil { return nil, err } return deal, nil } // Get list of leads. func (client *Client) GetCompanies( opts ...urlenc.Builder, ) ([]Company, NextFunc[[]Company], error) { res := fmt.Sprintf( "/api/v4/companies?%s", urlenc.Join(opts...).Encode(), ) return client.GetCompaniesByURL(res) } func (client *Client) GetCompaniesByURL( u string, ) ([]Company, NextFunc[[]Company], error) { var fn NextFunc[[]Company] coms := companies.Companies{} err := client.API.Get(u, &coms) if err != nil { if errors.Is(err, api.ErrNoContent) { return nil, nil, nil } return nil, nil, err } //ret = append(ret, coms.Embedded.Companies...) nextHref := coms.Links.Next.Href if nextHref != "" { fn = MakeNextFunc( nextHref, client.GetCompaniesByURL, ) } return coms.Embedded.Companies, fn, nil } func (client *Client) UpdateCompany( company *companies.Company, ) error { return client.updateEntity( "/api/v4/companies", company.ID, company, ) } func (client *Client) UpdateCompanies( cs []companies.Company, ) ([]Company, error) { if len(cs) > MEPR { return nil, ErrTooManyEntities } //ret := []Company{} err := client.API.Patch( "/api/v4/companies", cs, nil, ) if err != nil { return nil, err } return nil, nil }