Skip to content

Commit

Permalink
Merge pull request #386 from linode/proj/dc-specific-pricing
Browse files Browse the repository at this point in the history
project: DC-Specific Pricing Support
  • Loading branch information
lgarber-akamai authored Oct 2, 2023
2 parents 07730c0 + 086c49c commit 96af46f
Show file tree
Hide file tree
Showing 6 changed files with 415 additions and 13 deletions.
2 changes: 2 additions & 0 deletions account_invoices.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ type InvoiceItem struct {
UnitPrice int `json:"unitprice"`
Quantity int `json:"quantity"`
Amount float32 `json:"amount"`
Tax float32 `json:"tax"`
Region *string `json:"region"`
From *time.Time `json:"-"`
To *time.Time `json:"-"`
}
Expand Down
33 changes: 33 additions & 0 deletions account_transfer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package linodego

import "context"

// AccountTransfer represents an Account's network utilization for the current month.
type AccountTransfer struct {
Billable int `json:"billable"`
Quota int `json:"quota"`
Used int `json:"used"`

RegionTransfers []AccountTransferRegion `json:"region_transfers"`
}

// AccountTransferRegion represents an Account's network utilization for the current month
// in a given region.
type AccountTransferRegion struct {
ID string `json:"id"`
Billable int `json:"billable"`
Quota int `json:"quota"`
Used int `json:"used"`
}

// GetAccountTransfer gets current Account's network utilization for the current month.
func (c *Client) GetAccountTransfer(ctx context.Context) (*AccountTransfer, error) {
req := c.R(ctx).SetResult(&AccountTransfer{})
e := "account/transfer"
r, err := coupleAPIErrors(req.Get(e))
if err != nil {
return nil, err
}

return r.Result().(*AccountTransfer), nil
}
41 changes: 41 additions & 0 deletions test/integration/account_transfer_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package integration

import (
"context"
"reflect"
"testing"

"github.com/google/go-cmp/cmp"
"github.com/jarcoal/httpmock"
"github.com/linode/linodego"
)

func TestAccount_getTransfer(t *testing.T) {
client := createMockClient(t)

desiredResponse := linodego.AccountTransfer{
Billable: 123,
Quota: 456,
Used: 789,
RegionTransfers: []linodego.AccountTransferRegion{
{
ID: "us-southeast",
Billable: 987,
Quota: 654,
Used: 3211,
},
},
}

httpmock.RegisterRegexpResponder("GET", mockRequestURL(t, "/account/transfer"),
httpmock.NewJsonResponderOrPanic(200, &desiredResponse))

questions, err := client.GetAccountTransfer(context.Background())
if err != nil {
t.Fatal(err)
}

if !reflect.DeepEqual(*questions, desiredResponse) {
t.Fatalf("actual response does not equal desired response: %s", cmp.Diff(questions, desiredResponse))
}
}
Loading

0 comments on commit 96af46f

Please sign in to comment.