/
parcel.go
57 lines (50 loc) · 1.89 KB
/
parcel.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
package easypost
import (
"context"
)
// A Parcel objects represent a physical container being shipped.
type Parcel struct {
ID string `json:"id,omitempty"`
Object string `json:"object,omitempty"`
Mode string `json:"mode,omitempty"`
CreatedAt *DateTime `json:"created_at,omitempty"`
UpdatedAt *DateTime `json:"updated_at,omitempty"`
Length float64 `json:"length,omitempty"`
Width float64 `json:"width,omitempty"`
Height float64 `json:"height,omitempty"`
PredefinedPackage string `json:"predefined_package,omitempty"`
Weight float64 `json:"weight,omitempty"`
}
type createParcelRequest struct {
Parcel *Parcel `json:"parcel,omitempty"`
}
// CreateParcel creates a new Parcel object.
//
// c := easypost.New(MyEasyPostAPIKey)
// out, err := c.CreateParcel(
// &easypost.Parcel{
// Length: 20.2,
// Width: 10.9,
// Height: 5,
// Weight: 65.9,
// },
// )
func (c *Client) CreateParcel(in *Parcel) (out *Parcel, err error) {
return c.CreateParcelWithContext(context.Background(), in)
}
// CreateParcelWithContext performs the same operation as CreateParcel, but
// allows specifying a context that can interrupt the request.
func (c *Client) CreateParcelWithContext(ctx context.Context, in *Parcel) (out *Parcel, err error) {
err = c.post(ctx, "parcels", &createParcelRequest{Parcel: in}, &out)
return
}
// GetParcel retrieves an existing Parcel object by ID.
func (c *Client) GetParcel(parcelID string) (out *Parcel, err error) {
return c.GetParcelWithContext(context.Background(), parcelID)
}
// GetParcelWithContext performs the same operation as GetParcel, but allows
// specifying a context that can interrupt the request.
func (c *Client) GetParcelWithContext(ctx context.Context, parcelID string) (out *Parcel, err error) {
err = c.get(ctx, "parcels/"+parcelID, &out)
return
}