/
openaccess.go
67 lines (50 loc) · 1.75 KB
/
openaccess.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
package openaccess
import (
"github.com/aaronland/go-smithsonian-openaccess/edan"
"strings"
)
const SCREEN_IMAGE string = "Screen Image"
// https://edan.si.edu/openaccess/docs/more.html
type OpenAccessRecord struct {
Id string `json:"id"`
Title string `json:title"`
UnitCode string `json:"unitCode"`
LinkedId string `json:"linkedId"`
Type string `json:"type"`
URL string `json:"url"`
Content edan.IIMObjectRecord `json:"content"`
Hash string `json:"hash"`
DocSignature string `json:"docSignature"`
Timestamp int64 `json:"timestamp"`
LastTimeUpdated int64 `json:"lastTimeUpdated"`
Status int `json:"status"`
Version string `json:"version"`
PublicSearch bool `json:"publicSearch"`
Extensions interface{} `json:"extensions"`
}
func (rec *OpenAccessRecord) OnlineMedia() (edan.IIMOnlineMedia, error) {
return rec.Content.DescriptiveNonRepeating.OnlineMedia, nil
}
func (rec *OpenAccessRecord) ImageURLsWithLabel(label string) ([]string, error) {
online_media, err := rec.OnlineMedia()
if err != nil {
return nil, err
}
urls := make([]string, 0)
for _, m := range online_media.Media {
for _, r := range m.Resources {
if r.Label == label {
urls = append(urls, r.URL)
}
}
}
return urls, nil
}
func (rec *OpenAccessRecord) CreditLine() string {
entries := rec.Content.FreeText.CreditLine
phrases := make([]string, 0)
for _, e := range entries {
phrases = append(phrases, e.Content)
}
return strings.Join(phrases, " ")
}