Skip to content

Commit

Permalink
Reformatted endpoint functions to simplify them (#668)
Browse files Browse the repository at this point in the history
  • Loading branch information
ezilber-akamai authored Feb 4, 2025
1 parent 78fa5ac commit 72f6203
Show file tree
Hide file tree
Showing 70 changed files with 323 additions and 1,294 deletions.
3 changes: 1 addition & 2 deletions account_agreements.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,5 @@ func (c *Client) GetAccountAgreements(ctx context.Context) (*AccountAgreements,

// AcknowledgeAccountAgreements acknowledges account agreements for the Account
func (c *Client) AcknowledgeAccountAgreements(ctx context.Context, opts AccountAgreementsUpdateOptions) error {
_, err := doPOSTRequest[AccountAgreements](ctx, c, "account/agreements", opts)
return err
return doPOSTRequestNoResponseBody(ctx, c, "account/agreements", opts)
}
14 changes: 2 additions & 12 deletions account_availability.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,11 @@ type AccountAvailability struct {

// ListAccountAvailabilities lists all regions and the resource availabilities to the account.
func (c *Client) ListAccountAvailabilities(ctx context.Context, opts *ListOptions) ([]AccountAvailability, error) {
response, err := getPaginatedResults[AccountAvailability](ctx, c, "account/availability", opts)
if err != nil {
return nil, err
}

return response, nil
return getPaginatedResults[AccountAvailability](ctx, c, "account/availability", opts)
}

// GetAccountAvailability gets the resources availability in a region to the customer.
func (c *Client) GetAccountAvailability(ctx context.Context, regionID string) (*AccountAvailability, error) {
b := formatAPIPath("account/availability/%s", regionID)
response, err := doGETRequest[AccountAvailability](ctx, c, b)
if err != nil {
return nil, err
}

return response, nil
return doGETRequest[AccountAvailability](ctx, c, b)
}
25 changes: 4 additions & 21 deletions account_betas.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,33 +51,16 @@ func (cBeta *AccountBetaProgram) UnmarshalJSON(b []byte) error {

// ListAccountBetaPrograms lists all beta programs an account is enrolled in.
func (c *Client) ListAccountBetaPrograms(ctx context.Context, opts *ListOptions) ([]AccountBetaProgram, error) {
response, err := getPaginatedResults[AccountBetaProgram](ctx, c, "/account/betas", opts)
if err != nil {
return nil, err
}

return response, nil
return getPaginatedResults[AccountBetaProgram](ctx, c, "/account/betas", opts)
}

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

response, err := doGETRequest[AccountBetaProgram](ctx, c, b)
if err != nil {
return nil, err
}

return response, nil
e := formatAPIPath("/account/betas/%s", betaID)
return doGETRequest[AccountBetaProgram](ctx, c, e)
}

// JoinBetaProgram enrolls an account into a beta program.
func (c *Client) JoinBetaProgram(ctx context.Context, opts AccountBetaProgramCreateOpts) (*AccountBetaProgram, error) {
e := "account/betas"
response, err := doPOSTRequest[AccountBetaProgram](ctx, c, e, opts)
if err != nil {
return nil, err
}

return response, nil
return doPOSTRequest[AccountBetaProgram](ctx, c, "account/betas", opts)
}
20 changes: 4 additions & 16 deletions account_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,35 +300,23 @@ func (i *Event) UnmarshalJSON(b []byte) error {
// on the Account. The Events returned depend on the token grants and the grants
// of the associated user.
func (c *Client) ListEvents(ctx context.Context, opts *ListOptions) ([]Event, error) {
response, err := getPaginatedResults[Event](ctx, c, "account/events", opts)
if err != nil {
return nil, err
}

return response, nil
return getPaginatedResults[Event](ctx, c, "account/events", opts)
}

// GetEvent gets the Event with the Event ID
func (c *Client) GetEvent(ctx context.Context, eventID int) (*Event, error) {
e := formatAPIPath("account/events/%d", eventID)
response, err := doGETRequest[Event](ctx, c, e)
if err != nil {
return nil, err
}

return response, nil
return doGETRequest[Event](ctx, c, e)
}

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

// 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 := formatAPIPath("account/events/%d/seen", event.ID)
_, err := doPOSTRequest[Event](ctx, c, e, []any{})
return err
return doPOSTRequestNoRequestResponseBody(ctx, c, e)
}
21 changes: 3 additions & 18 deletions account_invoices.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,7 @@ type InvoiceItem struct {

// ListInvoices gets a paginated list of Invoices against the Account
func (c *Client) ListInvoices(ctx context.Context, opts *ListOptions) ([]Invoice, error) {
response, err := getPaginatedResults[Invoice](ctx, c, "account/invoices", opts)
if err != nil {
return nil, err
}

return response, nil
return getPaginatedResults[Invoice](ctx, c, "account/invoices", opts)
}

// UnmarshalJSON implements the json.Unmarshaler interface
Expand Down Expand Up @@ -94,20 +89,10 @@ 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 := formatAPIPath("account/invoices/%d", invoiceID)
response, err := doGETRequest[Invoice](ctx, c, e)
if err != nil {
return nil, err
}

return response, nil
return doGETRequest[Invoice](ctx, c, e)
}

// 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, formatAPIPath("account/invoices/%d/items", invoiceID), opts)
if err != nil {
return nil, err
}

return response, nil
return getPaginatedResults[InvoiceItem](ctx, c, formatAPIPath("account/invoices/%d/items", invoiceID), opts)
}
15 changes: 2 additions & 13 deletions account_logins.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,7 @@ type Login struct {
}

func (c *Client) ListLogins(ctx context.Context, opts *ListOptions) ([]Login, error) {
response, err := getPaginatedResults[Login](ctx, c, "account/logins", opts)
if err != nil {
return nil, err
}

return response, nil
return getPaginatedResults[Login](ctx, c, "account/logins", opts)
}

// UnmarshalJSON implements the json.Unmarshaler interface
Expand All @@ -48,11 +43,5 @@ func (i *Login) UnmarshalJSON(b []byte) error {

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

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

return response, nil
return doGETRequest[Login](ctx, c, e)
}
7 changes: 1 addition & 6 deletions account_notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,7 @@ const (
// have been resolved. For example, if the account has an important Ticket open, a response
// to the Ticket will dismiss the Notification.
func (c *Client) ListNotifications(ctx context.Context, opts *ListOptions) ([]Notification, error) {
response, err := getPaginatedResults[Notification](ctx, c, "account/notifications", opts)
if err != nil {
return nil, err
}

return response, nil
return getPaginatedResults[Notification](ctx, c, "account/notifications", opts)
}

// UnmarshalJSON implements the json.Unmarshaler interface
Expand Down
39 changes: 6 additions & 33 deletions account_oauth_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,61 +82,34 @@ func (i OAuthClient) GetUpdateOptions() (o OAuthClientUpdateOptions) {

// ListOAuthClients lists OAuthClients
func (c *Client) ListOAuthClients(ctx context.Context, opts *ListOptions) ([]OAuthClient, error) {
response, err := getPaginatedResults[OAuthClient](ctx, c, "account/oauth-clients", opts)
if err != nil {
return nil, err
}

return response, nil
return getPaginatedResults[OAuthClient](ctx, c, "account/oauth-clients", opts)
}

// GetOAuthClient gets the OAuthClient with the provided ID
func (c *Client) GetOAuthClient(ctx context.Context, clientID string) (*OAuthClient, error) {
e := formatAPIPath("account/oauth-clients/%s", clientID)
response, err := doGETRequest[OAuthClient](ctx, c, e)
if err != nil {
return nil, err
}

return response, nil
return doGETRequest[OAuthClient](ctx, c, e)
}

// CreateOAuthClient creates an OAuthClient
func (c *Client) CreateOAuthClient(ctx context.Context, opts OAuthClientCreateOptions) (*OAuthClient, error) {
e := "account/oauth-clients"
response, err := doPOSTRequest[OAuthClient](ctx, c, e, opts)
if err != nil {
return nil, err
}

return response, nil
return doPOSTRequest[OAuthClient](ctx, c, "account/oauth-clients", opts)
}

// UpdateOAuthClient updates the OAuthClient with the specified id
func (c *Client) UpdateOAuthClient(ctx context.Context, clientID string, opts OAuthClientUpdateOptions) (*OAuthClient, error) {
e := formatAPIPath("account/oauth-clients/%s", clientID)
response, err := doPUTRequest[OAuthClient](ctx, c, e, opts)
if err != nil {
return nil, err
}

return response, nil
return doPUTRequest[OAuthClient](ctx, c, e, opts)
}

// DeleteOAuthClient deletes the OAuthClient with the specified id
func (c *Client) DeleteOAuthClient(ctx context.Context, clientID string) error {
e := formatAPIPath("account/oauth-clients/%s", clientID)
err := doDELETERequest(ctx, c, e)
return err
return doDELETERequest(ctx, c, e)
}

// ResetOAuthClientSecret resets the OAuth Client secret for a client with a specified id
func (c *Client) ResetOAuthClientSecret(ctx context.Context, clientID string) (*OAuthClient, error) {
e := formatAPIPath("account/oauth-clients/%s/reset-secret", clientID)
response, err := doPOSTRequest[OAuthClient, any](ctx, c, e)
if err != nil {
return nil, err
}

return response, nil
return doPOSTRequest[OAuthClient, any](ctx, c, e)
}
6 changes: 2 additions & 4 deletions account_payment_methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,11 @@ func (c *Client) DeletePaymentMethod(ctx context.Context, paymentMethodID int) e

// AddPaymentMethod adds the provided payment method to the account
func (c *Client) AddPaymentMethod(ctx context.Context, opts PaymentMethodCreateOptions) error {
_, err := doPOSTRequest[PaymentMethod, any](ctx, c, "account/payment-methods", opts)
return err
return doPOSTRequestNoResponseBody(ctx, c, "account/payment-methods", opts)
}

// SetDefaultPaymentMethod sets the payment method with the provided ID as the default
func (c *Client) SetDefaultPaymentMethod(ctx context.Context, paymentMethodID int) error {
e := formatAPIPath("account/payment-methods/%d", paymentMethodID)
_, err := doPOSTRequest[PaymentMethod, any](ctx, c, e)
return err
return doPOSTRequestNoRequestResponseBody(ctx, c, e)
}
22 changes: 3 additions & 19 deletions account_payments.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,32 +57,16 @@ func (i Payment) GetCreateOptions() (o PaymentCreateOptions) {

// ListPayments lists Payments
func (c *Client) ListPayments(ctx context.Context, opts *ListOptions) ([]Payment, error) {
response, err := getPaginatedResults[Payment](ctx, c, "account/payments", opts)
if err != nil {
return nil, err
}

return response, nil
return getPaginatedResults[Payment](ctx, c, "account/payments", opts)
}

// GetPayment gets the payment with the provided ID
func (c *Client) GetPayment(ctx context.Context, paymentID int) (*Payment, error) {
e := formatAPIPath("account/payments/%d", paymentID)
response, err := doGETRequest[Payment](ctx, c, e)
if err != nil {
return nil, err
}

return response, nil
return doGETRequest[Payment](ctx, c, e)
}

// CreatePayment creates a Payment
func (c *Client) CreatePayment(ctx context.Context, opts PaymentCreateOptions) (*Payment, error) {
e := "account/payments"
response, err := doPOSTRequest[Payment](ctx, c, e, opts)
if err != nil {
return nil, err
}

return response, nil
return doPOSTRequest[Payment](ctx, c, "account/payments", opts)
}
2 changes: 1 addition & 1 deletion account_promo_credits.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,5 @@ func (i *Promotion) UnmarshalJSON(b []byte) error {

// AddPromoCode adds the provided promo code to the account
func (c *Client) AddPromoCode(ctx context.Context, opts PromoCodeCreateOptions) (*Promotion, error) {
return doPOSTRequest[Promotion, any](ctx, c, "account/promo-codes", opts)
return doPOSTRequest[Promotion](ctx, c, "account/promo-codes", opts)
}
9 changes: 3 additions & 6 deletions account_service_transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ func (ast *AccountServiceTransfer) UnmarshalJSON(b []byte) error {

// ListAccountServiceTransfer gets a paginated list of AccountServiceTransfer for the Account.
func (c *Client) ListAccountServiceTransfer(ctx context.Context, opts *ListOptions) ([]AccountServiceTransfer, error) {
e := "account/service-transfers"
return getPaginatedResults[AccountServiceTransfer](ctx, c, e, opts)
return getPaginatedResults[AccountServiceTransfer](ctx, c, "account/service-transfers", opts)
}

// GetAccountServiceTransfer gets the details of the AccountServiceTransfer for the provided token.
Expand All @@ -82,16 +81,14 @@ func (c *Client) GetAccountServiceTransfer(ctx context.Context, token string) (*

// RequestAccountServiceTransfer creates a transfer request for the specified services.
func (c *Client) RequestAccountServiceTransfer(ctx context.Context, opts AccountServiceTransferRequestOptions) (*AccountServiceTransfer, error) {
e := "account/service-transfers"
return doPOSTRequest[AccountServiceTransfer](ctx, c, e, opts)
return doPOSTRequest[AccountServiceTransfer](ctx, c, "account/service-transfers", opts)
}

// AcceptAccountServiceTransfer accepts an AccountServiceTransfer for the provided token to
// receive the services included in the transfer to the Account.
func (c *Client) AcceptAccountServiceTransfer(ctx context.Context, token string) error {
e := formatAPIPath("account/service-transfers/%s/accept", token)
_, err := doPOSTRequest[AccountServiceTransfer, any](ctx, c, e)
return err
return doPOSTRequestNoRequestResponseBody(ctx, c, e)
}

// CancelAccountServiceTransfer cancels the AccountServiceTransfer for the provided token.
Expand Down
18 changes: 2 additions & 16 deletions account_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,10 @@ type AccountSettingsUpdateOptions struct {

// GetAccountSettings gets the account wide flags or plans that effect new resources
func (c *Client) GetAccountSettings(ctx context.Context) (*AccountSettings, error) {
e := "account/settings"

response, err := doGETRequest[AccountSettings](ctx, c, e)
if err != nil {
return nil, err
}

return response, nil
return doGETRequest[AccountSettings](ctx, c, "account/settings")
}

// UpdateAccountSettings updates the settings associated with the account
func (c *Client) UpdateAccountSettings(ctx context.Context, opts AccountSettingsUpdateOptions) (*AccountSettings, error) {
e := "account/settings"

response, err := doPUTRequest[AccountSettings](ctx, c, e, opts)
if err != nil {
return nil, err
}

return response, nil
return doPUTRequest[AccountSettings](ctx, c, "account/settings", opts)
}
9 changes: 1 addition & 8 deletions account_transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,5 @@ type AccountTransferRegion struct {

// GetAccountTransfer gets current Account's network utilization for the current month.
func (c *Client) GetAccountTransfer(ctx context.Context) (*AccountTransfer, error) {
e := "account/transfer"

response, err := doGETRequest[AccountTransfer](ctx, c, e)
if err != nil {
return nil, err
}

return response, nil
return doGETRequest[AccountTransfer](ctx, c, "account/transfer")
}
Loading

0 comments on commit 72f6203

Please sign in to comment.