Documentation ¶
Overview ¶
Package unpaywall provides utitlity functions for the unpaywall.org api
Index ¶
- type SearchResult
- type Unpaywall
- func (u *Unpaywall) DownloadByDOI(doi string, targetPath string) (string, error)
- func (u *Unpaywall) DownloadByDOIs(dois []string, targetPath string) (<-chan string, <-chan error)
- func (u *Unpaywall) RequestByDOI(doi string) (*SearchResult, error)
- func (u *Unpaywall) RequestByDOIs(dois []string) (<-chan *SearchResult, <-chan error)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type SearchResult ¶
type SearchResult struct { StatusCode int BestOaLocation struct { Evidence string `json:"evidence"` HostType string `json:"host_type"` IsBest bool `json:"is_best"` License string `json:"license"` PmhID string `json:"pmh_id"` Updated string `json:"updated"` URL string `json:"url"` URLForLandingPage string `json:"url_for_landing_page"` URLForPdf string `json:"url_for_pdf"` Version string `json:"version"` } `json:"best_oa_location"` DataStandard int `json:"data_standard"` Doi string `json:"doi"` DoiURL string `json:"doi_url"` Genre string `json:"genre"` IsOa bool `json:"is_oa"` JournalIsInDoaj bool `json:"journal_is_in_doaj"` JournalIsOa bool `json:"journal_is_oa"` JournalIssns string `json:"journal_issns"` JournalName string `json:"journal_name"` OaLocations []struct { Evidence string `json:"evidence"` HostType string `json:"host_type"` IsBest bool `json:"is_best"` License string `json:"license"` PmhID string `json:"pmh_id"` Updated string `json:"updated"` URL string `json:"url"` URLForLandingPage string `json:"url_for_landing_page"` URLForPdf string `json:"url_for_pdf"` Version string `json:"version"` } `json:"oa_locations"` PublishedDate string `json:"published_date"` Publisher string `json:"publisher"` Title string `json:"title"` Updated string `json:"updated"` XReportedNoncompliantCopies []interface{} `json:"x_reported_noncompliant_copies"` Year int `json:"year"` ZAuthors []struct { Family string `json:"family"` Given string `json:"given"` } `json:"z_authors"` }
SearchResult describes the returned data structure from unpaywall
type Unpaywall ¶
type Unpaywall struct {
// contains filtered or unexported fields
}
Unpaywall provides methods to request the unpaywall api
func (*Unpaywall) DownloadByDOI ¶
DownloadByDOI searches for the paper by DOI and downloads it to the target path returns the filename / error
Example ¶
package main import ( "log" unpaywall "github.com/JVecsei/go-unpaywall" ) func main() { // your email address var email string // DOI var doi string u, _ := unpaywall.New(email) var targetPath = "./" file, err := u.DownloadByDOI(doi, targetPath) if err != nil { log.Fatalf("Error: %v", err) } log.Printf("Success! Downloaded file to %s", file) }
Output:
func (*Unpaywall) DownloadByDOIs ¶
DownloadByDOIs searches for the papers by DOI and downloads all found documents to the target path returns the filenames / errors
Example ¶
package main import ( "fmt" unpaywall "github.com/JVecsei/go-unpaywall" ) func main() { // your email address var email string // DOIs var dois []string // target directory var target string u, _ := unpaywall.New(email) res, err := u.DownloadByDOIs(dois, target) for err != nil || res != nil { select { case r, ok := <-res: if !ok { res = nil continue } fmt.Printf("Downloaded file to: %s \n", r) case e, ok := <-err: if !ok { err = nil continue } fmt.Printf("Error: %s \n", e) } } }
Output:
func (*Unpaywall) RequestByDOI ¶
func (u *Unpaywall) RequestByDOI(doi string) (*SearchResult, error)
RequestByDOI sends a new request to unpaywall with the given DOI
Example ¶
package main import ( "fmt" "log" unpaywall "github.com/JVecsei/go-unpaywall" ) func main() { // your email address var email string // DOI var doi string u, _ := unpaywall.New(email) // Request example result, err := u.RequestByDOI(doi) if err != nil { log.Fatalf("Error: %v", err) } fmt.Printf("Search result: %v", result) }
Output:
func (*Unpaywall) RequestByDOIs ¶
func (u *Unpaywall) RequestByDOIs(dois []string) (<-chan *SearchResult, <-chan error)
RequestByDOIs searches for the papers by DOI and returns all found results / errors
Example ¶
package main import ( "fmt" unpaywall "github.com/JVecsei/go-unpaywall" ) func main() { // your email address var email string // DOIs var dois []string u, _ := unpaywall.New(email) res, err := u.RequestByDOIs(dois) for err != nil || res != nil { select { case r, ok := <-res: if !ok { res = nil continue } fmt.Printf("Found: %s \n", r.BestOaLocation.URLForPdf) case e, ok := <-err: if !ok { err = nil continue } fmt.Printf("Error: %s \n", e) } } }
Output:
Click to show internal directories.
Click to hide internal directories.