Skip to content

Commit

Permalink
Utilized formatAPIPath helper
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikZilber committed Jun 18, 2024
1 parent af86f8c commit ac0c5c8
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 17 deletions.
5 changes: 1 addition & 4 deletions account_availability.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package linodego

import (
"context"
"fmt"
"net/url"
)

// AccountAvailability returns the resources availability in a region to an account.
Expand All @@ -30,8 +28,7 @@ func (c *Client) ListAccountAvailabilities(ctx context.Context, opts *ListOption

// GetAccountAvailability gets the resources availability in a region to the customer.
func (c *Client) GetAccountAvailability(ctx context.Context, regionID string) (*AccountAvailability, error) {
regionID = url.PathEscape(regionID)
b := fmt.Sprintf("account/availability/%s", regionID)
b := formatAPIPath("account/availability/%s", regionID)
response, err := doGETRequest[AccountAvailability](ctx, c, b)
if err != nil {
return nil, err
Expand Down
5 changes: 1 addition & 4 deletions account_betas.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package linodego
import (
"context"
"encoding/json"
"fmt"
"net/url"
"time"

"github.com/linode/linodego/internal/parseabletime"
Expand Down Expand Up @@ -63,8 +61,7 @@ func (c *Client) ListAccountBetaPrograms(ctx context.Context, opts *ListOptions)

// GetAccountBetaProgram gets the details of a beta program an account is enrolled in.
func (c *Client) GetAccountBetaProgram(ctx context.Context, betaID string) (*AccountBetaProgram, error) {
betaID = url.PathEscape(betaID)
b := fmt.Sprintf("/account/betas/%s", betaID)
b := formatAPIPath("/account/betas/%s", betaID)

response, err := doGETRequest[AccountBetaProgram](ctx, c, b)
if err != nil {
Expand Down
7 changes: 3 additions & 4 deletions account_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package linodego
import (
"context"
"encoding/json"
"fmt"
"time"

"github.com/linode/linodego/internal/duration"
Expand Down Expand Up @@ -297,7 +296,7 @@ func (c *Client) ListEvents(ctx context.Context, opts *ListOptions) ([]Event, er

// GetEvent gets the Event with the Event ID
func (c *Client) GetEvent(ctx context.Context, eventID int) (*Event, error) {
e := fmt.Sprintf("account/events/%d", eventID)
e := formatAPIPath("account/events/%d", eventID)
response, err := doGETRequest[Event](ctx, c, e)
if err != nil {
return nil, err
Expand All @@ -308,14 +307,14 @@ func (c *Client) GetEvent(ctx context.Context, eventID int) (*Event, error) {

// MarkEventRead marks a single Event as read.
func (c *Client) MarkEventRead(ctx context.Context, event *Event) error {
e := fmt.Sprintf("account/events/%d/read", event.ID)
e := formatAPIPath("account/events/%d/read", event.ID)
_, err := doPOSTRequest[Event](ctx, c, e, []any{})
return err
}

// MarkEventsSeen marks all Events up to and including this Event by ID as seen.
func (c *Client) MarkEventsSeen(ctx context.Context, event *Event) error {
e := fmt.Sprintf("account/events/%d/seen", event.ID)
e := formatAPIPath("account/events/%d/seen", event.ID)
_, err := doPOSTRequest[Event](ctx, c, e, []any{})
return err
}
5 changes: 2 additions & 3 deletions account_invoices.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package linodego
import (
"context"
"encoding/json"
"fmt"
"time"

"github.com/linode/linodego/internal/parseabletime"
Expand Down Expand Up @@ -84,7 +83,7 @@ func (i *InvoiceItem) UnmarshalJSON(b []byte) error {

// GetInvoice gets a single Invoice matching the provided ID
func (c *Client) GetInvoice(ctx context.Context, invoiceID int) (*Invoice, error) {
e := fmt.Sprintf("account/invoices/%d", invoiceID)
e := formatAPIPath("account/invoices/%d", invoiceID)
response, err := doGETRequest[Invoice](ctx, c, e)
if err != nil {
return nil, err
Expand All @@ -95,7 +94,7 @@ func (c *Client) GetInvoice(ctx context.Context, invoiceID int) (*Invoice, error

// ListInvoiceItems gets the invoice items associated with a specific Invoice
func (c *Client) ListInvoiceItems(ctx context.Context, invoiceID int, opts *ListOptions) ([]InvoiceItem, error) {
response, err := getPaginatedResults[InvoiceItem](ctx, c, fmt.Sprintf("account/invoices/%d/items", invoiceID), opts)
response, err := getPaginatedResults[InvoiceItem](ctx, c, formatAPIPath("account/invoices/%d/items", invoiceID), opts)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions account_logins.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package linodego
import (
"context"
"encoding/json"
"fmt"
"time"

"github.com/linode/linodego/internal/parseabletime"
Expand Down Expand Up @@ -48,7 +47,8 @@ func (i *Login) UnmarshalJSON(b []byte) error {
}

func (c *Client) GetLogin(ctx context.Context, loginID int) (*Login, error) {
e := fmt.Sprintf("account/logins/%d", loginID)
e := formatAPIPath("account/logins/%d", loginID)

response, err := doGETRequest[Login](ctx, c, e)
if err != nil {
return nil, err
Expand Down

0 comments on commit ac0c5c8

Please sign in to comment.