-
Notifications
You must be signed in to change notification settings - Fork 1
/
crossref_test.go
53 lines (43 loc) · 1.41 KB
/
crossref_test.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
package crossref_test
import (
"fmt"
"github.com/cgxeiji/crossref"
)
var client = crossref.NewClient("Crossref Go", "mail@example.com")
func Example() {
// If you want to debug the library, uncomment the following line:
// crossref.Debug()
// Search for a publication by doing a query. This returns up to 10 works
// that match the query terms.
search := "Slow Robots for Unobtrusive Posture Correction"
works, err := client.Query(search)
switch err {
case crossref.ErrZeroWorks:
fmt.Println("No works found")
case crossref.ErrEmptyQuery:
fmt.Println("An empty query was requested")
case nil:
default:
panic(err)
}
fmt.Printf("Found %d article(s) for query:\n > %q\n", len(works), search)
// Retrieve information directly from a DOI
doi := works[0].DOI
work, err := client.DOI(doi)
switch err {
case crossref.ErrZeroWorks:
fmt.Println("No works found")
case crossref.ErrEmptyQuery:
fmt.Println("An empty query was requested")
case nil:
default:
panic(err)
}
fmt.Printf("For DOI: %q found:\n", doi)
fmt.Printf(" > %q, (%v) %q\n", work.Title, work.Date, work.Authors)
// Output:
// Found 10 article(s) for query:
// > "Slow Robots for Unobtrusive Posture Correction"
// For DOI: "10.1145/3290605.3300843" found:
// > "Slow Robots for Unobtrusive Posture Correction", (2019) ["Shin, Joon-Gi" "Onchi, Eiji" "Reyes, Maria Jose" "Song, Junbong" "Lee, Uichin" "Lee, Seung-Hee" "Saakes, Daniel"]
}