Skip to content

Commit

Permalink
Rename RASPMessage to RaspMessage and some README fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
printesoi committed Mar 25, 2024
1 parent 01161a5 commit 286ac92
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 9 deletions.
31 changes: 26 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,11 @@ uploadRes, err := client.UploadXML(ctx, xml, UploadStandardUBL, "123456789")
### Upload message ###

```go
msg := efactura.RASPMessage{
msg := efactura.RaspMessage{
UploadIndex: 5008787839,
Message: "test",
}
uploadRes, err := client.UploadRASPMessage(ctx, msg, "123456789")
uploadRes, err := client.UploadRaspMessage(ctx, msg, "123456789")
if err != nil {
// Handle error
}
Expand Down Expand Up @@ -209,12 +209,34 @@ if validateRes.IsOk() {
}
```
### Errors ###
This library tries its best to overcome the not so clever API implementation
and to detect limits exceeded errors. To check if the error is cause by a
limit:
```go
resp, err := client.GetMessageState(ctx, uploadIndex)
if err != nil {
var limitsErr *efactura.LimitExceededError
var responseErr *efactura.ErrorResponse
if errors.As(err, &limitsErr) {
// The limits were exceeded. limitsErr.ErrorResponse contains more
// information about the HTTP response, and the limitsErr.Limit field
// contains the limit for the day.
} else if errors.As(err, &responseErr) {
// ErrorResponse means we got the HTTP response but we failed to parse
// it or some other error like invalid response content type.
}
}
```
## Generating an Invoice ##
TODO: See TestInvoiceBuilder() from builders_test.go for an example of using
InvoiceBuilder for creating an Invoice.
## Getting the raw XML of the invoice ##
### Getting the raw XML of the invoice ##
In case you need to get the XML encoding of the invoice (eg. you need to store
it somewhere before the upload):
Expand Down Expand Up @@ -242,7 +264,7 @@ if err != nil {
**NOTE** Don't use the standard `encoding/xml` package for generating the XML
encoding, since it does not produce Canonical XML [XML-C14N]!
## Unmarshal XML to invoice ##
### Unmarshal XML to invoice ##
```go
var invoice efactura.Invoice
Expand All @@ -262,7 +284,6 @@ cannot unmarshal a struct like efactura.Invoice due to namespace prefixes!
- [ ] Implement CreditNote.
- [ ] Add tests for all REST API calls and more tests for validating generated
XML (maybe checking with the tools provided by mfinante).
- [ ] Check and test API limits.
- [ ] Godoc and more code examples.
- [ ] Test coverage
- [ ] Support full OAuth2 authentication flow for the client, not just passing
Expand Down
2 changes: 2 additions & 0 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,9 @@ func newValidateSignatureError(err error) *ValidateSignatureError {

// LimitExceededError is an error returned if we hit an API limit.
type LimitExceededError struct {
// ErrorResponse has information about the HTTP response.
*ErrorResponse
// Limit stores the API limit that was hit for the day.
Limit int64
}

Expand Down
8 changes: 4 additions & 4 deletions rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ type (
PDF []byte
}

RASPMessage struct {
RaspMessage struct {
UploadIndex int64 `xml:"index_incarcare,attr"`
Message string `xml:"message,attr"`

Expand Down Expand Up @@ -582,9 +582,9 @@ func (c *Client) UploadInvoice(
return c.UploadXML(ctx, xmlReader, UploadStandardUBL, cif, opts...)
}

// UploadRASPMessage uploads the given RASPMessage.
func (c *Client) UploadRASPMessage(
ctx context.Context, msg RASPMessage, cif string,
// UploadRaspMessage uploads the given RaspMessage.
func (c *Client) UploadRaspMessage(
ctx context.Context, msg RaspMessage, cif string,
) (response *UploadResponse, err error) {
xmlReader, err := xmlMarshalReader(msg)
if err != nil {
Expand Down

0 comments on commit 286ac92

Please sign in to comment.