forked from afosto/sendcloud-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sender.go
63 lines (56 loc) · 1.42 KB
/
sender.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
package sendcloud
import "encoding/json"
type SenderResponseContainer struct {
SenderAddresses []SenderResponse `json:"sender_addresses"`
}
type Sender struct {
ID int64
CompanyName string
Email string
PhoneNumber string
Street string
HouseNumber string
PostCode string
City string
CountryCode string
}
type SenderResponse struct {
ID int64 `json:"id"`
CompanyName string `json:"company_name"`
ContactName string `json:"contact_name"`
Email string `json:"email"`
Telephone string `json:"telephone"`
Street string `json:"street"`
HouseNumber string `json:"house_number"`
PostalBox string `json:"postal_box"`
PostalCode string `json:"postal_code"`
City string `json:"city"`
Country string `json:"country"`
}
//Get formatted response
func (a *SenderResponseContainer) GetResponse() interface{} {
var senders []*Sender
for _, sa := range a.SenderAddresses {
sender := &Sender{
ID: sa.ID,
CompanyName: sa.CompanyName,
Email: sa.Email,
PhoneNumber: sa.Telephone,
Street: sa.Street,
HouseNumber: sa.HouseNumber,
PostCode: sa.PostalCode,
City: sa.City,
CountryCode: sa.Country,
}
senders = append(senders, sender)
}
return senders
}
//Set the response
func (a *SenderResponseContainer) SetResponse(body []byte) error {
err := json.Unmarshal(body, &a)
if err != nil {
return err
}
return nil
}