openmeter / api /v3 /client /client.go
Leon4gr45's picture
Upload folder using huggingface_hub (part 3)
04f1444 verified
Raw
History Blame Contribute Delete
3.38 kB
// Code generated by @openmeter/typespec-go. DO NOT EDIT.
package openmeter
import (
"fmt"
"net/http"
"net/url"
"strings"
)
type Client struct {
baseURL *url.URL
httpClient *http.Client
token string
userAgent string
Events *EventsService
Meters *MetersService
Customers *CustomersService
Entitlements *EntitlementsService
Subscriptions *SubscriptionsService
Apps *AppsService
Billing *BillingService
Invoices *InvoicesService
Tax *TaxService
Currencies *CurrenciesService
Features *FeaturesService
LLMCost *LLMCostService
Plans *PlansService
Addons *AddonsService
PlanAddons *PlanAddonsService
Defaults *DefaultsService
Governance *GovernanceService
}
func New(baseURL string, opts ...Option) (*Client, error) {
if baseURL == "" {
return nil, fmt.Errorf("openmeter: baseURL is required")
}
u, err := url.Parse(baseURL)
if err != nil {
return nil, fmt.Errorf("openmeter: invalid baseURL %q: %w", baseURL, err)
}
if u.Scheme == "" || u.Host == "" {
return nil, fmt.Errorf("openmeter: baseURL %q must be absolute (scheme and host)", baseURL)
}
c := &Client{
baseURL: u,
userAgent: defaultUserAgent,
}
for _, opt := range opts {
opt(c)
}
if c.httpClient == nil {
c.httpClient = defaultHTTPClient()
}
c.Events = &EventsService{client: c}
c.Meters = &MetersService{client: c}
c.Customers = &CustomersService{client: c}
c.Entitlements = &EntitlementsService{client: c}
c.Subscriptions = &SubscriptionsService{client: c}
c.Apps = &AppsService{client: c}
c.Billing = &BillingService{client: c}
c.Invoices = &InvoicesService{client: c}
c.Tax = &TaxService{client: c}
c.Currencies = &CurrenciesService{client: c}
c.Features = &FeaturesService{client: c}
c.LLMCost = &LLMCostService{client: c}
c.Plans = &PlansService{client: c}
c.Addons = &AddonsService{client: c}
c.PlanAddons = &PlanAddonsService{client: c}
c.Defaults = &DefaultsService{client: c}
c.Governance = &GovernanceService{client: c}
c.Customers.Billing = &CustomersBillingService{client: c}
c.Customers.Credits = &CustomersCreditsService{client: c}
c.Customers.Charges = &CustomersChargesService{client: c}
c.Customers.Credits.Grants = &CustomersCreditsGrantsService{client: c}
c.Customers.Credits.Balance = &CustomersCreditsBalanceService{client: c}
c.Customers.Credits.Adjustments = &CustomersCreditsAdjustmentsService{client: c}
c.Customers.Credits.Transactions = &CustomersCreditsTransactionsService{client: c}
return c, nil
}
// resolve joins the client base URL with an API path, preserving any base path
// prefix and base query present on the base URL. apiPath is parsed so percent
// escapes already present in a segment, such as an ID escaped by
// replacePathParam, are carried through on RawPath instead of being
// re-escaped.
func (c *Client) resolve(apiPath string) *url.URL {
base := *c.baseURL
if !strings.HasSuffix(base.Path, "/") {
base.Path += "/"
}
trimmed := strings.TrimPrefix(apiPath, "/")
ref, err := url.Parse(trimmed)
if err != nil {
ref = &url.URL{Path: trimmed}
}
resolved := base.ResolveReference(ref)
resolved.RawQuery = base.RawQuery
return resolved
}
func replacePathParam(path, name, value string) string {
return strings.ReplaceAll(path, "{"+name+"}", url.PathEscape(value))
}