Skip to content

Commit

Permalink
feat(api): update via SDK Studio (#1704)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] authored Apr 9, 2024
1 parent e65fb3d commit e180174
Show file tree
Hide file tree
Showing 28 changed files with 1,677 additions and 1,697 deletions.
90 changes: 49 additions & 41 deletions api.md

Large diffs are not rendered by default.

118 changes: 64 additions & 54 deletions intel/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/cloudflare/cloudflare-go/v2/internal/apijson"
"github.com/cloudflare/cloudflare-go/v2/internal/apiquery"
"github.com/cloudflare/cloudflare-go/v2/internal/pagination"
"github.com/cloudflare/cloudflare-go/v2/internal/param"
"github.com/cloudflare/cloudflare-go/v2/internal/requestconfig"
"github.com/cloudflare/cloudflare-go/v2/internal/shared"
Expand All @@ -35,16 +36,26 @@ func NewDNSService(opts ...option.RequestOption) (r *DNSService) {
}

// Get Passive DNS by IP
func (r *DNSService) Get(ctx context.Context, params DNSGetParams, opts ...option.RequestOption) (res *DNS, err error) {
opts = append(r.Options[:], opts...)
var env DNSGetResponseEnvelope
func (r *DNSService) List(ctx context.Context, params DNSListParams, opts ...option.RequestOption) (res *pagination.V4PagePagination[DNSListResponse], err error) {
var raw *http.Response
opts = append(r.Options, opts...)
opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...)
path := fmt.Sprintf("accounts/%s/intel/dns", params.AccountID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, params, &env, opts...)
cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, params, &res, opts...)
if err != nil {
return
return nil, err
}
res = &env.Result
return
err = cfg.Execute()
if err != nil {
return nil, err
}
res.SetPageConfig(cfg, raw)
return res, nil
}

// Get Passive DNS by IP
func (r *DNSService) ListAutoPaging(ctx context.Context, params DNSListParams, opts ...option.RequestOption) *pagination.V4PagePaginationAutoPager[DNSListResponse] {
return pagination.NewV4PagePaginationAutoPager(r.List(ctx, params, opts...))
}

type DNS struct {
Expand Down Expand Up @@ -120,53 +131,17 @@ func (r unnamedSchemaRefB5e16cee4f32382c294201aedb9fc050JSON) RawJSON() string {
return r.raw
}

type DNSGetParams struct {
// Identifier
AccountID param.Field[string] `path:"account_id,required"`
IPV4 param.Field[string] `query:"ipv4"`
// Requested page within paginated list of results.
Page param.Field[float64] `query:"page"`
// Maximum number of results requested.
PerPage param.Field[float64] `query:"per_page"`
StartEndParams param.Field[DNSGetParamsStartEndParams] `query:"start_end_params"`
}

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

type DNSGetParamsStartEndParams struct {
// Defaults to the current date.
End param.Field[time.Time] `query:"end" format:"date"`
// Defaults to 30 days before the end parameter value.
Start param.Field[time.Time] `query:"start" format:"date"`
}

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

type DNSGetResponseEnvelope struct {
type DNSListResponse struct {
Errors []shared.ResponseInfo `json:"errors,required"`
Messages []shared.ResponseInfo `json:"messages,required"`
Result DNS `json:"result,required"`
// Whether the API call was successful
Success DNSGetResponseEnvelopeSuccess `json:"success,required"`
JSON dnsGetResponseEnvelopeJSON `json:"-"`
Success DNSListResponseSuccess `json:"success,required"`
JSON dnsListResponseJSON `json:"-"`
}

// dnsGetResponseEnvelopeJSON contains the JSON metadata for the struct
// [DNSGetResponseEnvelope]
type dnsGetResponseEnvelopeJSON struct {
// dnsListResponseJSON contains the JSON metadata for the struct [DNSListResponse]
type dnsListResponseJSON struct {
Errors apijson.Field
Messages apijson.Field
Result apijson.Field
Expand All @@ -175,25 +150,60 @@ type dnsGetResponseEnvelopeJSON struct {
ExtraFields map[string]apijson.Field
}

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

func (r dnsGetResponseEnvelopeJSON) RawJSON() string {
func (r dnsListResponseJSON) RawJSON() string {
return r.raw
}

// Whether the API call was successful
type DNSGetResponseEnvelopeSuccess bool
type DNSListResponseSuccess bool

const (
DNSGetResponseEnvelopeSuccessTrue DNSGetResponseEnvelopeSuccess = true
DNSListResponseSuccessTrue DNSListResponseSuccess = true
)

func (r DNSGetResponseEnvelopeSuccess) IsKnown() bool {
func (r DNSListResponseSuccess) IsKnown() bool {
switch r {
case DNSGetResponseEnvelopeSuccessTrue:
case DNSListResponseSuccessTrue:
return true
}
return false
}

type DNSListParams struct {
// Identifier
AccountID param.Field[string] `path:"account_id,required"`
IPV4 param.Field[string] `query:"ipv4"`
// Requested page within paginated list of results.
Page param.Field[float64] `query:"page"`
// Maximum number of results requested.
PerPage param.Field[float64] `query:"per_page"`
StartEndParams param.Field[DNSListParamsStartEndParams] `query:"start_end_params"`
}

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

type DNSListParamsStartEndParams struct {
// Defaults to the current date.
End param.Field[time.Time] `query:"end" format:"date"`
// Defaults to 30 days before the end parameter value.
Start param.Field[time.Time] `query:"start" format:"date"`
}

// URLQuery serializes [DNSListParamsStartEndParams]'s query parameters as
// `url.Values`.
func (r DNSListParamsStartEndParams) URLQuery() (v url.Values) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatRepeat,
NestedFormat: apiquery.NestedQueryFormatBrackets,
})
}
6 changes: 3 additions & 3 deletions intel/dns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/cloudflare/cloudflare-go/v2/option"
)

func TestDNSGetWithOptionalParams(t *testing.T) {
func TestDNSListWithOptionalParams(t *testing.T) {
t.Skip("skipped: tests are disabled for the time being")
baseURL := "http://localhost:4010"
if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
Expand All @@ -29,12 +29,12 @@ func TestDNSGetWithOptionalParams(t *testing.T) {
option.WithAPIKey("144c9defac04969c7bfad8efaa8ea194"),
option.WithAPIEmail("[email protected]"),
)
_, err := client.Intel.DNS.Get(context.TODO(), intel.DNSGetParams{
_, err := client.Intel.DNS.List(context.TODO(), intel.DNSListParams{
AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"),
IPV4: cloudflare.F("string"),
Page: cloudflare.F(1.000000),
PerPage: cloudflare.F(20.000000),
StartEndParams: cloudflare.F(intel.DNSGetParamsStartEndParams{
StartEndParams: cloudflare.F(intel.DNSListParamsStartEndParams{
End: cloudflare.F(time.Now()),
Start: cloudflare.F(time.Now()),
}),
Expand Down
2 changes: 1 addition & 1 deletion internal/shared/union.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ type UnionString string

func (UnionString) ImplementsSharedUnnamedSchemaRef9444735ca60712dbcf8afd832eb5716aUnion() {}
func (UnionString) ImplementsUserAuditLogListResponse() {}
func (UnionString) ImplementsUserLoadBalancerPoolHealthResponseUnion() {}
func (UnionString) ImplementsUserLoadBalancingPoolHealthResponseUnion() {}
func (UnionString) ImplementsZonesCustomNameserverUpdateResponseUnion() {}
func (UnionString) ImplementsZonesCustomNameserverGetResponseUnion() {}
func (UnionString) ImplementsLoadBalancersPoolHealthGetResponseUnion() {}
Expand Down
7 changes: 4 additions & 3 deletions load_balancers/preview.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/cloudflare/cloudflare-go/v2/internal/requestconfig"
"github.com/cloudflare/cloudflare-go/v2/internal/shared"
"github.com/cloudflare/cloudflare-go/v2/option"
"github.com/cloudflare/cloudflare-go/v2/user"
)

// PreviewService contains methods and other services that help with interacting
Expand All @@ -33,7 +32,7 @@ func NewPreviewService(opts ...option.RequestOption) (r *PreviewService) {
}

// Get the result of a previous preview operation using the provided preview_id.
func (r *PreviewService) Get(ctx context.Context, previewID string, query PreviewGetParams, opts ...option.RequestOption) (res *user.Preview, err error) {
func (r *PreviewService) Get(ctx context.Context, previewID string, query PreviewGetParams, opts ...option.RequestOption) (res *PreviewGetResponse, err error) {
opts = append(r.Options[:], opts...)
var env PreviewGetResponseEnvelope
path := fmt.Sprintf("accounts/%s/load_balancers/preview/%s", query.AccountID, previewID)
Expand All @@ -45,6 +44,8 @@ func (r *PreviewService) Get(ctx context.Context, previewID string, query Previe
return
}

type PreviewGetResponse map[string]PreviewGetResponse

type PreviewGetParams struct {
// Identifier
AccountID param.Field[string] `path:"account_id,required"`
Expand All @@ -54,7 +55,7 @@ type PreviewGetResponseEnvelope struct {
Errors []shared.ResponseInfo `json:"errors,required"`
Messages []shared.ResponseInfo `json:"messages,required"`
// Resulting health data from a preview operation.
Result user.Preview `json:"result,required"`
Result PreviewGetResponse `json:"result,required"`
// Whether the API call was successful
Success PreviewGetResponseEnvelopeSuccess `json:"success,required"`
JSON previewGetResponseEnvelopeJSON `json:"-"`
Expand Down
Loading

0 comments on commit e180174

Please sign in to comment.