-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathissn2ppn.go
62 lines (52 loc) · 1.34 KB
/
issn2ppn.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
package gosudoc
import (
"encoding/xml"
"errors"
)
// Issn2ppnData: used to unmarshal the XML returned by Sudoc
// for the issn2ppn web service
type Issn2ppnData struct {
Err string `xml:"error"`
Pairs []struct {
Issn string `xml:"issn,omitempty"`
PPNs []string `xml:"result>ppn"`
PPNsNoHolding []string `xml:"resultNoHolding>ppn"`
} `xml:"query"`
}
// Issn2ppn takes 1 or more ISSNs
// and will return the corresponding sudoc record IDs
func Issn2ppn(input []string) (map[string][]string, error) {
result := make(map[string][]string)
// construct the url
baseURL := "http://www.sudoc.fr/services/issn2ppn"
getURL, err := getQryString(baseURL, input)
if err != nil {
return result, err
}
// call Sudoc & put the response into a []byte
b, err := callSudoc(getURL)
// unmarshall
var parsedResp Issn2ppnData
if xml.Unmarshal(b, &parsedResp); err != nil {
return result, err
}
if parsedResp.Err != "" {
ErrNoResult := errors.New("No result")
return result, ErrNoResult
}
for _, v := range parsedResp.Pairs {
PResults := []string{}
if len(v.PPNs) > 0 {
for _, value := range v.PPNs {
PResults = append(PResults, value)
}
}
if len(v.PPNsNoHolding) > 0 {
for _, value := range v.PPNsNoHolding {
PResults = append(PResults, value)
}
}
result[v.Issn] = PResults
}
return result, nil
}