-
Notifications
You must be signed in to change notification settings - Fork 76
/
batches.go
74 lines (58 loc) · 1.93 KB
/
batches.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package gochimp3
import (
"fmt"
"net/url"
)
const (
batches_path = "/batches"
single_batch_path = batches_path + "/%s"
)
func (api *API) GetBatchOperations(params *ListQueryParams) (*ListOfBatchOperations, error) {
response := new(ListOfBatchOperations)
err := api.Request("GET", batches_path, params, nil, response)
if err != nil {
return nil, err
}
for _, l := range response.BatchOperations {
l.api = api
}
return response, nil
}
type ListOfBatchOperations struct {
baseList
BatchOperations []BatchOperationResponse `json:"batches"`
}
func (api *API) GetBatchOperation(id string, params *BasicQueryParams) (*BatchOperationResponse, error) {
endpoint := fmt.Sprintf(single_batch_path, id)
response := new(BatchOperationResponse)
response.api = api
return response, api.Request("GET", endpoint, params, nil, response)
}
func (api *API) CreateBatchOperation(body *BatchOperationCreationRequest) (*BatchOperationResponse, error) {
response := new(BatchOperationResponse)
response.api = api
return response, api.Request("POST", batches_path, nil, body, response)
}
type BatchOperationCreationRequest struct {
Operations []BatchOperation `json:"operations"`
}
type BatchOperationResponse struct {
Links []Link `json:"_links,omitempty"`
ID string `json:"id"`
Status string `json:"status"`
TotalOperations int `json:"total_operations"`
FinishedOperations int `json:"finished_operations"`
ErroredOperations int `json:"errored_operations"`
SubmittedAt string `json:"submitted_at,omitempty"`
CompletedAt string `json:"completed_at,omitempty"`
ResponseBodyUrl string `json:"response_body_url"`
api *API
}
type BatchOperation struct {
Method string `json:"method"`
Path string `json:"path"`
Params url.Values `json:"params,omitempty"`
Body string `json:"body"`
OperationID string `json:"operation_id,omitempty"`
api *API
}