-
Notifications
You must be signed in to change notification settings - Fork 1
/
delivery.go
58 lines (54 loc) · 1.86 KB
/
delivery.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
package picnic
import (
"strings"
)
type Delivery struct {
Type string `json:"type"`
Id string `json:"id"`
DeliveryId string `json:"delivery_id"`
CreationTime string `json:"creation_time"`
Slot DeliverySlot `json:"slot"`
Eta2 DeliveryTime `json:"eta_2"`
Status DeliveryStatus `json:"status"`
DeliveryTime DeliveryTime `json:"delivery_time"`
Orders []Order `json:"orders"`
ReturnedContainers []ReturnContainer `json:"returned_containers"`
Parcels []string `json:"parcels"`
}
// GetDeliveries Query for all current or past deliveries. Optionally provide a filter of the list of DeliveryStatus
// to filter the deliveries by. The data returned is a summary, to get the complete data of a delivery use GetDelivery
//
// Method requires client to be authenticated
func (c *Client) GetDeliveries(filter []DeliveryStatus) (*[]Delivery, error) {
if !c.IsAuthenticated() {
return nil, authenticationError()
}
if filter == nil {
filter = []DeliveryStatus{}
}
searchUrl := c.baseURL + "/deliveries/summary"
var deliveries []Delivery
err := c.post(searchUrl, filter, &deliveries)
if err != nil {
return nil, err
}
return &deliveries, nil
}
// GetDelivery Query for the complete details of a particular delivery.
//
// Method requires client to be authenticated
func (c *Client) GetDelivery(deliveryId string) (*Delivery, error) {
if !c.IsAuthenticated() {
return nil, authenticationError()
}
if strings.TrimSpace(deliveryId) == "" {
return nil, createError("GetDelivery requires a valid deliveryId string")
}
searchUrl := c.baseURL + "/deliveries/" + deliveryId
var delivery Delivery
err := c.get(searchUrl, &delivery)
if err != nil {
return nil, err
}
return &delivery, nil
}