-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathfolderjob.go
More file actions
95 lines (83 loc) · 3.22 KB
/
folderjob.go
File metadata and controls
95 lines (83 loc) · 3.22 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package imagekit
import (
"context"
"errors"
"fmt"
"net/http"
"slices"
"github.com/imagekit-developer/imagekit-go/v2/internal/apijson"
"github.com/imagekit-developer/imagekit-go/v2/internal/requestconfig"
"github.com/imagekit-developer/imagekit-go/v2/option"
"github.com/imagekit-developer/imagekit-go/v2/packages/respjson"
)
// FolderJobService contains methods and other services that help with interacting
// with the ImageKit API.
//
// Note, unlike clients, this service does not read variables from the environment
// automatically. You should not instantiate this service directly, and instead use
// the [NewFolderJobService] method instead.
type FolderJobService struct {
Options []option.RequestOption
}
// NewFolderJobService generates a new service that applies the given options to
// each request. These options are applied after the parent client's options (if
// there is one), and before any request-specific options.
func NewFolderJobService(opts ...option.RequestOption) (r FolderJobService) {
r = FolderJobService{}
r.Options = opts
return
}
// This API returns the status of a bulk job like copy and move folder operations.
func (r *FolderJobService) Get(ctx context.Context, jobID string, opts ...option.RequestOption) (res *FolderJobGetResponse, err error) {
opts = slices.Concat(r.Options, opts)
if jobID == "" {
err = errors.New("missing required jobId parameter")
return nil, err
}
path := fmt.Sprintf("v1/bulkJobs/%s", jobID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return res, err
}
type FolderJobGetResponse struct {
// Unique identifier of the bulk job.
JobID string `json:"jobId"`
// Unique identifier of the purge request. This will be present only if
// `purgeCache` is set to `true` in the rename folder API request.
PurgeRequestID string `json:"purgeRequestId"`
// Status of the bulk job.
//
// Any of "Pending", "Completed".
Status FolderJobGetResponseStatus `json:"status"`
// Type of the bulk job.
//
// Any of "COPY_FOLDER", "MOVE_FOLDER", "RENAME_FOLDER".
Type FolderJobGetResponseType `json:"type"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
JobID respjson.Field
PurgeRequestID respjson.Field
Status respjson.Field
Type respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r FolderJobGetResponse) RawJSON() string { return r.JSON.raw }
func (r *FolderJobGetResponse) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Status of the bulk job.
type FolderJobGetResponseStatus string
const (
FolderJobGetResponseStatusPending FolderJobGetResponseStatus = "Pending"
FolderJobGetResponseStatusCompleted FolderJobGetResponseStatus = "Completed"
)
// Type of the bulk job.
type FolderJobGetResponseType string
const (
FolderJobGetResponseTypeCopyFolder FolderJobGetResponseType = "COPY_FOLDER"
FolderJobGetResponseTypeMoveFolder FolderJobGetResponseType = "MOVE_FOLDER"
FolderJobGetResponseTypeRenameFolder FolderJobGetResponseType = "RENAME_FOLDER"
)