diff --git a/examples/preprints/main.go b/examples/preprints/main.go index cf0ef12..5b6ad55 100644 --- a/examples/preprints/main.go +++ b/examples/preprints/main.go @@ -31,4 +31,11 @@ func main() { spew.Dump(res) spew.Dump(preprints) + + preprint, err := client.Preprints.GetPreprintByID(ctx, preprints[0].ID) + if err != nil { + log.Fatal(err) + } + + spew.Dump(preprint) } diff --git a/osf/preprints.go b/osf/preprints.go index 7319e43..f2d03d3 100644 --- a/osf/preprints.go +++ b/osf/preprints.go @@ -2,6 +2,7 @@ package osf import ( "context" + "fmt" ) type PreprintsService service @@ -78,3 +79,20 @@ func (s *PreprintsService) ListPreprints(ctx context.Context, opts *PreprintsLis return preprints, res, nil } + +func (s *PreprintsService) GetPreprintByID(ctx context.Context, id string) (*Preprint, error) { + u := fmt.Sprintf("preprints/%s", id) + + req, err := s.client.NewRequest("GET", u, nil) + if err != nil { + return nil, err + } + + var preprint Preprint + _, err = s.client.Do(ctx, req, &preprint) + if err != nil { + return nil, err + } + + return &preprint, nil +}