aboutsummaryrefslogtreecommitdiffstats
path: root/lulu.go
diff options
context:
space:
mode:
Diffstat (limited to 'lulu.go')
-rw-r--r--lulu.go50
1 files changed, 40 insertions, 10 deletions
diff --git a/lulu.go b/lulu.go
index 44220b8..2346749 100644
--- a/lulu.go
+++ b/lulu.go
@@ -41,11 +41,11 @@ type ValidationStatus string
const (
StatusNull ValidationStatus = "NULL" // file validation is not started yet
- StatusValidating = "VALIDATING" // file validation is still running
- StatusValidated = "VALIDATED" // file validation finished without any errors
- StatusNormalizing = "NORMALIZING" // file normalization (next step of validation, available only if pod_package_id is was passed in the payload) is still running
- StatusNormalized = "NORMALIZED" // file normalization finished without any errors
- StatusError = "ERROR" // file is invalid, list of errors is included in the response
+ StatusValidating ValidationStatus = "VALIDATING" // file validation is still running
+ StatusValidated ValidationStatus = "VALIDATED" // file validation finished without any errors
+ StatusNormalizing ValidationStatus = "NORMALIZING" // file normalization (next step of validation, available only if pod_package_id is was passed in the payload) is still running
+ StatusNormalized ValidationStatus = "NORMALIZED" // file normalization finished without any errors
+ StatusError ValidationStatus = "ERROR" // file is invalid, list of errors is included in the response
)
func (s ValidationStatus) IsFinal() bool {
@@ -136,16 +136,46 @@ func (c *Client) validateInterior(payload any) (uint, error) {
return 0, fmt.Errorf("lulu: POST %s: %s: %s", url, resp.Status, body)
}
- dec := json.NewDecoder(resp.Body)
+ buf := new(bytes.Buffer)
+ if _, err := io.Copy(buf, resp.Body); err != nil {
+ return 0, fmt.Errorf("lulu: POST %s: error reading response body: %w", url, err)
+ }
+ dec := json.NewDecoder(buf)
var rec InteriorValidationRecord
- err = dec.Decode(&rec)
- return rec.Id, err
+ if err := dec.Decode(&rec); err != nil {
+ return 0, fmt.Errorf("lulu: POST %s: error decoding response body %q: %w", url, buf, err)
+ }
+ return rec.Id, nil
}
// GetInteriorValidation retrieves information about an interior file
// validation job that was started by ValidateInterior().
//
// https://api.lulu.com/docs/#tag/Files-validation/operation/Validate-Interior_read
-func (c *Client) GetInteriorValidation(id int) (InteriorValidationRecord, error) {
- return InteriorValidationRecord{}, fmt.Errorf("not implemented") // TODO
+func (c *Client) GetInteriorValidation(id uint) (InteriorValidationRecord, error) {
+ url, err := url.JoinPath(ApiUrl, validateInteriorPath, fmt.Sprint(id))
+ if err != nil {
+ return InteriorValidationRecord{}, fmt.Errorf("lulu: %w", err)
+ }
+ resp, err := c.c.Get(url)
+ if err != nil {
+ return InteriorValidationRecord{}, fmt.Errorf("lulu: %w", err)
+ }
+ defer resp.Body.Close()
+
+ if resp.StatusCode != http.StatusOK {
+ body, _ := io.ReadAll(resp.Body)
+ return InteriorValidationRecord{}, fmt.Errorf("lulu: GET %s: %s: %s", url, resp.Status, body)
+ }
+
+ buf := new(bytes.Buffer)
+ if _, err := io.Copy(buf, resp.Body); err != nil {
+ return InteriorValidationRecord{}, fmt.Errorf("lulu: GET %s: error reading response body: %w", url, err)
+ }
+ dec := json.NewDecoder(buf)
+ var rec InteriorValidationRecord
+ if err := dec.Decode(&rec); err != nil {
+ return rec, fmt.Errorf("lulu: GET %s: error decoding response body %q: %w", url, buf, err)
+ }
+ return rec, nil
}