forked from EasyPost/easypost-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscan_form.go
More file actions
89 lines (78 loc) · 3.28 KB
/
scan_form.go
File metadata and controls
89 lines (78 loc) · 3.28 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package easypost
import (
"context"
"net/http"
"time"
)
// A ScanForm object represents a document that can be scanned to mark all
// included tracking codes as "Accepted for Shipment" by the carrier.
type ScanForm struct {
ID string `json:"id,omitempty"`
Object string `json:"object,omitempty"`
CreatedAt *time.Time `json:"created_at,omitempty"`
UpdatedAt *time.Time `json:"updated_at,omitempty"`
Status string `json:"status,omitempty"`
Message string `json:"message,omitempty"`
Address *Address `json:"address,omitempty"`
TrackingCodes []string `json:"tracking_codes,omitempty"`
FormURL string `json:"form_url,omitempty"`
FormFileType string `json:"form_file_type,omitempty"`
BatchID string `json:"batch_id,omitempty"`
}
type scanFormRequest struct {
Shipments []*Shipment `json:"shipments,omitempty"`
}
func newscanFormRequest(shipmentIDs ...string) *scanFormRequest {
l := len(shipmentIDs)
if l == 0 {
return nil
}
req := &scanFormRequest{Shipments: make([]*Shipment, l)}
for i := 0; i < l; i++ {
req.Shipments[i] = &Shipment{ID: shipmentIDs[i]}
}
return req
}
// CreateScanForm creates a scan form for the given Shipments.
// c := easypost.New(MyEasyPostAPIKey)
// out, err := c.CreateScanForm("shp_1", "shp_2")
func (c *Client) CreateScanForm(shipmentIDs ...string) (out *ScanForm, err error) {
err = c.post(nil, "scan_forms", newscanFormRequest(shipmentIDs...), &out)
return
}
// CreateScanFormWithContext performs the same operation as CreateScanForm, but
// allows specifying a context that can interrupt the request.
func (c *Client) CreateScanFormWithContext(ctx context.Context, shipmentIDs ...string) (out *ScanForm, err error) {
err = c.post(ctx, "scan_forms", newscanFormRequest(shipmentIDs...), &out)
return
}
// ListScanFormsResult holds the results from the list scan forms API.
type ListScanFormsResult struct {
ScanForms []*ScanForm `json:"scan_forms,omitempty"`
// HasMore indicates if there are more responses to be fetched. If True,
// additional responses can be fetched by updating the ListScanFormsOptions
// parameter's AfterID field with the ID of the last item in this object's
// ScanForms field.
HasMore bool `json:"has_more,omitempty"`
}
// ListScanForms provides a paginated result of ScanForm objects.
func (c *Client) ListScanForms(opts *ListOptions) (out *ListScanFormsResult, err error) {
return c.ListScanFormsWithContext(nil, opts)
}
// ListScanFormsWithContext performs the same operation as ListScanForms, but
// allows specifying a context that can interrupt the request.
func (c *Client) ListScanFormsWithContext(ctx context.Context, opts *ListOptions) (out *ListScanFormsResult, err error) {
err = c.do(ctx, http.MethodGet, "scan_forms", c.convertOptsToURLValues(opts), &out)
return
}
// GetScanForm retrieves a ScanForm object by ID.
func (c *Client) GetScanForm(scanFormID string) (out *ScanForm, err error) {
err = c.get(nil, "scan_forms/"+scanFormID, &out)
return
}
// GetScanFormWithContext performs the same operation as GetScanForm, but
// allows specifying a context that can interrupt the request.
func (c *Client) GetScanFormWithContext(ctx context.Context, scanFormID string) (out *ScanForm, err error) {
err = c.get(ctx, "scan_forms/"+scanFormID, &out)
return
}