/
profile.go
102 lines (88 loc) · 4.16 KB
/
profile.go
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package cloudsigma
import (
"context"
"fmt"
"net/http"
)
const profileBasePath = "profile"
// ProfileService handles communication with the profile related methods of the CloudSigma API.
//
// CloudSigma API docs: https://cloudsigma-docs.readthedocs.io/en/latest/profile.html
type ProfileService service
// Profile represents a CloudSigma user profile.
type Profile struct {
Address string `json:"address,omitempty"`
APIHTTPSOnly bool `json:"api_https_only,omitempty"`
AutoTopUpAmount string `json:"autotopup_amount,omitempty"`
AutoTopUpThreshold string `json:"autotopup_threshold,omitempty"`
BankReference string `json:"bank_reference,omitempty"`
CloneNaming string `json:"clone_naming,omitempty"`
Company string `json:"company,omitempty"`
Country string `json:"country,omitempty"`
Currency string `json:"currency,omitempty"`
Email string `json:"email,omitempty"`
FirstName string `json:"first_name,omitempty"`
HasAutoTopUp bool `json:"has_autotopup,omitempty"`
HasTxAutoTopUp bool `json:"has_tx_autotopup,omitempty"`
Invoicing bool `json:"invoicing,omitempty"`
KeyAuth bool `json:"key_auth,omitempty"`
Language string `json:"language,omitempty"`
LastName string `json:"last_name,omitempty"`
MailingList bool `json:"mailing_list,omitempty"`
Meta map[string]interface{} `json:"meta,omitempty"`
MyNotes string `json:"my_notes,omitempty"`
NetworkRestrictions string `json:"network_restrictions,omitempty"`
Nickname string `json:"nickname,omitempty"`
Phone string `json:"phone,omitempty"`
Postcode string `json:"postcode,omitempty"`
Reseller string `json:"reseller,omitempty"`
SignupTime string `json:"signup_time,omitempty"`
State string `json:"state,omitempty"`
TaxName string `json:"tax_name,omitempty"`
TaxRate string `json:"tax_rate,omitempty"`
Title string `json:"title,omitempty"`
Town string `json:"town,omitempty"`
TxAutoTopUpAmount string `json:"tx_autotopup_amount,omitempty"`
TxAutoTopUpThreshold string `json:"tx_autotopup_threshold,omitempty"`
UUID string `json:"uuid"`
VAT string `json:"vat,omitempty"`
}
// ProfileUpdateRequest represents a request to update a profile.
type ProfileUpdateRequest struct {
*Profile
}
// Get provides information for an user profile.
//
// CloudSigma API docs: https://cloudsigma-docs.readthedocs.io/en/latest/profile.html#listing
func (s *ProfileService) Get(ctx context.Context) (*Profile, *Response, error) {
path := fmt.Sprintf("%v/", profileBasePath)
req, err := s.client.NewRequest(http.MethodGet, path, nil)
if err != nil {
return nil, nil, err
}
profile := new(Profile)
resp, err := s.client.Do(ctx, req, profile)
if err != nil {
return nil, resp, err
}
return profile, resp, nil
}
// Update edits a user profile.
//
// CloudSigma API docs: https://cloudsigma-docs.readthedocs.io/en/latest/profile.html#editing
func (s *ProfileService) Update(ctx context.Context, updateRequest *ProfileUpdateRequest) (*Profile, *Response, error) {
if updateRequest == nil {
return nil, nil, ErrEmptyPayloadNotAllowed
}
path := fmt.Sprintf("%v/", profileBasePath)
req, err := s.client.NewRequest(http.MethodPut, path, updateRequest)
if err != nil {
return nil, nil, err
}
profile := new(Profile)
resp, err := s.client.Do(ctx, req, profile)
if err != nil {
return nil, resp, err
}
return profile, resp, nil
}