Repository navigation
Expand file tree
/
Copy pathactor_version.go
More file actions
73 lines (60 loc) · 3.11 KB
/
Copy pathactor_version.go
File metadata and controls
73 lines (60 loc) · 3.11 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package apify
import "context"
// ActorVersionCollectionClient is a client for an Actor's version collection
// (GET/POST /v2/actors/{actorId}/versions).
type ActorVersionCollectionClient struct {
ctx *resourceContext
}
func newActorVersionCollectionClient(hc *httpClient, actorURL string) *ActorVersionCollectionClient {
return &ActorVersionCollectionClient{ctx: newCollectionContext(hc, actorURL, "versions")}
}
// List lists the Actor's versions.
func (c *ActorVersionCollectionClient) List(ctx context.Context, options ListOptions) (PaginationList[ActorVersion], error) {
params := NewQueryParams()
options.apply(params)
return listResource[ActorVersion](ctx, c.ctx, "", params)
}
// Iterate returns a lazy iterator over the Actor's versions. The versions endpoint ignores
// offset/limit/desc (per the OpenAPI specification, it always returns every version in one
// response), so options and chunkSize are accepted only for interface symmetry with the other
// collections' Iterate and have no effect; the iterator drains a single page. Mirrors the
// reference client's versions().list(), which likewise exposes no pagination options.
func (c *ActorVersionCollectionClient) Iterate(options ListOptions, chunkSize *int64) *ListIterator[ActorVersion] {
return newUnpaginatedIterator(func(ctx context.Context) (PaginationList[ActorVersion], error) {
return c.List(ctx, options)
})
}
// Create creates a new Actor version. version is any JSON-serializable version definition.
func (c *ActorVersionCollectionClient) Create(ctx context.Context, version any) (ActorVersion, error) {
return createResource[ActorVersion](ctx, c.ctx, NewQueryParams(), version, c.ctx.shortTimeout())
}
// ActorVersionClient is a client for a specific Actor version
// (GET/PUT/DELETE /v2/actors/{actorId}/versions/{versionNumber}).
type ActorVersionClient struct {
ctx *resourceContext
versionURL string
}
func newActorVersionClient(hc *httpClient, actorURL, versionNumber string) *ActorVersionClient {
ctx := newSingleContext(hc, actorURL, "versions", versionNumber)
return &ActorVersionClient{ctx: ctx, versionURL: ctx.subURL("")}
}
// Get fetches the version. The bool reports whether it exists.
func (c *ActorVersionClient) Get(ctx context.Context) (ActorVersion, bool, error) {
return getResource[ActorVersion](ctx, c.ctx, "", NewQueryParams())
}
// Update updates the version with the given fields and returns the updated object.
func (c *ActorVersionClient) Update(ctx context.Context, newFields any) (ActorVersion, error) {
return updateResource[ActorVersion](ctx, c.ctx, "", newFields)
}
// Delete deletes the version.
func (c *ActorVersionClient) Delete(ctx context.Context) error {
return deleteResource(ctx, c.ctx, "")
}
// EnvVar returns a client for a specific environment variable of this version.
func (c *ActorVersionClient) EnvVar(name string) *ActorEnvVarClient {
return newActorEnvVarClient(c.ctx.http, c.versionURL, name)
}
// EnvVars returns a client for this version's environment variable collection.
func (c *ActorVersionClient) EnvVars() *ActorEnvVarCollectionClient {
return newActorEnvVarCollectionClient(c.ctx.http, c.versionURL)
}