-
Notifications
You must be signed in to change notification settings - Fork 0
/
couriers.go
48 lines (41 loc) · 1.44 KB
/
couriers.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
package trackingmore
import (
"context"
"errors"
"net/http"
)
type Courier struct {
CourierName string `json:"courier_name"`
CourierCode string `json:"courier_code"`
CourierCountryIso2 interface{} `json:"courier_country_iso2"`
CourierUrl string `json:"courier_url"`
CourierPhone string `json:"courier_phone"`
CourierType string `json:"courier_type"`
TrackingRequiredFields interface{} `json:"tracking_required_fields"`
OptionalFields interface{} `json:"optional_fields"`
DefaultLanguage string `json:"default_language"`
SupportLanguage []string `json:"support_language"`
CourierLogo string `json:"courier_logo"`
}
type DetectParams struct {
TrackingNumber string `json:"tracking_number"`
}
func (client *Client) GetAllCouriers(ctx context.Context) (*Response, error) {
var couriers []Courier
response, err := client.sendApiRequest(ctx, http.MethodGet, "/couriers/all", nil, nil, &couriers)
if err != nil {
return nil, err
}
return response, nil
}
func (client *Client) Detect(ctx context.Context, params DetectParams) (*Response, error) {
if params.TrackingNumber == "" {
return nil, errors.New(ErrMissingTrackingNumber)
}
var couriers []Courier
response, err := client.sendApiRequest(ctx, http.MethodPost, "/couriers/detect", nil, params, &couriers)
if err != nil {
return nil, err
}
return response, nil
}