Skip to content

Commit

Permalink
Added pricing
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnSharpe committed Apr 15, 2024
1 parent bbf2806 commit e026e53
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 0 deletions.
10 changes: 10 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"regexp"
"strings"

"github.com/RedisLabs/rediscloud-go-api/service/pricing"

"github.com/RedisLabs/rediscloud-go-api/service/access_control_lists/redis_rules"
"github.com/RedisLabs/rediscloud-go-api/service/access_control_lists/roles"
"github.com/RedisLabs/rediscloud-go-api/service/access_control_lists/users"
Expand All @@ -32,6 +34,10 @@ type Client struct {
Regions *regions.API
LatestBackup *latest_backups.API
LatestImport *latest_imports.API
<<<<<<< Updated upstream
=======
Pricing *pricing.API
>>>>>>> Stashed changes
// acl
RedisRules *redis_rules.API
Roles *roles.API
Expand Down Expand Up @@ -71,6 +77,10 @@ func NewClient(configs ...Option) (*Client, error) {
Regions: regions.NewAPI(client, t, config.logger),
LatestBackup: latest_backups.NewAPI(client, t, config.logger),
LatestImport: latest_imports.NewAPI(client, t, config.logger),
<<<<<<< Updated upstream
=======
Pricing: pricing.NewAPI(client),
>>>>>>> Stashed changes
// acl
RedisRules: redis_rules.NewAPI(client, t, config.logger),
Roles: roles.NewAPI(client, t, config.logger),
Expand Down
52 changes: 52 additions & 0 deletions pricing_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package rediscloud_api

import (
"context"
"net/http/httptest"
"testing"

"github.com/stretchr/testify/require"
)

func TestGet(t *testing.T) {
server := httptest.NewServer(
testServer(
"key",
"secret",
getRequest(
t,
"/subscriptions/12/databases/34/pricing",
`[
{
"type": "Shards",
"typeDetails": "micro",
"quantity": 1,
"quantityMeasurement": "shards",
"pricePerUnit": 0.027,
"priceCurrency": "USD",
"pricePeriod": "hour"
},
[
{
"rel": "self",
"href": "https://api-staging.qa.redislabs.com/v1/subscriptions/110777/pricing",
"type": "GET"
}
]
]`,
),
))

subject, err := clientFromTestServer(server, "key", "secret")
require.NoError(t, err)

_, err = subject.Pricing.List(context.TODO(), 20000)
require.NoError(t, err)

//assert.Equal(t, &users.GetUserResponse{
// ID: redis.Int(20000),
// Name: redis.String("test-user"),
// Role: redis.String("test-role"),
// Status: redis.String(users.StatusPending),
//}, actual)
}
31 changes: 31 additions & 0 deletions service/pricing/model.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package pricing

import (
"fmt"

"github.com/RedisLabs/rediscloud-go-api/internal"
)

type Pricing struct {
DatabaseName *string `json:"databaseName,omitempty"`
Type *string `json:"type,omitempty"`
TypeDetails *string `json:"typeDetails,omitempty"`
Quantity *int `json:"quantity,omitempty"`
QuantityMeasurement *string `json:"quantityMeasurement,omitempty"`
PricePerUnit *float64 `json:"pricePerUnit,omitempty"`
PriceCurrency *string `json:"priceCurrency,omitempty"`
PricePeriod *string `json:"pricePeriod,omitempty"`
Region *string `json:"region,omitempty"`
}

func (o Pricing) String() string {
return internal.ToString(o)
}

type NotFound struct {
subId int
}

func (f *NotFound) Error() string {
return fmt.Sprintf("subscription %d not found", f.subId)
}
32 changes: 32 additions & 0 deletions service/pricing/service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package pricing

import (
"context"
"fmt"
)

type HttpClient interface {
Get(ctx context.Context, name, path string, responseBody interface{}) error
}

type API struct {
client HttpClient
}

func NewAPI(client HttpClient) *API {
return &API{client: client}
}

// List will return the list of available pricing detail blocks for the provided subscription.
func (a *API) List(ctx context.Context, subscription int) ([]*Pricing, error) {
var body []*Pricing

message := fmt.Sprintf("get pricing information for subscription %d", subscription)
address := fmt.Sprintf("/subscriptions/%d/pricing", subscription)

if err := a.client.Get(ctx, message, address, &body); err != nil {
return nil, err
}

return body, nil
}

0 comments on commit e026e53

Please sign in to comment.