Skip to content

Commit

Permalink
feat: generated
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-bot committed Feb 12, 2024
1 parent 908f5e7 commit 313d9b6
Show file tree
Hide file tree
Showing 7 changed files with 1 addition and 2,337 deletions.
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
configured_endpoints: 333
configured_endpoints: 326
254 changes: 0 additions & 254 deletions account.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,14 @@ package cloudflare

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

"github.com/cloudflare/cloudflare-sdk-go/internal/apijson"
"github.com/cloudflare/cloudflare-sdk-go/internal/apiquery"
"github.com/cloudflare/cloudflare-sdk-go/internal/param"
"github.com/cloudflare/cloudflare-sdk-go/internal/requestconfig"
"github.com/cloudflare/cloudflare-sdk-go/internal/shared"
"github.com/cloudflare/cloudflare-sdk-go/option"
"github.com/tidwall/gjson"
)

// AccountService contains methods and other services that help with interacting
Expand All @@ -35,32 +31,6 @@ func NewAccountService(opts ...option.RequestOption) (r *AccountService) {
return
}

// Get information about a specific account that you are a member of.
func (r *AccountService) Get(ctx context.Context, identifier interface{}, opts ...option.RequestOption) (res *AccountGetResponse, err error) {
opts = append(r.Options[:], opts...)
var env AccountGetResponseEnvelope
path := fmt.Sprintf("accounts/%v", identifier)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &env, opts...)
if err != nil {
return
}
res = &env.Result
return
}

// Update an existing account.
func (r *AccountService) Update(ctx context.Context, identifier interface{}, body AccountUpdateParams, opts ...option.RequestOption) (res *AccountUpdateResponse, err error) {
opts = append(r.Options[:], opts...)
var env AccountUpdateResponseEnvelope
path := fmt.Sprintf("accounts/%v", identifier)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPut, path, body, &env, opts...)
if err != nil {
return
}
res = &env.Result
return
}

// List all accounts you have ownership or verified access to.
func (r *AccountService) List(ctx context.Context, query AccountListParams, opts ...option.RequestOption) (res *[]AccountListResponse, err error) {
opts = append(r.Options[:], opts...)
Expand All @@ -74,232 +44,8 @@ func (r *AccountService) List(ctx context.Context, query AccountListParams, opts
return
}

// Union satisfied by [AccountGetResponseUnknown] or [shared.UnionString].
type AccountGetResponse interface {
ImplementsAccountGetResponse()
}

func init() {
apijson.RegisterUnion(
reflect.TypeOf((*AccountGetResponse)(nil)).Elem(),
"",
apijson.UnionVariant{
TypeFilter: gjson.String,
Type: reflect.TypeOf(shared.UnionString("")),
},
)
}

// Union satisfied by [AccountUpdateResponseUnknown] or [shared.UnionString].
type AccountUpdateResponse interface {
ImplementsAccountUpdateResponse()
}

func init() {
apijson.RegisterUnion(
reflect.TypeOf((*AccountUpdateResponse)(nil)).Elem(),
"",
apijson.UnionVariant{
TypeFilter: gjson.String,
Type: reflect.TypeOf(shared.UnionString("")),
},
)
}

type AccountListResponse = interface{}

type AccountGetResponseEnvelope struct {
Errors []AccountGetResponseEnvelopeErrors `json:"errors,required"`
Messages []AccountGetResponseEnvelopeMessages `json:"messages,required"`
Result AccountGetResponse `json:"result,required"`
// Whether the API call was successful
Success AccountGetResponseEnvelopeSuccess `json:"success,required"`
JSON accountGetResponseEnvelopeJSON `json:"-"`
}

// accountGetResponseEnvelopeJSON contains the JSON metadata for the struct
// [AccountGetResponseEnvelope]
type accountGetResponseEnvelopeJSON struct {
Errors apijson.Field
Messages apijson.Field
Result apijson.Field
Success apijson.Field
raw string
ExtraFields map[string]apijson.Field
}

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

type AccountGetResponseEnvelopeErrors struct {
Code int64 `json:"code,required"`
Message string `json:"message,required"`
JSON accountGetResponseEnvelopeErrorsJSON `json:"-"`
}

// accountGetResponseEnvelopeErrorsJSON contains the JSON metadata for the struct
// [AccountGetResponseEnvelopeErrors]
type accountGetResponseEnvelopeErrorsJSON struct {
Code apijson.Field
Message apijson.Field
raw string
ExtraFields map[string]apijson.Field
}

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

type AccountGetResponseEnvelopeMessages struct {
Code int64 `json:"code,required"`
Message string `json:"message,required"`
JSON accountGetResponseEnvelopeMessagesJSON `json:"-"`
}

// accountGetResponseEnvelopeMessagesJSON contains the JSON metadata for the struct
// [AccountGetResponseEnvelopeMessages]
type accountGetResponseEnvelopeMessagesJSON struct {
Code apijson.Field
Message apijson.Field
raw string
ExtraFields map[string]apijson.Field
}

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

// Whether the API call was successful
type AccountGetResponseEnvelopeSuccess bool

const (
AccountGetResponseEnvelopeSuccessTrue AccountGetResponseEnvelopeSuccess = true
)

type AccountUpdateParams struct {
// Account name
Name param.Field[string] `json:"name,required"`
// Account settings
Settings param.Field[AccountUpdateParamsSettings] `json:"settings"`
}

func (r AccountUpdateParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}

// Account settings
type AccountUpdateParamsSettings struct {
// Specifies the default nameservers to be used for new zones added to this
// account.
//
// - `cloudflare.standard` for Cloudflare-branded nameservers
// - `custom.account` for account custom nameservers
// - `custom.tenant` for tenant custom nameservers
//
// See
// [Custom Nameservers](https://developers.cloudflare.com/dns/additional-options/custom-nameservers/)
// for more information.
DefaultNameservers param.Field[AccountUpdateParamsSettingsDefaultNameservers] `json:"default_nameservers"`
// Indicates whether membership in this account requires that Two-Factor
// Authentication is enabled
EnforceTwofactor param.Field[bool] `json:"enforce_twofactor"`
// Indicates whether new zones should use the account-level custom nameservers by
// default
UseAccountCustomNsByDefault param.Field[bool] `json:"use_account_custom_ns_by_default"`
}

func (r AccountUpdateParamsSettings) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}

// Specifies the default nameservers to be used for new zones added to this
// account.
//
// - `cloudflare.standard` for Cloudflare-branded nameservers
// - `custom.account` for account custom nameservers
// - `custom.tenant` for tenant custom nameservers
//
// See
// [Custom Nameservers](https://developers.cloudflare.com/dns/additional-options/custom-nameservers/)
// for more information.
type AccountUpdateParamsSettingsDefaultNameservers string

const (
AccountUpdateParamsSettingsDefaultNameserversCloudflareStandard AccountUpdateParamsSettingsDefaultNameservers = "cloudflare.standard"
AccountUpdateParamsSettingsDefaultNameserversCustomAccount AccountUpdateParamsSettingsDefaultNameservers = "custom.account"
AccountUpdateParamsSettingsDefaultNameserversCustomTenant AccountUpdateParamsSettingsDefaultNameservers = "custom.tenant"
)

type AccountUpdateResponseEnvelope struct {
Errors []AccountUpdateResponseEnvelopeErrors `json:"errors,required"`
Messages []AccountUpdateResponseEnvelopeMessages `json:"messages,required"`
Result AccountUpdateResponse `json:"result,required"`
// Whether the API call was successful
Success AccountUpdateResponseEnvelopeSuccess `json:"success,required"`
JSON accountUpdateResponseEnvelopeJSON `json:"-"`
}

// accountUpdateResponseEnvelopeJSON contains the JSON metadata for the struct
// [AccountUpdateResponseEnvelope]
type accountUpdateResponseEnvelopeJSON struct {
Errors apijson.Field
Messages apijson.Field
Result apijson.Field
Success apijson.Field
raw string
ExtraFields map[string]apijson.Field
}

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

type AccountUpdateResponseEnvelopeErrors struct {
Code int64 `json:"code,required"`
Message string `json:"message,required"`
JSON accountUpdateResponseEnvelopeErrorsJSON `json:"-"`
}

// accountUpdateResponseEnvelopeErrorsJSON contains the JSON metadata for the
// struct [AccountUpdateResponseEnvelopeErrors]
type accountUpdateResponseEnvelopeErrorsJSON struct {
Code apijson.Field
Message apijson.Field
raw string
ExtraFields map[string]apijson.Field
}

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

type AccountUpdateResponseEnvelopeMessages struct {
Code int64 `json:"code,required"`
Message string `json:"message,required"`
JSON accountUpdateResponseEnvelopeMessagesJSON `json:"-"`
}

// accountUpdateResponseEnvelopeMessagesJSON contains the JSON metadata for the
// struct [AccountUpdateResponseEnvelopeMessages]
type accountUpdateResponseEnvelopeMessagesJSON struct {
Code apijson.Field
Message apijson.Field
raw string
ExtraFields map[string]apijson.Field
}

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

// Whether the API call was successful
type AccountUpdateResponseEnvelopeSuccess bool

const (
AccountUpdateResponseEnvelopeSuccessTrue AccountUpdateResponseEnvelopeSuccess = true
)

type AccountListParams struct {
// Direction to order results.
Direction param.Field[AccountListParamsDirection] `query:"direction"`
Expand Down
63 changes: 0 additions & 63 deletions account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,69 +13,6 @@ import (
"github.com/cloudflare/cloudflare-sdk-go/option"
)

func TestAccountGet(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 {
baseURL = envURL
}
if !testutil.CheckTestServer(t, baseURL) {
return
}
client := cloudflare.NewClient(
option.WithBaseURL(baseURL),
option.WithAPIKey("144c9defac04969c7bfad8efaa8ea194"),
option.WithAPIEmail("dev@cloudflare.com"),
option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"),
option.WithUserServiceKey("My User Service Key"),
)
_, err := client.Accounts.Get(context.TODO(), map[string]interface{}{})
if err != nil {
var apierr *cloudflare.Error
if errors.As(err, &apierr) {
t.Log(string(apierr.DumpRequest(true)))
}
t.Fatalf("err should be nil: %s", err.Error())
}
}

func TestAccountUpdateWithOptionalParams(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 {
baseURL = envURL
}
if !testutil.CheckTestServer(t, baseURL) {
return
}
client := cloudflare.NewClient(
option.WithBaseURL(baseURL),
option.WithAPIKey("144c9defac04969c7bfad8efaa8ea194"),
option.WithAPIEmail("dev@cloudflare.com"),
option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"),
option.WithUserServiceKey("My User Service Key"),
)
_, err := client.Accounts.Update(
context.TODO(),
map[string]interface{}{},
cloudflare.AccountUpdateParams{
Name: cloudflare.F("Demo Account"),
Settings: cloudflare.F(cloudflare.AccountUpdateParamsSettings{
DefaultNameservers: cloudflare.F(cloudflare.AccountUpdateParamsSettingsDefaultNameserversCloudflareStandard),
EnforceTwofactor: cloudflare.F(true),
UseAccountCustomNsByDefault: cloudflare.F(true),
}),
},
)
if err != nil {
var apierr *cloudflare.Error
if errors.As(err, &apierr) {
t.Log(string(apierr.DumpRequest(true)))
}
t.Fatalf("err should be nil: %s", err.Error())
}
}

func TestAccountListWithOptionalParams(t *testing.T) {
t.Skip("skipped: tests are disabled for the time being")
baseURL := "http://localhost:4010"
Expand Down
Loading

0 comments on commit 313d9b6

Please sign in to comment.