forked from EasyPost/easypost-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparcel.go
More file actions
59 lines (52 loc) · 1.91 KB
/
parcel.go
File metadata and controls
59 lines (52 loc) · 1.91 KB
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
package easypost
import (
"context"
"time"
)
// 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 *time.Time `json:"created_at,omitempty"`
UpdatedAt *time.Time `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) {
err = c.post(nil, "parcels", &createParcelRequest{Parcel: in}, &out)
return
}
// 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) {
err = c.get(nil, "parcels/"+parcelID, &out)
return
}
// 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
}