Skip to content

Commit

Permalink
add GetPreprintByID
Browse files Browse the repository at this point in the history
  • Loading branch information
azaky committed May 11, 2022
1 parent 15f4347 commit 48ad446
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
7 changes: 7 additions & 0 deletions examples/preprints/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
18 changes: 18 additions & 0 deletions osf/preprints.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package osf

import (
"context"
"fmt"
)

type PreprintsService service
Expand Down Expand Up @@ -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
}

0 comments on commit 48ad446

Please sign in to comment.