/
PdfInfo.go
69 lines (59 loc) · 1.5 KB
/
PdfInfo.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package endpoint
import (
"encoding/json"
"strings"
"github.com/dynamicpdf-api/go-client/v2/resource"
)
// Represents the pdf info endpoint.
type PdfInfo struct {
Endpoint
resource.Resource
resource resource.PdfResource
}
/*
Initializes a new instance of the `PdfInfo` class.
- @param {Resource} resource The resource of type `PdfResource`
*/
func NewPdfInfoResource(resource resource.PdfResource) *PdfInfo {
var ep PdfInfo
ep.resource = resource
return &ep
}
var _ EndpointProcessor = (*PdfInfo)(nil)
func (p *PdfInfo) BaseUrl() string {
return p.Endpoint.BaseUrl
}
func (p *PdfInfo) ApiKey() string {
return p.Endpoint.ApiKey
}
func (p *PdfInfo) EndpointName() string {
return "pdf-info"
}
/*
Process the pdf resource to get pdf's information.
- @returns A Promise of PdfInfo response
*/
func (p *PdfInfo) Process() <-chan PdfInfoResponse {
restResponse := make(chan PdfInfoResponse)
postUrl := strings.TrimSuffix(p.Endpoint.BaseUrl, "/") + "/v1.0/" + p.EndpointName()
postAuth := "Bearer " + p.Endpoint.ApiKey
go func() {
res, err := postHttpRequest(postUrl, p.resource.Data(), postAuth, "application/pdf")
if err != nil {
res.clientError = err
}
pdfRes := PdfInfoResponse{JsonResponse: res}
restResponse <- pdfRes
}()
return restResponse
}
func (p PdfInfo) MarshalJSON() ([]byte, error) {
type Alias PdfInfo
return json.Marshal(&struct {
ResourceName resource.PdfResource `json:"resourceName,omitempty"`
Alias
}{
ResourceName: p.resource,
Alias: (Alias)(p),
})
}