-
Notifications
You must be signed in to change notification settings - Fork 1
/
readwise.go
51 lines (43 loc) · 1.05 KB
/
readwise.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
package main
import (
"bytes"
"fmt"
"io/ioutil"
"net/http"
)
type Highlight struct {
DocumentID string `json:"document_id"`
Text string `json:"text"`
Title string `json:"title"`
Author string `json:"author"`
SourceType string `json:"source_type"`
Category string `json:"category"`
LocationType string `json:"location_type"`
Location int `json:"location"`
}
type ReadWise struct {
Highlights []Highlight `json:"highlights"`
}
const url = "https://readwise.io/api/v2/highlights/"
func SendRequest(data []byte, token string) (body []byte, err error) {
client := http.Client{}
req, err := http.NewRequest("POST", url, bytes.NewReader(data))
if err != nil {
return
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorizaton", "Token "+token)
res, err := client.Do(req)
if err != nil {
return
}
body, err = ioutil.ReadAll(res.Body)
if err != nil {
return
}
if res.StatusCode != http.StatusOK {
err = fmt.Errorf("not ok, Status: %d", res.StatusCode)
return
}
return body, nil
}