-
Notifications
You must be signed in to change notification settings - Fork 1
/
rmeta.go
93 lines (73 loc) · 2.1 KB
/
rmeta.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package tika
import (
"errors"
"net/http"
)
// RecursiveMetaResource represents the structure of our Recursive Meta resource
type RecursiveMetaResource struct {
client *Client
endpoint string
}
// RMeta is the entry point for interacting with the Recursive Meta resource
func (c *Client) RMeta() *RecursiveMetaResource {
endpoint := c.Url + "/rmeta"
return &RecursiveMetaResource{client: c,
endpoint: endpoint,
}
}
// Html returns a list of Metadata objects for the container document and all embedded documents as HTML
func (rmr *RecursiveMetaResource) Html() (string, error) {
rmr.endpoint += "/html"
req, err := rmr.newRequest()
if err != nil {
return "", err
}
res, err := rmr.client.raw(req)
return string(res), err
}
// Ignore returns the metadata only
func (rmr *RecursiveMetaResource) Ignore() (string, error) {
rmr.endpoint += "/ignore"
req, err := rmr.newRequest()
if err != nil {
return "", err
}
res, err := rmr.client.raw(req)
return string(res), err
}
// Json returns a list of Metadata objects for the container document and all embedded documents as JSON
func (rmr *RecursiveMetaResource) Json() ([]byte, error) {
req, err := rmr.newRequest()
if err != nil {
return nil, err
}
return rmr.client.raw(req)
}
// Raw returns a list of Metadata objects for the container document and all embedded documents as bytes
func (rmr *RecursiveMetaResource) Raw() ([]byte, error) {
req, err := rmr.newRequest()
if err != nil {
return nil, err
}
return rmr.client.raw(req)
}
// Text returns a list of Metadata objects for the container document and all embedded documents as plain text
func (rmr *RecursiveMetaResource) Text() (string, error) {
rmr.endpoint += "/text"
req, err := rmr.newRequest()
if err != nil {
return "", err
}
res, err := rmr.client.raw(req)
return string(res), err
}
func (rmr *RecursiveMetaResource) newRequest() (*http.Request, error) {
if rmr.client.Document == nil {
return nil, errors.New("need a document")
}
req, err := rmr.client.NewRequest(http.MethodPut, rmr.endpoint, rmr.client.Document)
if err != nil {
return nil, err
}
return req, nil
}