Skip to content

Commit 72f6203

Browse files
Reformatted endpoint functions to simplify them (#668)
1 parent 78fa5ac commit 72f6203

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+323
-1294
lines changed

account_agreements.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,5 @@ func (c *Client) GetAccountAgreements(ctx context.Context) (*AccountAgreements,
3232

3333
// AcknowledgeAccountAgreements acknowledges account agreements for the Account
3434
func (c *Client) AcknowledgeAccountAgreements(ctx context.Context, opts AccountAgreementsUpdateOptions) error {
35-
_, err := doPOSTRequest[AccountAgreements](ctx, c, "account/agreements", opts)
36-
return err
35+
return doPOSTRequestNoResponseBody(ctx, c, "account/agreements", opts)
3736
}

account_availability.go

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,11 @@ type AccountAvailability struct {
1818

1919
// ListAccountAvailabilities lists all regions and the resource availabilities to the account.
2020
func (c *Client) ListAccountAvailabilities(ctx context.Context, opts *ListOptions) ([]AccountAvailability, error) {
21-
response, err := getPaginatedResults[AccountAvailability](ctx, c, "account/availability", opts)
22-
if err != nil {
23-
return nil, err
24-
}
25-
26-
return response, nil
21+
return getPaginatedResults[AccountAvailability](ctx, c, "account/availability", opts)
2722
}
2823

2924
// GetAccountAvailability gets the resources availability in a region to the customer.
3025
func (c *Client) GetAccountAvailability(ctx context.Context, regionID string) (*AccountAvailability, error) {
3126
b := formatAPIPath("account/availability/%s", regionID)
32-
response, err := doGETRequest[AccountAvailability](ctx, c, b)
33-
if err != nil {
34-
return nil, err
35-
}
36-
37-
return response, nil
27+
return doGETRequest[AccountAvailability](ctx, c, b)
3828
}

account_betas.go

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -51,33 +51,16 @@ func (cBeta *AccountBetaProgram) UnmarshalJSON(b []byte) error {
5151

5252
// ListAccountBetaPrograms lists all beta programs an account is enrolled in.
5353
func (c *Client) ListAccountBetaPrograms(ctx context.Context, opts *ListOptions) ([]AccountBetaProgram, error) {
54-
response, err := getPaginatedResults[AccountBetaProgram](ctx, c, "/account/betas", opts)
55-
if err != nil {
56-
return nil, err
57-
}
58-
59-
return response, nil
54+
return getPaginatedResults[AccountBetaProgram](ctx, c, "/account/betas", opts)
6055
}
6156

6257
// GetAccountBetaProgram gets the details of a beta program an account is enrolled in.
6358
func (c *Client) GetAccountBetaProgram(ctx context.Context, betaID string) (*AccountBetaProgram, error) {
64-
b := formatAPIPath("/account/betas/%s", betaID)
65-
66-
response, err := doGETRequest[AccountBetaProgram](ctx, c, b)
67-
if err != nil {
68-
return nil, err
69-
}
70-
71-
return response, nil
59+
e := formatAPIPath("/account/betas/%s", betaID)
60+
return doGETRequest[AccountBetaProgram](ctx, c, e)
7261
}
7362

7463
// JoinBetaProgram enrolls an account into a beta program.
7564
func (c *Client) JoinBetaProgram(ctx context.Context, opts AccountBetaProgramCreateOpts) (*AccountBetaProgram, error) {
76-
e := "account/betas"
77-
response, err := doPOSTRequest[AccountBetaProgram](ctx, c, e, opts)
78-
if err != nil {
79-
return nil, err
80-
}
81-
82-
return response, nil
65+
return doPOSTRequest[AccountBetaProgram](ctx, c, "account/betas", opts)
8366
}

account_events.go

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -300,35 +300,23 @@ func (i *Event) UnmarshalJSON(b []byte) error {
300300
// on the Account. The Events returned depend on the token grants and the grants
301301
// of the associated user.
302302
func (c *Client) ListEvents(ctx context.Context, opts *ListOptions) ([]Event, error) {
303-
response, err := getPaginatedResults[Event](ctx, c, "account/events", opts)
304-
if err != nil {
305-
return nil, err
306-
}
307-
308-
return response, nil
303+
return getPaginatedResults[Event](ctx, c, "account/events", opts)
309304
}
310305

311306
// GetEvent gets the Event with the Event ID
312307
func (c *Client) GetEvent(ctx context.Context, eventID int) (*Event, error) {
313308
e := formatAPIPath("account/events/%d", eventID)
314-
response, err := doGETRequest[Event](ctx, c, e)
315-
if err != nil {
316-
return nil, err
317-
}
318-
319-
return response, nil
309+
return doGETRequest[Event](ctx, c, e)
320310
}
321311

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

329318
// MarkEventsSeen marks all Events up to and including this Event by ID as seen.
330319
func (c *Client) MarkEventsSeen(ctx context.Context, event *Event) error {
331320
e := formatAPIPath("account/events/%d/seen", event.ID)
332-
_, err := doPOSTRequest[Event](ctx, c, e, []any{})
333-
return err
321+
return doPOSTRequestNoRequestResponseBody(ctx, c, e)
334322
}

account_invoices.go

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,7 @@ type InvoiceItem struct {
4141

4242
// ListInvoices gets a paginated list of Invoices against the Account
4343
func (c *Client) ListInvoices(ctx context.Context, opts *ListOptions) ([]Invoice, error) {
44-
response, err := getPaginatedResults[Invoice](ctx, c, "account/invoices", opts)
45-
if err != nil {
46-
return nil, err
47-
}
48-
49-
return response, nil
44+
return getPaginatedResults[Invoice](ctx, c, "account/invoices", opts)
5045
}
5146

5247
// UnmarshalJSON implements the json.Unmarshaler interface
@@ -94,20 +89,10 @@ func (i *InvoiceItem) UnmarshalJSON(b []byte) error {
9489
// GetInvoice gets a single Invoice matching the provided ID
9590
func (c *Client) GetInvoice(ctx context.Context, invoiceID int) (*Invoice, error) {
9691
e := formatAPIPath("account/invoices/%d", invoiceID)
97-
response, err := doGETRequest[Invoice](ctx, c, e)
98-
if err != nil {
99-
return nil, err
100-
}
101-
102-
return response, nil
92+
return doGETRequest[Invoice](ctx, c, e)
10393
}
10494

10595
// ListInvoiceItems gets the invoice items associated with a specific Invoice
10696
func (c *Client) ListInvoiceItems(ctx context.Context, invoiceID int, opts *ListOptions) ([]InvoiceItem, error) {
107-
response, err := getPaginatedResults[InvoiceItem](ctx, c, formatAPIPath("account/invoices/%d/items", invoiceID), opts)
108-
if err != nil {
109-
return nil, err
110-
}
111-
112-
return response, nil
97+
return getPaginatedResults[InvoiceItem](ctx, c, formatAPIPath("account/invoices/%d/items", invoiceID), opts)
11398
}

account_logins.go

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,7 @@ type Login struct {
1818
}
1919

2020
func (c *Client) ListLogins(ctx context.Context, opts *ListOptions) ([]Login, error) {
21-
response, err := getPaginatedResults[Login](ctx, c, "account/logins", opts)
22-
if err != nil {
23-
return nil, err
24-
}
25-
26-
return response, nil
21+
return getPaginatedResults[Login](ctx, c, "account/logins", opts)
2722
}
2823

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

4944
func (c *Client) GetLogin(ctx context.Context, loginID int) (*Login, error) {
5045
e := formatAPIPath("account/logins/%d", loginID)
51-
52-
response, err := doGETRequest[Login](ctx, c, e)
53-
if err != nil {
54-
return nil, err
55-
}
56-
57-
return response, nil
46+
return doGETRequest[Login](ctx, c, e)
5847
}

account_notifications.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,7 @@ const (
6262
// have been resolved. For example, if the account has an important Ticket open, a response
6363
// to the Ticket will dismiss the Notification.
6464
func (c *Client) ListNotifications(ctx context.Context, opts *ListOptions) ([]Notification, error) {
65-
response, err := getPaginatedResults[Notification](ctx, c, "account/notifications", opts)
66-
if err != nil {
67-
return nil, err
68-
}
69-
70-
return response, nil
65+
return getPaginatedResults[Notification](ctx, c, "account/notifications", opts)
7166
}
7267

7368
// UnmarshalJSON implements the json.Unmarshaler interface

account_oauth_client.go

Lines changed: 6 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -82,61 +82,34 @@ func (i OAuthClient) GetUpdateOptions() (o OAuthClientUpdateOptions) {
8282

8383
// ListOAuthClients lists OAuthClients
8484
func (c *Client) ListOAuthClients(ctx context.Context, opts *ListOptions) ([]OAuthClient, error) {
85-
response, err := getPaginatedResults[OAuthClient](ctx, c, "account/oauth-clients", opts)
86-
if err != nil {
87-
return nil, err
88-
}
89-
90-
return response, nil
85+
return getPaginatedResults[OAuthClient](ctx, c, "account/oauth-clients", opts)
9186
}
9287

9388
// GetOAuthClient gets the OAuthClient with the provided ID
9489
func (c *Client) GetOAuthClient(ctx context.Context, clientID string) (*OAuthClient, error) {
9590
e := formatAPIPath("account/oauth-clients/%s", clientID)
96-
response, err := doGETRequest[OAuthClient](ctx, c, e)
97-
if err != nil {
98-
return nil, err
99-
}
100-
101-
return response, nil
91+
return doGETRequest[OAuthClient](ctx, c, e)
10292
}
10393

10494
// CreateOAuthClient creates an OAuthClient
10595
func (c *Client) CreateOAuthClient(ctx context.Context, opts OAuthClientCreateOptions) (*OAuthClient, error) {
106-
e := "account/oauth-clients"
107-
response, err := doPOSTRequest[OAuthClient](ctx, c, e, opts)
108-
if err != nil {
109-
return nil, err
110-
}
111-
112-
return response, nil
96+
return doPOSTRequest[OAuthClient](ctx, c, "account/oauth-clients", opts)
11397
}
11498

11599
// UpdateOAuthClient updates the OAuthClient with the specified id
116100
func (c *Client) UpdateOAuthClient(ctx context.Context, clientID string, opts OAuthClientUpdateOptions) (*OAuthClient, error) {
117101
e := formatAPIPath("account/oauth-clients/%s", clientID)
118-
response, err := doPUTRequest[OAuthClient](ctx, c, e, opts)
119-
if err != nil {
120-
return nil, err
121-
}
122-
123-
return response, nil
102+
return doPUTRequest[OAuthClient](ctx, c, e, opts)
124103
}
125104

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

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

account_payment_methods.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,11 @@ func (c *Client) DeletePaymentMethod(ctx context.Context, paymentMethodID int) e
153153

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

160159
// SetDefaultPaymentMethod sets the payment method with the provided ID as the default
161160
func (c *Client) SetDefaultPaymentMethod(ctx context.Context, paymentMethodID int) error {
162161
e := formatAPIPath("account/payment-methods/%d", paymentMethodID)
163-
_, err := doPOSTRequest[PaymentMethod, any](ctx, c, e)
164-
return err
162+
return doPOSTRequestNoRequestResponseBody(ctx, c, e)
165163
}

account_payments.go

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -57,32 +57,16 @@ func (i Payment) GetCreateOptions() (o PaymentCreateOptions) {
5757

5858
// ListPayments lists Payments
5959
func (c *Client) ListPayments(ctx context.Context, opts *ListOptions) ([]Payment, error) {
60-
response, err := getPaginatedResults[Payment](ctx, c, "account/payments", opts)
61-
if err != nil {
62-
return nil, err
63-
}
64-
65-
return response, nil
60+
return getPaginatedResults[Payment](ctx, c, "account/payments", opts)
6661
}
6762

6863
// GetPayment gets the payment with the provided ID
6964
func (c *Client) GetPayment(ctx context.Context, paymentID int) (*Payment, error) {
7065
e := formatAPIPath("account/payments/%d", paymentID)
71-
response, err := doGETRequest[Payment](ctx, c, e)
72-
if err != nil {
73-
return nil, err
74-
}
75-
76-
return response, nil
66+
return doGETRequest[Payment](ctx, c, e)
7767
}
7868

7969
// CreatePayment creates a Payment
8070
func (c *Client) CreatePayment(ctx context.Context, opts PaymentCreateOptions) (*Payment, error) {
81-
e := "account/payments"
82-
response, err := doPOSTRequest[Payment](ctx, c, e, opts)
83-
if err != nil {
84-
return nil, err
85-
}
86-
87-
return response, nil
71+
return doPOSTRequest[Payment](ctx, c, "account/payments", opts)
8872
}

0 commit comments

Comments
 (0)