Files
sdk/api_allowance.go

152 lines
5.3 KiB
Go

/*
Hanzo Cloud API
The Hanzo Cloud API as a customer calls it: every operation under /v1/ except the operator's admin product, relay routes, legacy spellings and capabilities still reached by flag. Tagged by product: the first path segment after /v1/.
API version: v1
*/
// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.
package hanzoai
import (
"bytes"
"context"
"io"
"net/http"
"net/url"
)
// AllowanceAPIService AllowanceAPI service
type AllowanceAPIService service
type AllowanceAPIGetAllowanceRequest struct {
ctx context.Context
ApiService *AllowanceAPIService
}
func (r AllowanceAPIGetAllowanceRequest) Execute() (*AllowanceAllowance, *http.Response, error) {
return r.ApiService.GetAllowanceExecute(r)
}
/*
GetAllowance Answers what the CALLER has left of their plan's free-call allowance in the window that holds them, and the instant that window reopens.
Answers what the CALLER has left of their plan's free-call allowance in the window
that holds them, and the instant that window reopens.
This is the number a product shows beside the composer — "2 of 3 left" —
and the moment to offer a plan is when it reaches zero. It READS: asking does not
spend, so a page that polls it costs the caller nothing. A Free person's window is
a session that opens at their first call after the last one ended and runs five
hours; while none runs, resets is 0 and the next call opens one.
A bounded caller is POOLED: the Free plan is limited usage from one pool every
free user shares — the platform's vendor accounts for free models — so the answer
says so (pooled) and carries that pool's standing: available, busy or exhausted,
and when it refills. The pool is read from the process that spends it and is
absent when that process does not answer, never guessed. A paid plan is not
pooled and carries no pool: its usage is metered in money.
The subject is the caller's own, resolved from the verified credential, and can
never be named in the request — so this is a mirror, not a lookup of someone else.
An unauthenticated caller is refused: there is no allowance without someone to
hold it.
A named handler, not a closure, so zipdoc can lift this prose into the registry.
@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
@return AllowanceAPIGetAllowanceRequest
*/
func (a *AllowanceAPIService) GetAllowance(ctx context.Context) AllowanceAPIGetAllowanceRequest {
return AllowanceAPIGetAllowanceRequest{
ApiService: a,
ctx: ctx,
}
}
// Execute executes the request
//
// @return AllowanceAllowance
func (a *AllowanceAPIService) GetAllowanceExecute(r AllowanceAPIGetAllowanceRequest) (*AllowanceAllowance, *http.Response, error) {
var (
localVarHTTPMethod = http.MethodGet
localVarPostBody interface{}
formFiles []formFile
localVarReturnValue *AllowanceAllowance
)
localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "AllowanceAPIService.GetAllowance")
if err != nil {
return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()}
}
localVarPath := localBasePath + "/v1/allowance"
localVarHeaderParams := make(map[string]string)
localVarQueryParams := url.Values{}
localVarFormParams := url.Values{}
// to determine the Content-Type header
localVarHTTPContentTypes := []string{}
// set Content-Type header
localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes)
if localVarHTTPContentType != "" {
localVarHeaderParams["Content-Type"] = localVarHTTPContentType
}
// to determine the Accept header
localVarHTTPHeaderAccepts := []string{"application/json", "application/problem+json"}
// set Accept header
localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts)
if localVarHTTPHeaderAccept != "" {
localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept
}
req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles)
if err != nil {
return localVarReturnValue, nil, err
}
localVarHTTPResponse, err := a.client.callAPI(req)
if err != nil || localVarHTTPResponse == nil {
return localVarReturnValue, localVarHTTPResponse, err
}
localVarBody, err := io.ReadAll(localVarHTTPResponse.Body)
localVarHTTPResponse.Body.Close()
localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody))
if err != nil {
return localVarReturnValue, localVarHTTPResponse, err
}
if localVarHTTPResponse.StatusCode >= 300 {
newErr := &GenericOpenAPIError{
body: localVarBody,
error: localVarHTTPResponse.Status,
}
var v ProblemDetails
err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr.error = err.Error()
return localVarReturnValue, localVarHTTPResponse, newErr
}
newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v)
newErr.model = v
return localVarReturnValue, localVarHTTPResponse, newErr
}
err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr := &GenericOpenAPIError{
body: localVarBody,
error: err.Error(),
}
return localVarReturnValue, localVarHTTPResponse, newErr
}
return localVarReturnValue, localVarHTTPResponse, nil
}