123456789101112131415161718192021222324252627282930313233343536373839 |
- package amo
- import "surdeus.su/core/amo/events"
- import "surdeus.su/core/amo/api"
- import "surdeus.su/core/ss/urlenc"
- import "errors"
- import "fmt"
- // Returns the events from AmoCRM by specified request.
- // If there are no such events returns an empty slice of events.
- func (client *Client) GetEvents(
- opts ...urlenc.Builder,
- ) ([]events.Event, error) {
- res := fmt.Sprintf(
- "/api/v4/events?%s",
- urlenc.Join(opts...).Encode(),
- )
- ret := []events.Event{}
- for {
- resp := events.EventsResponse{}
- err := client.API.Get(res, &resp)
- if err != nil {
- // Return empty if no content avialable.
- if errors.Is(err, api.ErrNoContent) {
- break
- }
- return nil, err
- }
- ret = append(ret, resp.Embedded.Events...)
- if resp.Links.Next.Href == "" {
- break
- }
- //time.Sleep(time.Millisecond * 300)
- res = resp.Links.Next.Href
- }
- return ret, nil
- }
|