diff --git a/unpaywall.go b/unpaywall.go index b455e3c..fa9b6ae 100644 --- a/unpaywall.go +++ b/unpaywall.go @@ -19,7 +19,7 @@ type UnpaywallService struct { // DOI lookup response from unpaywall type unpaywallDOIResponse struct { - BestOaLocation unpaywallLocation `json:"best_oa_location"` + OaLocations []unpaywallLocation `json:"oa_locations"` } type unpaywallLocation struct { @@ -41,28 +41,28 @@ func (u UnpaywallService) Lookup(doi string) (*DoiInfo, error) { var doiResponse DoiInfo - // For now we'll only return the best location for the manuscript - location := results.BestOaLocation - - // Get the file name from the decoded url for pdf - // but log any problems do not cause response to fail - var fileName string - decodedURLForPdf, err := url.QueryUnescape(location.URLForPdf) - if err != nil { - log.Printf("file name decoding failed: %s", err) - } else { - splitURLForPdf := strings.Split(decodedURLForPdf, "/") - fileName = splitURLForPdf[len(splitURLForPdf)-1] - } - - if location.URLForPdf != "" { - doiResponse.Manuscripts = append(doiResponse.Manuscripts, Manuscript{ - Location: location.URLForPdf, - RepositoryInstitution: location.RepositoryInstitution, - Type: "application/pdf", - Source: "Unpaywall", - Name: fileName, - }) + for _, location := range results.OaLocations { + if location.URLForPdf != "" { + + // Get the file name from the decoded url for pdf + // but log any problems do not cause response to fail + var fileName string + decodedURLForPdf, err := url.QueryUnescape(location.URLForPdf) + if err != nil { + log.Printf("file name decoding failed: %s", err) + } else { + splitURLForPdf := strings.Split(decodedURLForPdf, "/") + fileName = splitURLForPdf[len(splitURLForPdf)-1] + } + + doiResponse.Manuscripts = append(doiResponse.Manuscripts, Manuscript{ + Location: location.URLForPdf, + RepositoryInstitution: location.RepositoryInstitution, + Type: "application/pdf", + Source: "Unpaywall", + Name: fileName, + }) + } } return &doiResponse, nil diff --git a/unpaywall_test.go b/unpaywall_test.go index 5eb4692..a5375a6 100644 --- a/unpaywall_test.go +++ b/unpaywall_test.go @@ -25,6 +25,20 @@ func TestUnpaywall(t *testing.T) { Source: "Unpaywall", Name: "Nanometer-Scale Thermometry.pdf", }, + { + Location: "http://europepmc.org/articles/pmc4221854?pdf=render", + RepositoryInstitution: "pubmedcentral.nih.gov", + Type: "application/pdf", + Source: "Unpaywall", + Name: "pmc4221854?pdf=render", + }, + { + Location: "http://arxiv.org/pdf/1304.1068", + RepositoryInstitution: "arXiv.org", + Type: "application/pdf", + Source: "Unpaywall", + Name: "1304.1068", + }, }, }