Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(api): update via SDK Studio #1946

Merged
merged 1 commit into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions workers/aigateway.go → ai_gateway/aigateway.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

package workers
package ai_gateway

import (
"context"
Expand All @@ -23,7 +23,7 @@ import (
// service directly, and instead use the [NewAIGatewayService] method instead.
type AIGatewayService struct {
Options []option.RequestOption
Logs *AIGatewayLogService
Logs *LogService
}

// NewAIGatewayService generates a new service that applies the given options to
Expand All @@ -32,7 +32,7 @@ type AIGatewayService struct {
func NewAIGatewayService(opts ...option.RequestOption) (r *AIGatewayService) {
r = &AIGatewayService{}
r.Options = opts
r.Logs = NewAIGatewayLogService(opts...)
r.Logs = NewLogService(opts...)
return
}

Expand Down
20 changes: 10 additions & 10 deletions workers/aigateway_test.go → ai_gateway/aigateway_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

package workers_test
package ai_gateway_test

import (
"context"
Expand All @@ -9,9 +9,9 @@ import (
"testing"

"github.com/cloudflare/cloudflare-go/v2"
"github.com/cloudflare/cloudflare-go/v2/ai_gateway"
"github.com/cloudflare/cloudflare-go/v2/internal/testutil"
"github.com/cloudflare/cloudflare-go/v2/option"
"github.com/cloudflare/cloudflare-go/v2/workers"
)

func TestAIGatewayNewWithOptionalParams(t *testing.T) {
Expand All @@ -27,10 +27,10 @@ func TestAIGatewayNewWithOptionalParams(t *testing.T) {
option.WithAPIKey("144c9defac04969c7bfad8efaa8ea194"),
option.WithAPIEmail("user@example.com"),
)
_, err := client.Workers.AI.Gateways.New(
_, err := client.AIGateway.New(
context.TODO(),
"0d37909e38d3e99c29fa2cd343ac421a",
workers.AIGatewayNewParams{
ai_gateway.AIGatewayNewParams{
CacheInvalidateOnUpdate: cloudflare.F(true),
CacheTTL: cloudflare.F(int64(0)),
CollectLogs: cloudflare.F(true),
Expand Down Expand Up @@ -63,11 +63,11 @@ func TestAIGatewayUpdateWithOptionalParams(t *testing.T) {
option.WithAPIKey("144c9defac04969c7bfad8efaa8ea194"),
option.WithAPIEmail("user@example.com"),
)
_, err := client.Workers.AI.Gateways.Update(
_, err := client.AIGateway.Update(
context.TODO(),
"0d37909e38d3e99c29fa2cd343ac421a",
"182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
workers.AIGatewayUpdateParams{
ai_gateway.AIGatewayUpdateParams{
CacheInvalidateOnUpdate: cloudflare.F(true),
CacheTTL: cloudflare.F(int64(0)),
CollectLogs: cloudflare.F(true),
Expand Down Expand Up @@ -100,10 +100,10 @@ func TestAIGatewayListWithOptionalParams(t *testing.T) {
option.WithAPIKey("144c9defac04969c7bfad8efaa8ea194"),
option.WithAPIEmail("user@example.com"),
)
_, err := client.Workers.AI.Gateways.List(
_, err := client.AIGateway.List(
context.TODO(),
"0d37909e38d3e99c29fa2cd343ac421a",
workers.AIGatewayListParams{
ai_gateway.AIGatewayListParams{
ID: cloudflare.F("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e"),
OrderBy: cloudflare.F("string"),
Page: cloudflare.F(int64(1)),
Expand Down Expand Up @@ -132,7 +132,7 @@ func TestAIGatewayDelete(t *testing.T) {
option.WithAPIKey("144c9defac04969c7bfad8efaa8ea194"),
option.WithAPIEmail("user@example.com"),
)
_, err := client.Workers.AI.Gateways.Delete(
_, err := client.AIGateway.Delete(
context.TODO(),
"0d37909e38d3e99c29fa2cd343ac421a",
"182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
Expand All @@ -159,7 +159,7 @@ func TestAIGatewayGet(t *testing.T) {
option.WithAPIKey("144c9defac04969c7bfad8efaa8ea194"),
option.WithAPIEmail("user@example.com"),
)
_, err := client.Workers.AI.Gateways.Get(
_, err := client.AIGateway.Get(
context.TODO(),
"0d37909e38d3e99c29fa2cd343ac421a",
"182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
Expand Down
115 changes: 115 additions & 0 deletions ai_gateway/aliases.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

package ai_gateway

import (
"github.com/cloudflare/cloudflare-go/v2/internal/apierror"
"github.com/cloudflare/cloudflare-go/v2/shared"
)

type Error = apierror.Error

// This is an alias to an internal type.
type ASN = shared.ASN

// This is an alias to an internal type.
type ASNParam = shared.ASNParam

// This is an alias to an internal type.
type AuditLog = shared.AuditLog

// This is an alias to an internal type.
type AuditLogAction = shared.AuditLogAction

// This is an alias to an internal type.
type AuditLogActor = shared.AuditLogActor

// The type of actor, whether a User, Cloudflare Admin, or an Automated System.
//
// This is an alias to an internal type.
type AuditLogActorType = shared.AuditLogActorType

// This is an alias to an internal value.
const AuditLogActorTypeUser = shared.AuditLogActorTypeUser

// This is an alias to an internal value.
const AuditLogActorTypeAdmin = shared.AuditLogActorTypeAdmin

// This is an alias to an internal value.
const AuditLogActorTypeCloudflare = shared.AuditLogActorTypeCloudflare

// This is an alias to an internal type.
type AuditLogOwner = shared.AuditLogOwner

// This is an alias to an internal type.
type AuditLogResource = shared.AuditLogResource

// A Cloudflare Tunnel that connects your origin to Cloudflare's edge.
//
// This is an alias to an internal type.
type CloudflareTunnel = shared.CloudflareTunnel

// This is an alias to an internal type.
type CloudflareTunnelConnection = shared.CloudflareTunnelConnection

// The type of tunnel.
//
// This is an alias to an internal type.
type CloudflareTunnelTunType = shared.CloudflareTunnelTunType

// This is an alias to an internal value.
const CloudflareTunnelTunTypeCfdTunnel = shared.CloudflareTunnelTunTypeCfdTunnel

// This is an alias to an internal value.
const CloudflareTunnelTunTypeWARPConnector = shared.CloudflareTunnelTunTypeWARPConnector

// This is an alias to an internal value.
const CloudflareTunnelTunTypeIPSec = shared.CloudflareTunnelTunTypeIPSec

// This is an alias to an internal value.
const CloudflareTunnelTunTypeGRE = shared.CloudflareTunnelTunTypeGRE

// This is an alias to an internal value.
const CloudflareTunnelTunTypeCNI = shared.CloudflareTunnelTunTypeCNI

// This is an alias to an internal type.
type ErrorData = shared.ErrorData

// This is an alias to an internal type.
type Member = shared.Member

// This is an alias to an internal type.
type MemberRole = shared.MemberRole

// This is an alias to an internal type.
type MemberRolesPermissions = shared.MemberRolesPermissions

// This is an alias to an internal type.
type MemberUser = shared.MemberUser

// This is an alias to an internal type.
type MemberParam = shared.MemberParam

// This is an alias to an internal type.
type MemberRoleParam = shared.MemberRoleParam

// This is an alias to an internal type.
type MemberRolesPermissionsParam = shared.MemberRolesPermissionsParam

// This is an alias to an internal type.
type MemberUserParam = shared.MemberUserParam

// This is an alias to an internal type.
type Permission = shared.Permission

// This is an alias to an internal type.
type PermissionGrant = shared.PermissionGrant

// This is an alias to an internal type.
type PermissionGrantParam = shared.PermissionGrantParam

// This is an alias to an internal type.
type ResponseInfo = shared.ResponseInfo

// This is an alias to an internal type.
type Role = shared.Role
162 changes: 162 additions & 0 deletions ai_gateway/log.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

package ai_gateway

import (
"context"
"fmt"
"net/http"
"net/url"
"time"

"github.com/cloudflare/cloudflare-go/v2/internal/apijson"
"github.com/cloudflare/cloudflare-go/v2/internal/apiquery"
"github.com/cloudflare/cloudflare-go/v2/internal/param"
"github.com/cloudflare/cloudflare-go/v2/internal/requestconfig"
"github.com/cloudflare/cloudflare-go/v2/option"
)

// LogService contains methods and other services that help with interacting with
// the cloudflare 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 [NewLogService] method instead.
type LogService struct {
Options []option.RequestOption
}

// NewLogService 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 NewLogService(opts ...option.RequestOption) (r *LogService) {
r = &LogService{}
r.Options = opts
return
}

// List Gateway Logs
func (r *LogService) Get(ctx context.Context, accountTag string, id string, query LogGetParams, opts ...option.RequestOption) (res *[]LogGetResponse, err error) {
opts = append(r.Options[:], opts...)
var env LogGetResponseEnvelope
path := fmt.Sprintf("accounts/%s/ai-gateway/gateways/%s/logs", accountTag, id)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, query, &env, opts...)
if err != nil {
return
}
res = &env.Result
return
}

type LogGetResponse struct {
ID string `json:"id,required" format:"uuid"`
Cached bool `json:"cached,required"`
CreatedAt time.Time `json:"created_at,required" format:"date-time"`
Duration int64 `json:"duration,required"`
Model string `json:"model,required"`
Path string `json:"path,required"`
Provider string `json:"provider,required"`
Request string `json:"request,required"`
Response string `json:"response,required"`
Success bool `json:"success,required"`
TokensIn int64 `json:"tokens_in,required"`
TokensOut int64 `json:"tokens_out,required"`
JSON logGetResponseJSON `json:"-"`
}

// logGetResponseJSON contains the JSON metadata for the struct [LogGetResponse]
type logGetResponseJSON struct {
ID apijson.Field
Cached apijson.Field
CreatedAt apijson.Field
Duration apijson.Field
Model apijson.Field
Path apijson.Field
Provider apijson.Field
Request apijson.Field
Response apijson.Field
Success apijson.Field
TokensIn apijson.Field
TokensOut apijson.Field
raw string
ExtraFields map[string]apijson.Field
}

func (r *LogGetResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}

func (r logGetResponseJSON) RawJSON() string {
return r.raw
}

type LogGetParams struct {
Cached param.Field[bool] `query:"cached"`
Direction param.Field[LogGetParamsDirection] `query:"direction"`
EndDate param.Field[time.Time] `query:"end_date" format:"date-time"`
OrderBy param.Field[LogGetParamsOrderBy] `query:"order_by"`
Page param.Field[int64] `query:"page"`
PerPage param.Field[int64] `query:"per_page"`
Search param.Field[string] `query:"search"`
StartDate param.Field[time.Time] `query:"start_date" format:"date-time"`
Success param.Field[bool] `query:"success"`
}

// URLQuery serializes [LogGetParams]'s query parameters as `url.Values`.
func (r LogGetParams) URLQuery() (v url.Values) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatRepeat,
NestedFormat: apiquery.NestedQueryFormatBrackets,
})
}

type LogGetParamsDirection string

const (
LogGetParamsDirectionAsc LogGetParamsDirection = "asc"
LogGetParamsDirectionDesc LogGetParamsDirection = "desc"
)

func (r LogGetParamsDirection) IsKnown() bool {
switch r {
case LogGetParamsDirectionAsc, LogGetParamsDirectionDesc:
return true
}
return false
}

type LogGetParamsOrderBy string

const (
LogGetParamsOrderByCreatedAt LogGetParamsOrderBy = "created_at"
LogGetParamsOrderByProvider LogGetParamsOrderBy = "provider"
)

func (r LogGetParamsOrderBy) IsKnown() bool {
switch r {
case LogGetParamsOrderByCreatedAt, LogGetParamsOrderByProvider:
return true
}
return false
}

type LogGetResponseEnvelope struct {
Result []LogGetResponse `json:"result,required"`
Success bool `json:"success,required"`
JSON logGetResponseEnvelopeJSON `json:"-"`
}

// logGetResponseEnvelopeJSON contains the JSON metadata for the struct
// [LogGetResponseEnvelope]
type logGetResponseEnvelopeJSON struct {
Result apijson.Field
Success apijson.Field
raw string
ExtraFields map[string]apijson.Field
}

func (r *LogGetResponseEnvelope) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}

func (r logGetResponseEnvelopeJSON) RawJSON() string {
return r.raw
}
Loading