forked from sapcc/go-vice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetOrgInfo.go
77 lines (64 loc) · 1.84 KB
/
getOrgInfo.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
package vice
import (
"context"
"encoding/xml"
"fmt"
"time"
)
const getOrgInfoBasePath = "/vswebservices/rest/services/getOrgInfo"
type SimpleTime struct {
time.Time
}
func (sT *SimpleTime) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
const shortForm = "01/02/2006" // mm/dd/yyyy date format
var v string
d.DecodeElement(&v, &start)
if v == "N/A" {
return fmt.Errorf("date not available")
}
parse, err := time.Parse(shortForm, v)
if err != nil {
return err
}
*sT = SimpleTime{parse}
return nil
}
func NewSimpleTime(day, month, year int) SimpleTime {
return SimpleTime{time.Date(year, time.Month(month), day, 0, 0, 0, 0, time.UTC)}
}
type _OrgContact struct {
FirstName string `xml:"FirstName,omitempty"`
LastName string `xml:"LastName,omitempty"`
Phone string `xml:"Phone,omitempty"`
Email string `xml:"Email,omitempty"`
}
type _OrgAddress struct {
City string `xml:"City,omitempty"`
State string `xml:"State,omitempty"`
Country string `xml:"Country,omitempty"`
}
type _Organization struct {
Name string `xml:"name,attr,omitempty"`
OrgStatus string `xml:"OrgStatus,omitempty"`
AuthStatus string `xml:"AuthStatus,omitempty"`
EVEnabled string `xml:"EV_Enabled,omitempty"`
AuthExpires SimpleTime `xml:"AuthExpires,omitempty"`
OrgContact _OrgContact `xml:"OrgContact,omitempty"`
OrgAddress _OrgAddress `xml:"OrgAddress,omitempty"`
}
type OrganizationInfo struct {
ViceResponse
Organization _Organization `xml:"Organization"`
}
func (c *CertificatesServiceOp) GetOrganizationInfo(ctx context.Context) (*OrganizationInfo, error) {
req, err := c.client.newRequest(ctx, "GET", getOrgInfoBasePath, nil)
if err != nil {
return nil, err
}
getOrgInfo := new(OrganizationInfo)
err = c.client.Do(req, getOrgInfo)
if err != nil {
return nil, err
}
return getOrgInfo, nil
}