This repository has been archived by the owner on Jul 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
checkpoints.go
47 lines (39 loc) · 1.67 KB
/
checkpoints.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
package aftership
import (
"context"
"fmt"
"net/http"
"github.com/pkg/errors"
)
// GetCheckpointParams is the additional parameters in checkpoint query
type GetCheckpointParams struct {
// List of fields to include in the response. Use comma for multiple values.
// Fields to include:slug,created_at,checkpoint_time,city,coordinates,country_iso3,
// country_name,message,state,tag,zip
// Default: none, Example: city,tag
Fields string `url:"fields,omitempty" json:"fields,omitempty"`
// Support Chinese to English translation for china-ems and china-post only (Example: en)
Lang string `url:"lang,omitempty" json:"lang,omitempty"`
AdditionalField
}
// LastCheckpoint is the last checkpoint API response
type LastCheckpoint struct {
ID string `json:"id,omitempty"`
Slug string `json:"slug,omitempty"`
TrackingNumber string `json:"tracking_number,omitempty"`
Tag string `json:"tag,omitempty"`
Subtag string `json:"subtag,omitempty"`
SubtagMessage string `json:"subtag_message,omitempty"`
Checkpoint Checkpoint `json:"checkpoint"`
}
// GetLastCheckpoint returns the tracking information of the last checkpoint of a single tracking.
func (client *Client) GetLastCheckpoint(ctx context.Context, identifier TrackingIdentifier, params GetCheckpointParams) (LastCheckpoint, error) {
uriPath, err := identifier.URIPath()
if err != nil {
return LastCheckpoint{}, errors.Wrap(err, "error getting last checkpoint")
}
uriPath = fmt.Sprintf("/last_checkpoint%s", uriPath)
var lastCheckpoint LastCheckpoint
err = client.makeRequest(ctx, http.MethodGet, uriPath, params, nil, &lastCheckpoint)
return lastCheckpoint, err
}