Skip to content

Commit

Permalink
Add some getters for the endpoint responses
Browse files Browse the repository at this point in the history
  • Loading branch information
printesoi committed Mar 22, 2024
1 parent 59a3954 commit cb1b66e
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,39 @@ func (r *ValidateResponse) IsOk() bool {
return r != nil && r.State == CodeOk
}

// GetFirstMessage returns the first message from the validate response. If no
// messages are set, empty string is returned.
func (r *ValidateResponse) GetFirstMessage() string {
if r == nil || len(r.Messages) == 0 {
return ""
}

return r.Messages[0].Message
}

// IsOk returns true if the XML-To-PDF response was successful.
func (r *GeneratePDFResponse) IsOk() bool {
return r != nil && r.Error == nil
}

// GetError is a getter for the Error field.
func (r *GeneratePDFResponse) GetError() *GeneratePDFResponseError {
if r == nil {
return nil
}
return r.Error
}

// GetFirstMessage returns the first message from the validate response. If no
// messages are set, empty string is returned.
func (r *GeneratePDFResponseError) GetFirstMessage() string {
if r == nil || len(r.Messages) == 0 {
return ""
}

return r.Messages[0].Message
}

// IsOk returns true if the response corresponding to an upload was successful.
func (r *UploadResponse) IsOk() bool {
return r != nil && r.ExecutionStatus != nil && *r.ExecutionStatus == 0
Expand All @@ -255,6 +283,16 @@ func (r *UploadResponse) GetUploadIndex() int64 {
return *r.UploadIndex
}

// GetFirstErrorMessage returns the first error message. If no error messages
// are set for the upload response, empty string is returned.
func (r *UploadResponse) GetFirstErrorMessage() string {
if r == nil || len(r.Errors) == 0 {
return ""
}

return r.Errors[0].ErrorMessage
}

// IsOk returns true if the message state if ok (processed, and can be
// downloaded).
func (r *GetMessageStateResponse) IsOk() bool {
Expand Down Expand Up @@ -286,6 +324,16 @@ func (r *GetMessageStateResponse) IsInvalidXML() bool {
return r != nil && r.State == GetMessageStateCodeInvalidXML
}

// GetFirstErrorMessage returns the first error message. If no error messages
// are set for the response, empty string is returned.
func (r *GetMessageStateResponse) GetFirstErrorMessage() string {
if r == nil || len(r.Errors) == 0 {
return ""
}

return r.Errors[0].ErrorMessage
}

func (t MessageFilterType) String() string {
switch t {
case MessageFilterErrors:
Expand Down

0 comments on commit cb1b66e

Please sign in to comment.