File: accounts.go

package info (click to toggle)
golang-github-dnsimple-dnsimple-go 2.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,428 kB
  • sloc: makefile: 3
file content (61 lines) | stat: -rw-r--r-- 1,880 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package dnsimple

import (
	"context"
)

// AccountsService handles communication with the account related
// methods of the DNSimple API.
//
// See https://developer.dnsimple.com/v2/accounts/
type AccountsService struct {
	client *Client
}

// Account represents a DNSimple account.
type Account struct {
	ID             int64  `json:"id,omitempty"`
	Email          string `json:"email,omitempty"`
	PlanIdentifier string `json:"plan_identifier,omitempty"`
	CreatedAt      string `json:"created_at,omitempty"`
	UpdatedAt      string `json:"updated_at,omitempty"`
}

// AccountsResponse represents a response from an API method that returns a collection of Account struct.
type AccountsResponse struct {
	Response
	Data []Account `json:"data"`
}

// AccountInvitation represents an invitation to a DNSimple account.
type AccountInvitation struct {
	ID                   int64  `json:"id,omitempty"`
	Email                string `json:"email,omitempty"`
	Token                string `json:"token,omitempty"`
	AccountID            int64  `json:"account_id,omitempty"`
	CreatedAt            string `json:"created_at,omitempty"`
	UpdatedAt            string `json:"updated_at,omitempty"`
	InvitationSentAt     string `json:"invitation_sent_at,omitempty"`
	InvitationAcceptedAt string `json:"invitation_accepted_at,omitempty"`
}

// ListAccounts list the accounts for an user.
//
// See https://developer.dnsimple.com/v2/accounts/#list
func (s *AccountsService) ListAccounts(ctx context.Context, options *ListOptions) (*AccountsResponse, error) {
	path := versioned("/accounts")
	accountsResponse := &AccountsResponse{}

	path, err := addURLQueryOptions(path, options)
	if err != nil {
		return nil, err
	}

	resp, err := s.client.get(ctx, path, accountsResponse)
	if err != nil {
		return accountsResponse, err
	}

	accountsResponse.HTTPResponse = resp
	return accountsResponse, nil
}