-
Notifications
You must be signed in to change notification settings - Fork 501
/
contacts_fetch.go
55 lines (45 loc) · 1.21 KB
/
contacts_fetch.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package crm
import (
"context"
"github.com/clarkmcc/go-hubspot"
"github.com/clarkmcc/go-hubspot/generated/v3/contacts"
"github.com/cloudquery/cloudquery/plugins/source/hubspot/client"
"github.com/cloudquery/plugin-sdk/v4/schema"
)
func fetchContacts(ctx context.Context, meta schema.ClientMeta, parent *schema.Resource, res chan<- any) error {
config := contacts.NewConfiguration()
hubspotClient := contacts.NewAPIClient(config)
cqClient := meta.(*client.Client)
var after string
for {
if err := cqClient.RateLimiter.Wait(ctx); err != nil {
return nil
}
req := hubspotClient.BasicApi.
GetPage(hubspot.WithAuthorizer(ctx, cqClient.Authorizer)).
Properties(cqClient.Spec.TableOptions.ForTable("hubspot_crm_contacts").GetProperties()).
Associations(cqClient.Spec.TableOptions.ForTable("hubspot_crm_contacts").GetAssociations()).
Limit(client.DefaultPageSize)
if len(after) > 0 {
req = req.After(after)
}
out, _, err := req.Execute()
if err != nil {
return err
}
res <- out.Results
if !out.HasPaging() {
break
}
paging := out.GetPaging()
if !paging.HasNext() {
break
}
next := paging.GetNext()
after = next.After
if after == "" {
break
}
}
return nil
}