diff options
| author | Sam Anthony <sam@samanthony.xyz> | 2026-05-16 14:04:39 -0400 |
|---|---|---|
| committer | Sam Anthony <sam@samanthony.xyz> | 2026-05-16 14:04:39 -0400 |
| commit | e39f8f5b075b67ae3c63cc3ee7c5b7e81271b530 (patch) | |
| tree | 9fd0aa2204ba5af2bc8b1d9ce0a1848f35a18f78 | |
| parent | 45914474e6d25b97e51f7858ddb5c78438d386d7 (diff) | |
| download | lulu-e39f8f5b075b67ae3c63cc3ee7c5b7e81271b530.zip | |
reprint
| -rw-r--r-- | lulu.go | 29 | ||||
| -rw-r--r-- | print_test.go | 45 |
2 files changed, 67 insertions, 7 deletions
@@ -315,10 +315,30 @@ func (c *Client) GetPrintJob(id uint64) (PrintJob, error) { // // https://api.lulu.com/docs/#tag/Print-Jobs/operation/Print-Jobs_create func (c *Client) Print(contact EmailAddress, externalId string, productionDelay time.Duration, addr ShippingAddress, shipOpt ShippingLevel, items []Printable) (PrintJob, error) { + job, err := print(c, contact, externalId, productionDelay, addr, shipOpt, items) + if err != nil { + err = pkgErr(err) + } + return job, err +} + +// Reprint creates a print job, printing books whose PrintableIds are +// known from a prior order. See also: Print(). +// +// https://api.lulu.com/docs/#tag/Print-Jobs/operation/Print-Jobs_reprint +func (c *Client) Reprint(contact EmailAddress, externalId string, productionDelay time.Duration, addr ShippingAddress, shipOpt ShippingLevel, items []Reprintable) (PrintJob, error) { + job, err := print(c, contact, externalId, productionDelay, addr, shipOpt, items) + if err != nil { + err = pkgErr(err) + } + return job, err +} + +func print[P Printable | Reprintable](c *Client, contact EmailAddress, externalId string, productionDelay time.Duration, addr ShippingAddress, shipOpt ShippingLevel, items []P) (PrintJob, error) { if err := verifyProductionDelay(productionDelay); err != nil { - return PrintJob{}, pkgErr(err) + return PrintJob{}, err } - req := printReq[Printable]{ + req := printReq[P]{ Contact: contact, ExternalId: externalId, LineItems: items, @@ -328,10 +348,7 @@ func (c *Client) Print(contact EmailAddress, externalId string, productionDelay } var job PrintJob err := c.postDecode(printJobsPath, req, http.StatusCreated, &job) - if err != nil { - return job, pkgErr(err) - } - return job, nil + return job, err } func verifyProductionDelay(delay time.Duration) error { diff --git a/print_test.go b/print_test.go index ad8730b..2ff6209 100644 --- a/print_test.go +++ b/print_test.go @@ -189,7 +189,46 @@ func TestPrint(t *testing.T) { } func TestReprint(t *testing.T) { - t.Fail() // TODO + contact := MustParseEmailAddress("test@test.com") + productionDelay := 120 * time.Minute + addr := shipAddrSample + shipOpt := Mail + printItem := printableSample + + // Create print job + c := newClient(t) + job1, err := c.Print(contact, "print", productionDelay, addr, shipOpt, []Printable{printItem}) + require.NoError(t, err) + id1 := job1.Id + + // Wait for it to be assigned a printable_id + tpoll(t, func() bool { + job1, err = c.GetPrintJob(id1) + require.NoError(t, err) + require.Len(t, job1.LineItems, 1) + return job1.LineItems[0].Status.Status != ItemCreated + }) + t.Logf("Job 1: %#v\n", job1) + require.Len(t, job1.LineItems, 1) + pid := job1.LineItems[0].PrintableId + require.NotEmpty(t, pid) + + // Reprint + reprintItem := Reprintable{ + printItem.ExternalId, + pid, + printItem.Quantity, + printItem.Title, + } + job2, err := c.Reprint(contact, "reprint", productionDelay, addr, shipOpt, []Reprintable{reprintItem}) + require.NoError(t, err) + require.Len(t, job2.LineItems, 1) + item1, item2 := job1.LineItems[0], job2.LineItems[0] + require.Equal(t, item1.Title, item2.Title) + require.Equal(t, item1.ExternalId, item2.ExternalId) + require.Equal(t, item1.Quantity, item2.Quantity) + require.Equal(t, item1.PrintableId, item2.PrintableId) + require.Equal(t, item1.Mfg, item2.Mfg) } func TestGetPrintJob(t *testing.T) { @@ -214,3 +253,7 @@ func TestGetPrintJob(t *testing.T) { require.Equal(t, job1, job2) } + +func TestCancel(t *testing.T) { + t.Fail() // TODO +} |