/
misc.go
117 lines (103 loc) · 3.54 KB
/
misc.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package admin
import (
"context"
"net/http"
"time"
"github.com/cloudinary/cloudinary-go/api"
)
const (
ping api.EndPoint = "ping"
usage api.EndPoint = "usage"
)
// Ping tests the reachability of the Cloudinary API.
//
// https://cloudinary.com/documentation/admin_api#ping
func (a *API) Ping(ctx context.Context) (*PingResult, error) {
res := &PingResult{}
_, err := a.get(ctx, ping, nil, res)
return res, err
}
// PingResult represents the result of the Ping request.
type PingResult struct {
Status string `json:"status"`
Error api.ErrorResp `json:"error,omitempty"`
Response http.Response
}
// UsageParams are the parameters for Usage.
type UsageParams struct {
Date time.Time `json:"-"`
}
// Usage gets account usage details.
//
// Returns a report detailing your current Cloudinary account usage details, including
// storage, bandwidth, requests, number of resources, and add-on usage.
// Note that numbers are updated periodically.
//
// https://cloudinary.com/documentation/admin_api#usage
func (a *API) Usage(ctx context.Context, params UsageParams) (*UsageResult, error) {
date := ""
if !params.Date.IsZero() {
date = params.Date.Format("02-01-2006")
}
res := &UsageResult{}
_, err := a.get(ctx, api.BuildPath(usage, date), params, res)
return res, err
}
// UsageResult is the result of Usage.
type UsageResult struct {
Plan string `json:"plan"`
LastUpdated string `json:"last_updated"`
Transformations struct {
Usage int `json:"usage"`
Limit int `json:"limit"`
UsedPercent float64 `json:"used_percent"`
} `json:"transformations"`
Objects struct {
Usage int `json:"usage"`
Limit int `json:"limit"`
UsedPercent float64 `json:"used_percent"`
} `json:"objects"`
Bandwidth struct {
Usage int64 `json:"usage"`
Limit int64 `json:"limit"`
UsedPercent float64 `json:"used_percent"`
} `json:"bandwidth"`
Storage struct {
Usage int64 `json:"usage"`
Limit int64 `json:"limit"`
UsedPercent float64 `json:"used_percent"`
} `json:"storage"`
Requests int64 `json:"requests"`
Resources int `json:"resources"`
DerivedResources int `json:"derived_resources"`
MediaLimits struct {
ImageMaxSizeBytes int `json:"image_max_size_bytes"`
VideoMaxSizeBytes int `json:"video_max_size_bytes"`
RawMaxSizeBytes int `json:"raw_max_size_bytes"`
ImageMaxPx int `json:"image_max_px"`
AssetMaxTotalPx int `json:"asset_max_total_px"`
} `json:"media_limits"`
Error api.ErrorResp `json:"error,omitempty"`
Response interface{}
}
// TagsParams are the parameters for Tags.
type TagsParams struct {
AssetType api.AssetType `json:"-"` // The type of asset.
NextCursor string `json:"next_cursor,omitempty"` // The cursor used for pagination.
MaxResults int `json:"max_results,omitempty"` // Maximum number of tags to return (up to 500). Default: 10.
Prefix string `json:"prefix,omitempty"` // Find all tags that start with the given prefix.
}
// Tags lists all the tags currently used for a specified asset type.
//
// https://cloudinary.com/documentation/admin_api#get_tags
func (a *API) Tags(ctx context.Context, params TagsParams) (*TagsResult, error) {
res := &TagsResult{}
_, err := a.get(ctx, api.BuildPath(tags, params.AssetType), params, res)
return res, err
}
// TagsResult is the result of Tags.
type TagsResult struct {
Tags []string `json:"tags"`
NextCursor string `json:"next_cursor"`
Error api.ErrorResp `json:"error,omitempty"`
}