Skip to content

Commit

Permalink
Merge branch 'main' into fix-deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
luthermonson committed Oct 5, 2023
2 parents 4e48706 + 96af46f commit 26e34c3
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 26e34c3

Please sign in to comment.