-
Notifications
You must be signed in to change notification settings - Fork 1
/
model.go
155 lines (134 loc) · 4.99 KB
/
model.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
package trakpak
import (
"encoding/base64"
"encoding/xml"
"time"
"github.com/pkg/errors"
)
// Time - Marshalls time.Time to expected format.
type Time time.Time
var timeFormat = "2006-01-02 15:04:05"
// "2016-10-21 18:53:53" as "2006-01-02T15:04:05Z07:00"
// MarshalXML - Marshals time to TrakPak format.
func (t Time) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
return errors.Wrap(e.EncodeElement(time.Time(t).Format(timeFormat), start), "Problem encoding time to TrakPak format")
}
// UnmarshalXML - Unmarshals time from TrakPak format.
func (t *Time) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
var v string
if err := d.DecodeElement(&v, &start); err != nil {
return errors.Wrapf(err, "Problem decoding element %v when unmarshaling TrakPak time", start)
}
parsedTime, err := time.Parse(timeFormat, v)
if err != nil {
return errors.Wrapf(err, "Problem parsing trackpack time %q", v)
}
*t = Time(parsedTime)
return nil
}
// AccessRequest - TODO
type AccessRequest struct {
AccessLicenseNumber string `valid:"required,length(1|12)"`
UserID string `xml:"UserId" valid:"required,length(1|6)"`
Password string `valid:"required,length(1|20)"`
}
// Shipment - TODO
type Shipment struct {
ShipmentDate Time // <ShipmentDate>2013-06-24 10:32:44</ShipmentDate>
Shipper *Shipper
Destination *Destination
ShipmentInformation *ShipmentInformation
}
// Shipper - TODO
type Shipper struct {
ShipperCompany string `valid:"required,length(1|35)"`
ShipperAddress1 string `valid:"required,length(1|35)"`
ShipperAddress2 string `valid:"required,length(1|35)"`
ShipperAddress3 string `valid:"required,length(1|35)"`
ShipperCity string `valid:"required,length(1|20)"`
ShipperCounty string `valid:"length(1|35)"`
ShipperCountryCode string `valid:"required,length(2|2)"`
ShipperPostcode string `valid:"required,length(1|10)"`
ShipperContact string `valid:"length(0|40)"`
ShipperPhone string `valid:"required,length(1|10)"`
ShipperVat string `valid:"required,length(0|17)"`
ShipperEmail string `valid:"email,length(1|40)"`
ShipperReference string `valid:"length(1|20)"`
ShipperDept string `valid:"length(1|17)"`
}
// Destination - TODO
type Destination struct {
DestinationCompany string `valid:"required,length(1|35)"`
DestinationAddress1 string `valid:"required,length(1|35)"`
DestinationAddress2 string `valid:"required,length(1|35)"`
DestinationAddress3 string `valid:"length(10|35)"`
DestinationCity string `valid:"required,length(1|20)"`
DestinationCounty string `valid:"length(1|35)"`
DestinationCountryCode string `valid:"required,length(2|2)"`
DestinationPostCode string `valid:"length(0|10)"`
DestinationContact string `valid:"required,length(1|40)"`
DestinationPhone string `valid:"length(0|20)"`
DestinationVat string `valid:"length(0|17)"`
DestinationEmail string `valid:"required,email,length(1|40)"`
}
// ShipmentInformation - TODO
type ShipmentInformation struct {
Service string `valid:"required,length(1|4)"`
TotalPieces int
TotalWeight float64
WeightID string `xml:"WeightId" valid:"length(1|1)"`
Length int
Width int
Height int
Product string `valid:"required,length(3|3)"`
DescriptionOfGoods string `valid:"required,length(1|70)"`
Value float64
ValueCurrency string `valid:"required,length(3|3)"`
Terms string `valid:"length(3|3)"`
LabelImageFormat string `valid:"length(3|3)"`
ItemInformation []ItemInformation
}
// ItemInformation - TODO
type ItemInformation struct {
ItemDescription string `valid:"required,length(1|255)"`
ItemHsCode string `valid:"length(1|10)"`
ItemQuantity int
ItemValue float64
ItemSkuCode string `valid:"length(1|10)"`
ItemCOO string `valid:"length(2|2)"`
}
/*
type Ack struct {
xml.Name `xml:"ack"`
DateTimeStamp Time
}
*/
// ShipmentResponse - the wrapped response to a ShipmentBookingRequest
type ShipmentResponse struct {
Hawb string `valid:"required,length(1|12)"`
TrackingNumber string `valid:"required,length(1|50)"`
TrackingURL string `valid:"required"`
QuickTrackURL string
CarrierTrackingURL string `valid:"required"`
LabelImage Label `valid:"required"`
LabelImageFormat string `valid:"required,length(3|3)"`
}
// Label - Base64 encoded label
type Label string
// Decode - Decodes Base64 data
func (l *Label) Decode() ([]byte, error) {
return base64.StdEncoding.DecodeString(string(*l))
}
// ShipmentBookingAck - wrapper for the the ShipmentBookingResponse
type ShipmentBookingAck struct {
xml.Name `xml:"ack"`
DateTimeStamp Time
ShipmentResponse *ShipmentResponse
ErrorData string
}
type ShipmentVoidRequest struct {
TrackingNumber string `valid:"required,length(1|50)"`
}
type ShipmentConfirmRequest struct {
TrackingNumber string `valid:"required,length(1|50)"`
}