Skip to content

Commit

Permalink
Add support for GetConfig Admin API
Browse files Browse the repository at this point in the history
  • Loading branch information
const-cloudinary committed Aug 18, 2024
1 parent fa37a0e commit 586a79b
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
34 changes: 32 additions & 2 deletions api/admin/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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:"-"`
Expand Down
13 changes: 13 additions & 0 deletions api/admin/misc_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package admin_test

import (
"github.com/cloudinary/cloudinary-go/v2/api"
"github.com/stretchr/testify/assert"
"testing"
"time"

Expand All @@ -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{})

Expand Down

0 comments on commit 586a79b

Please sign in to comment.