diff --git a/api/admin/misc.go b/api/admin/misc.go index bbdf1d6..d319035 100644 --- a/api/admin/misc.go +++ b/api/admin/misc.go @@ -8,8 +8,9 @@ import ( ) const ( - ping api.EndPoint = "ping" - usage api.EndPoint = "usage" + ping api.EndPoint = "ping" + cloudConfig api.EndPoint = "config" + usage api.EndPoint = "usage" ) // Ping tests the reachability of the Cloudinary API. @@ -29,6 +30,35 @@ type PingResult struct { Response interface{} } +// GetConfigParams are the parameters for GetConfig. +type GetConfigParams struct { + Settings *bool `json:"settings,omitempty"` +} + +// GetConfig gets cloud config details. +// +// https://cloudinary.com/documentation/admin_api#config +func (a *API) GetConfig(ctx context.Context, params GetConfigParams) (*GetConfigResult, error) { + res := &GetConfigResult{} + _, err := a.get(ctx, cloudConfig, params, res) + + return res, err +} + +// GetConfigResult represents the result of the GetConfig request. +type GetConfigResult struct { + CloudName string `json:"cloud_name"` + CreatedAt time.Time `json:"created_at"` + Settings CloudSettings `json:"settings"` + Error api.ErrorResp `json:"error,omitempty"` + Response interface{} +} + +// CloudSettings represents the settings of the cloud. +type CloudSettings struct { + FolderMode string `json:"folder_mode"` +} + // UsageParams are the parameters for Usage. type UsageParams struct { Date time.Time `json:"-"` diff --git a/api/admin/misc_test.go b/api/admin/misc_test.go index 70a191f..9f9550f 100644 --- a/api/admin/misc_test.go +++ b/api/admin/misc_test.go @@ -1,6 +1,8 @@ package admin_test import ( + "github.com/cloudinary/cloudinary-go/v2/api" + "github.com/stretchr/testify/assert" "testing" "time" @@ -21,6 +23,17 @@ func TestAdmin_Ping(t *testing.T) { } } +func TestAdmin_GetConfig(t *testing.T) { + resp, err := adminAPI.GetConfig(ctx, admin.GetConfigParams{Settings: api.Bool(true)}) + + if err != nil || resp.Error.Message != "" { + t.Error(resp) + } + + assert.Equal(t, adminAPI.Config.Cloud.CloudName, resp.CloudName) + assert.NotEmpty(t, resp.Settings.FolderMode) +} + func TestAdmin_Usage(t *testing.T) { resp, err := adminAPI.Usage(ctx, admin.UsageParams{})