-
Notifications
You must be signed in to change notification settings - Fork 1
/
requests.go
41 lines (38 loc) · 971 Bytes
/
requests.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package novapost
import (
"bytes"
"io"
)
const (
AddressModel = "Address"
AddressGeneralModel = "AddressGeneral"
CounterpartyModel = "Counterparty"
ContactPersonModel = "ContactPerson"
ScanSheetModel = "ScanSheet"
CommonModel = "Common"
CommonGeneralModel = "CommonGeneral"
AdditionalServiceModel = "AdditionalService"
InternetDocumentModel = "InternetDocument"
TrackingDocumentModel = "TrackingDocument"
)
func RawRequest[Res any](c *Client, model, method string, props any) (*Response[Res], error) {
b, err := c.Marshaler(Request{c.apiKey, model, method, props})
if err != nil {
return nil, err
}
res, err := c.HTTPClient.Post(c.Url, "", bytes.NewBuffer(b))
if err != nil {
return nil, err
}
b, err = io.ReadAll(res.Body)
if err != nil {
return nil, err
}
resp := &Response[Res]{}
err = c.Unmarshaler(b, resp)
if err != nil {
return nil, err
}
_ = res.Body.Close()
return resp, nil
}