Skip to content

Commit

Permalink
Added Response var to funcs
Browse files Browse the repository at this point in the history
  • Loading branch information
mondragonfx committed Jan 31, 2023
1 parent 5a30f05 commit 2ba0ed6
Show file tree
Hide file tree
Showing 52 changed files with 1,071 additions and 931 deletions.
13 changes: 7 additions & 6 deletions account.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
// AccountService is the interface to interact with Accounts endpoint on the Vultr API
// Link : https://www.vultr.com/api/#tag/account
type AccountService interface {
Get(ctx context.Context) (*Account, error)
Get(ctx context.Context) (*Account, *http.Response, error)
}

// AccountServiceHandler handles interaction with the account methods for the Vultr API
Expand All @@ -32,17 +32,18 @@ type Account struct {
}

// Get Vultr account info
func (a *AccountServiceHandler) Get(ctx context.Context) (*Account, error) {
func (a *AccountServiceHandler) Get(ctx context.Context) (*Account, *http.Response, error) {
uri := "/v2/account"
req, err := a.client.NewRequest(ctx, http.MethodGet, uri, nil)
if err != nil {
return nil, err
return nil, nil, err
}

account := new(accountBase)
if err = a.client.DoWithContext(ctx, req, account); err != nil {
return nil, err
resp, err := a.client.DoWithContext(ctx, req, account)
if err != nil {
return nil,resp, err
}

return account.Account, nil
return account.Account, resp, nil
}
3 changes: 2 additions & 1 deletion account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ func TestAccountServiceHandler_Get(t *testing.T) {
fmt.Fprint(w, response)
})

account, err := client.Account.Get(ctx)
account, _, err := client.Account.Get(ctx)
if err != nil {
t.Errorf("Account.Get returned error: %v", err)
}


expected := &Account{Balance: -5519.11, PendingCharges: 57.03, LastPaymentDate: "2014-07-18 15:31:01", LastPaymentAmount: -1.00, Name: "Test Tester", Email: "[email protected]", ACL: []string{"subscriptions", "billing", "support", "provisioning"}}

if !reflect.DeepEqual(account, expected) {
Expand Down
14 changes: 7 additions & 7 deletions application.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
// ApplicationService is the interface to interact with the Application endpoint on the Vultr API.
// Link : https://www.vultr.com/api/#tag/application
type ApplicationService interface {
List(ctx context.Context, options *ListOptions) ([]Application, *Meta, error)
List(ctx context.Context, options *ListOptions) ([]Application, *Meta,*http.Response, error)
}

// ApplicationServiceHandler handles interaction with the application methods for the Vultr API.
Expand All @@ -35,26 +35,26 @@ type applicationBase struct {
}

// List retrieves a list of available applications that can be launched when creating a Vultr instance
func (a *ApplicationServiceHandler) List(ctx context.Context, options *ListOptions) ([]Application, *Meta, error) {
func (a *ApplicationServiceHandler) List(ctx context.Context, options *ListOptions) ([]Application, *Meta,*http.Response, error) {
uri := "/v2/applications"

req, err := a.client.NewRequest(ctx, http.MethodGet, uri, nil)
if err != nil {
return nil, nil, err
return nil, nil,nil, err
}

newValues, err := query.Values(options)
if err != nil {
return nil, nil, err
return nil, nil,nil, err
}

req.URL.RawQuery = newValues.Encode()
apps := new(applicationBase)

err = a.client.DoWithContext(ctx, req, apps)
resp,err := a.client.DoWithContext(ctx, req, apps)
if err != nil {
return nil, nil, err
return nil, nil,resp, err
}

return apps.Applications, apps.Meta, nil
return apps.Applications, apps.Meta,resp, nil
}
2 changes: 1 addition & 1 deletion application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestApplicationServiceHandler_List(t *testing.T) {
PerPage: 1,
Cursor: "",
}
apps, meta, err := client.Application.List(ctx, options)
apps, meta,_, err := client.Application.List(ctx, options)
if err != nil {
t.Errorf("Application.List returned error: %v", err)
}
Expand Down
15 changes: 8 additions & 7 deletions backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
// BackupService is the interface to interact with the backup endpoint on the Vultr API
// Link : https://www.vultr.com/api/#tag/backup
type BackupService interface {
Get(ctx context.Context, backupID string) (*Backup, error)
Get(ctx context.Context, backupID string) (*Backup, *http.Response, error)
List(ctx context.Context, options *ListOptions) ([]Backup, *Meta, error)
}

Expand Down Expand Up @@ -39,20 +39,21 @@ type backupBase struct {
}

// Get retrieves a backup that matches the given backupID
func (b *BackupServiceHandler) Get(ctx context.Context, backupID string) (*Backup, error) {
func (b *BackupServiceHandler) Get(ctx context.Context, backupID string) (*Backup, *http.Response, error) {
uri := fmt.Sprintf("/v2/backups/%s", backupID)
req, err := b.client.NewRequest(ctx, http.MethodGet, uri, nil)

if err != nil {
return nil, err
return nil, nil, err
}

backup := new(backupBase)
if err := b.client.DoWithContext(ctx, req, backup); err != nil {
return nil, err
resp, err := b.client.DoWithContext(ctx, req, backup)
if err != nil {
return nil, resp, err
}

return backup.Backup, nil
return backup.Backup, resp, nil
}

// List retrieves a list of all backups on the current account
Expand All @@ -72,7 +73,7 @@ func (b *BackupServiceHandler) List(ctx context.Context, options *ListOptions) (
req.URL.RawQuery = newValues.Encode()

backups := new(backupsBase)
if err = b.client.DoWithContext(ctx, req, backups); err != nil {
if _, err = b.client.DoWithContext(ctx, req, backups); err != nil {
return nil, nil, err
}

Expand Down
4 changes: 2 additions & 2 deletions backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func TestBackupServiceHandler_Get(t *testing.T) {
fmt.Fprint(w, response)
})

backup, err := client.Backup.Get(ctx, "543d34149403a")
backup, _, err := client.Backup.Get(ctx, "543d34149403a")
if err != nil {
t.Errorf("Backup.Get returned error: %v", err)
}
Expand Down Expand Up @@ -165,7 +165,7 @@ func TestBackupServiceHandler_GetEmpty(t *testing.T) {
fmt.Fprint(w, response)
})

backup, err := client.Backup.Get(ctx, "543d34149403a")
backup,_, err := client.Backup.Get(ctx, "543d34149403a")
if err != nil {
t.Errorf("Backup.Get returned error: %v", err)
}
Expand Down
Loading

0 comments on commit 2ba0ed6

Please sign in to comment.