-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlimit.go
More file actions
226 lines (208 loc) · 7.7 KB
/
limit.go
File metadata and controls
226 lines (208 loc) · 7.7 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package ark
import (
"context"
"net/http"
"slices"
"time"
"github.com/ArkHQ-io/ark-go/internal/apijson"
"github.com/ArkHQ-io/ark-go/internal/requestconfig"
"github.com/ArkHQ-io/ark-go/option"
"github.com/ArkHQ-io/ark-go/packages/respjson"
"github.com/ArkHQ-io/ark-go/shared"
)
// LimitService contains methods and other services that help with interacting with
// the ark 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 [NewLimitService] method instead.
type LimitService struct {
Options []option.RequestOption
}
// NewLimitService 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 NewLimitService(opts ...option.RequestOption) (r LimitService) {
r = LimitService{}
r.Options = opts
return
}
// Returns current rate limit and send limit information for your account.
//
// This endpoint is the recommended way to check your account's operational limits.
// Use `/usage` endpoints for historical usage analytics.
//
// **Response includes:**
//
// - `rateLimit` - API request rate limit (requests per second)
// - `sendLimit` - Email sending limit (emails per hour)
// - `billing` - Credit balance and auto-recharge configuration
//
// **Notes:**
//
// - This request counts against your rate limit
// - `sendLimit` may be null if the service is temporarily unavailable
// - `billing` is null if billing is not configured
// - Send limit resets at the top of each hour
func (r *LimitService) Get(ctx context.Context, opts ...option.RequestOption) (res *LimitGetResponse, err error) {
opts = slices.Concat(r.Options, opts)
path := "limits"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return
}
// Current usage and limit information
type LimitsData struct {
// Billing and credit information
Billing LimitsDataBilling `json:"billing,required"`
// API rate limit status
RateLimit LimitsDataRateLimit `json:"rateLimit,required"`
// Email send limit status (hourly cap)
SendLimit LimitsDataSendLimit `json:"sendLimit,required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Billing respjson.Field
RateLimit respjson.Field
SendLimit respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r LimitsData) RawJSON() string { return r.JSON.raw }
func (r *LimitsData) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Billing and credit information
type LimitsDataBilling struct {
// Auto-recharge configuration
AutoRecharge LimitsDataBillingAutoRecharge `json:"autoRecharge,required"`
// Current credit balance as formatted string (e.g., "25.50")
CreditBalance string `json:"creditBalance,required"`
// Current credit balance in cents for precise calculations
CreditBalanceCents int64 `json:"creditBalanceCents,required"`
// Whether a payment method is configured
HasPaymentMethod bool `json:"hasPaymentMethod,required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
AutoRecharge respjson.Field
CreditBalance respjson.Field
CreditBalanceCents respjson.Field
HasPaymentMethod respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r LimitsDataBilling) RawJSON() string { return r.JSON.raw }
func (r *LimitsDataBilling) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Auto-recharge configuration
type LimitsDataBillingAutoRecharge struct {
// Amount to recharge when triggered
Amount string `json:"amount,required"`
// Whether auto-recharge is enabled
Enabled bool `json:"enabled,required"`
// Balance threshold that triggers recharge
Threshold string `json:"threshold,required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Amount respjson.Field
Enabled respjson.Field
Threshold respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r LimitsDataBillingAutoRecharge) RawJSON() string { return r.JSON.raw }
func (r *LimitsDataBillingAutoRecharge) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// API rate limit status
type LimitsDataRateLimit struct {
// Maximum requests allowed per period
Limit int64 `json:"limit,required"`
// Time period for the limit
//
// Any of "second".
Period string `json:"period,required"`
// Requests remaining in current window
Remaining int64 `json:"remaining,required"`
// Unix timestamp when the limit resets
Reset int64 `json:"reset,required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Limit respjson.Field
Period respjson.Field
Remaining respjson.Field
Reset respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r LimitsDataRateLimit) RawJSON() string { return r.JSON.raw }
func (r *LimitsDataRateLimit) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Email send limit status (hourly cap)
type LimitsDataSendLimit struct {
// Whether approaching the limit (>90%)
Approaching bool `json:"approaching,required"`
// Whether the limit has been exceeded
Exceeded bool `json:"exceeded,required"`
// Maximum emails allowed per hour (null = unlimited)
Limit int64 `json:"limit,required"`
// Time period for the limit
//
// Any of "hour".
Period string `json:"period,required"`
// Emails remaining in current period (null if unlimited)
Remaining int64 `json:"remaining,required"`
// ISO timestamp when the limit window resets (top of next hour)
ResetsAt time.Time `json:"resetsAt,required" format:"date-time"`
// Usage as a percentage (null if unlimited)
UsagePercent float64 `json:"usagePercent,required"`
// Emails sent in current period
Used int64 `json:"used,required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Approaching respjson.Field
Exceeded respjson.Field
Limit respjson.Field
Period respjson.Field
Remaining respjson.Field
ResetsAt respjson.Field
UsagePercent respjson.Field
Used respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r LimitsDataSendLimit) RawJSON() string { return r.JSON.raw }
func (r *LimitsDataSendLimit) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Account rate limits and send limits response
type LimitGetResponse struct {
// Current usage and limit information
Data LimitsData `json:"data,required"`
Meta shared.APIMeta `json:"meta,required"`
Success bool `json:"success,required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Data respjson.Field
Meta respjson.Field
Success respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r LimitGetResponse) RawJSON() string { return r.JSON.raw }
func (r *LimitGetResponse) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}