-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathitem.go
45 lines (38 loc) · 1.06 KB
/
item.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
package internetarchive
import (
"encoding/json"
"io/ioutil"
"net/http"
)
type Item struct {
Identifier string `json:"identifier"`
Downloads float64 `json:"downloads"`
Date string `json:"date"`
AvgRating string `json:"avg_rating"`
Metadata metadata `json:"-"`
}
type metadata struct {
Created float64 `json:"created"`
Dir string `json:"dir"`
Files []map[string]interface{} `json:"files"`
FilesCount float64 `json:"files_count"`
ItemSize float64 `json:"item_size"`
Reviews []map[string]interface{} `json:"reviews"`
CustomData map[string]interface{} `json:"metadata"`
}
func (item *Item) GetMetadata() error {
requestUrl := "http://archive.org/metadata/" + item.Identifier
// GET request to Archive Metadata API
r, err := http.Get(requestUrl)
if err != nil {
return err
}
// read response
data, err := ioutil.ReadAll(r.Body)
check(err)
// unmarshal response
if err := json.Unmarshal(data, &item.Metadata); err != nil {
return err
}
return nil
}