aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--notes9
-rw-r--r--print.go37
-rw-r--r--print_test.go30
-rw-r--r--testdata/jobsresp.json4
-rw-r--r--testdata/printablenormalization.json31
5 files changed, 85 insertions, 26 deletions
diff --git a/notes b/notes
index ce427d0..331cabe 100644
--- a/notes
+++ b/notes
@@ -9,12 +9,3 @@ real response did not; thus "fees" is included in the testdata. The
real response had "first_name" and "last_name" rather than just
"name", so ShippingAddress has a custom UnmarshalJSON() function to
account for both. And so on...
-
-
--- Print Jobs --
-
-I made some corrections to testdata/getprintjobsresp.json. These
-include changing "source_md5sum" to "source_md5_sum" and changing the
-postcode field from integer to string, etc., as per the schema. It
-remains to be seen if the errors are just in the documentation example
-or if they (sometimes) appear in real server responses too...
diff --git a/print.go b/print.go
index 8d48d17..930950c 100644
--- a/print.go
+++ b/print.go
@@ -188,20 +188,22 @@ type EstimatedShippingDates struct {
type PrintableNormalization struct {
Cover NormalizationJob `json:"cover"`
Interior NormalizationJob `json:"interior"`
+ Mfg PkgId `json:"pod_package_id"`
}
// NormalizationJob represents the normalization process of an interior
// or cover source file.
type NormalizationJob struct {
- JobId uint `json:"job_id"`
- NormalizedFile NormalizedFile `json:"normalized_file"`
- SrcMd5Sum string `json:"source_md5_sum"` // md5 hash of the source file.
- SrcUrl string `json:"source_url"` // URL of the source file.
+ JobId uint `json:"job_id"`
+ Src File `json:"source_file"`
+ Norm File `json:"normalized_file"`
+ SrcMd5Sum string `json:"source_md5sum"` // md5 hash of the source file.
+ SrcUrl string `json:"source_url"` // URL of the source file.
+ NPages uint `json:"page_count"`
}
-// NormalizedFile represents a file on the server that was created by
-// normalizing a cover or interior source file.
-type NormalizedFile struct {
+// File represents a file on the server.
+type File struct {
Id uint64 `json:"file_id"`
Name string `json:"filename"`
}
@@ -212,14 +214,14 @@ type LineItemStatus struct {
}
type LineItemStatusMessages struct {
- Delay time.Duration // Expected delay due to the error, if present.
- Error string `json:"error"`
- Info string `json:"info"`
- PrintableNormalization PrintableNormalization `json:"printable_normalization"`
- Timestamp time.Time `json:"timestamp"` // Timestamp of the last status change.
- TrackingUrls []string
- TrackingId string `json:"tracking_id"` // Tracking ID for this line item's shipment.
- Carrier string `json:"carrier_name"` // Name of the carrier handling the shipment.
+ Delay time.Duration // Expected delay due to the error, if present.
+ Error string `json:"error"`
+ Info string `json:"info"`
+ Norm PrintableNormalizationMessages `json:"printable_normalization"`
+ Timestamp time.Time `json:"timestamp"` // Timestamp of the last status change.
+ TrackingUrls []string
+ TrackingId string `json:"tracking_id"` // Tracking ID for this line item's shipment.
+ Carrier string `json:"carrier_name"` // Name of the carrier handling the shipment.
}
func (msgs *LineItemStatusMessages) UnmarshalJSON(data []byte) error {
@@ -254,6 +256,11 @@ func (msgs *LineItemStatusMessages) UnmarshalJSON(data []byte) error {
return nil
}
+type PrintableNormalizationMessages struct {
+ Cover []string `json:"cover"`
+ Interior []string `json:"interior"`
+}
+
type PrintJobStatus struct {
Changed time.Time `json:"changed"` // time of the last status change
Msg string `json:"message"`
diff --git a/print_test.go b/print_test.go
index 79381a1..993ead1 100644
--- a/print_test.go
+++ b/print_test.go
@@ -9,6 +9,35 @@ import (
"github.com/stretchr/testify/require"
)
+//go:embed testdata/printablenormalization.json
+var printableNormalizationJson string
+
+func TestMarshalUnmarshalPrintableNormalization(t *testing.T) {
+ t.Parallel()
+
+ norm := PrintableNormalization{
+ Interior: NormalizationJob{
+ Src: File{4354943, "unspecified"},
+ Norm: File{4354947, "normalized.pdf"},
+ SrcUrl: "https://www.dropbox.com/s/r20orb8umqjzav9/lulu_trade_interior_template-32.pdf?dl=1&raw=1",
+ SrcMd5Sum: "2a8526c4189e82ff119f11457e23fb9b",
+ JobId: 501439,
+ NPages: 32,
+ },
+ Cover: NormalizationJob{
+ Src: File{4354944, "unspecified"},
+ Norm: File{4354948, "normalized.pdf"},
+ SrcUrl: "https://www.dropbox.com/s/7bv6mg2tj0h3l0r/lulu_trade_perfect_template.pdf?dl=1&raw=1",
+ SrcMd5Sum: "d90458dd2081aa59bb77a04eb6b5fb0c",
+ JobId: 543910,
+ NPages: 1,
+ },
+ Mfg: PkgId{UsTrade, Mono, Standard, Perfect, P60UncoatedWhite, Matte, NoLinen, NoFoil},
+ }
+ requireMarshalJsonEq(t, printableNormalizationJson, norm)
+ requireUnmarshalJsonEq(t, norm, printableNormalizationJson)
+}
+
//go:embed testdata/jobsresp.json
var jobsRespJson string
@@ -64,6 +93,7 @@ var printJobSample = PrintJob{
SrcMd5Sum: "7f8af20c296747689756f8e310135d79",
SrcUrl: "https://www.dropbox.com/sh/p3zh22vzsaegiri/AACOUn3LFKsITDzylh13bQpsa/161025/thesis2.pdf?dl=1",
},
+ Mfg: PkgId{UsTrade, Mono, Standard, Perfect, P60UncoatedWhite, Matte, NoLinen, NoFoil},
},
Quantity: 20,
Status: LineItemStatus{
diff --git a/testdata/jobsresp.json b/testdata/jobsresp.json
index 3f43d2c..69b216f 100644
--- a/testdata/jobsresp.json
+++ b/testdata/jobsresp.json
@@ -55,7 +55,7 @@
"normalized_file": null,
"page_count": null,
"source_file": null,
- "source_md5_sum": "e78512c777e7f5841fe8f1992cefb898",
+ "source_md5sum": "e78512c777e7f5841fe8f1992cefb898",
"source_url": "https://www.dropbox.com/sh/p3zh22vzsaegiri/AADP367j0bTWlt8fCu-_tm2ia/161025/139056_cover.pdf?dl=1"
},
"interior": {
@@ -63,7 +63,7 @@
"normalized_file": null,
"page_count": null,
"source_file": null,
- "source_md5_sum": "7f8af20c296747689756f8e310135d79",
+ "source_md5sum": "7f8af20c296747689756f8e310135d79",
"source_url": "https://www.dropbox.com/sh/p3zh22vzsaegiri/AACOUn3LFKsITDzylh13bQpsa/161025/thesis2.pdf?dl=1"
},
"pod_package_id": "0600X0900.BW.STD.PB.060UW444.MXX"
diff --git a/testdata/printablenormalization.json b/testdata/printablenormalization.json
new file mode 100644
index 0000000..990dcd0
--- /dev/null
+++ b/testdata/printablenormalization.json
@@ -0,0 +1,31 @@
+{
+ "interior": {
+ "source_file": {
+ "file_id": 4354943,
+ "filename": "unspecified"
+ },
+ "normalized_file": {
+ "file_id": 4354947,
+ "filename": "normalized.pdf"
+ },
+ "source_url": "https://www.dropbox.com/s/r20orb8umqjzav9/lulu_trade_interior_template-32.pdf?dl=1&raw=1",
+ "source_md5sum": "2a8526c4189e82ff119f11457e23fb9b",
+ "job_id": 501439,
+ "page_count": 32
+ },
+ "cover": {
+ "source_file": {
+ "file_id": 4354944,
+ "filename": "unspecified"
+ },
+ "normalized_file": {
+ "file_id": 4354948,
+ "filename": "normalized.pdf"
+ },
+ "source_url": "https://www.dropbox.com/s/7bv6mg2tj0h3l0r/lulu_trade_perfect_template.pdf?dl=1&raw=1",
+ "source_md5sum": "d90458dd2081aa59bb77a04eb6b5fb0c",
+ "job_id": 543910,
+ "page_count": 1
+ },
+ "pod_package_id": "0600X0900.BW.STD.PB.060UW444.MXX"
+}