Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test pr #1

Closed
wants to merge 32 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
87362f1
delete logging
joshuabezaleel May 12, 2022
50248bc
TODO: FileLinks
joshuabezaleel May 12, 2022
b7a4599
In Progress: Add Files group endpoint
joshuabezaleel May 12, 2022
1a423f8
Move Timestamp to osf.go
joshuabezaleel May 12, 2022
c2ee13e
Add example for file, fix jsonapi structtag ID
joshuabezaleel May 12, 2022
60cfbb4
strip jsonapi lib + implement own response model with generics
azaky May 13, 2022
d2f248b
use mapstructure for unmarshaling FileLinks
azaky May 13, 2022
b3dff1c
complete Links and Relationships objects + build function
azaky May 13, 2022
0649900
add missing buildFile
azaky May 13, 2022
9529109
IN PROGRESS: Download file
joshuabezaleel May 13, 2022
612a74f
IN PROGRESS: Download file
joshuabezaleel May 13, 2022
b422b92
Resolve conflict
joshuabezaleel May 13, 2022
0141e18
Download File
joshuabezaleel May 13, 2022
8eabc39
implement list preprints providers
azaky May 15, 2022
82e8680
Enable filter query params for list endpoint
joshuabezaleel May 15, 2022
606e198
Add test for Preprints_List
joshuabezaleel May 15, 2022
f50fd9f
Remove Citations for now
joshuabezaleel May 15, 2022
a67f9e5
Add test for Files.GetFileByID
joshuabezaleel May 15, 2022
7283827
implement create preprints
azaky May 15, 2022
c983829
add update preprints
azaky May 15, 2022
675cfe8
add get preprints primary files
azaky May 15, 2022
337f55a
add readme
azaky May 15, 2022
968bd38
add license
azaky May 16, 2022
d0b3b0a
inject pagination meta into ManyPayload
azaky May 16, 2022
09baeb5
remove debug
azaky May 16, 2022
6ff6e13
cleanup
azaky May 16, 2022
9fa961a
update examples
azaky May 16, 2022
70060a5
add docs
azaky May 16, 2022
0951271
bump to v0.0.3
azaky May 16, 2022
b07b705
add github actions
azaky May 16, 2022
6df235e
add tests badge
azaky May 16, 2022
0cea967
test change pr branch
joshuabezaleel Jun 7, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
on:
push:
branches:
- main
pull_request:
branches:
- main

name: tests

jobs:
test:
strategy:
matrix:
go-version: [1.18.x]
platform: [ubuntu-latest, windows-latest]
runs-on: ${{ matrix.platform }}

steps:
- uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}
- uses: actions/checkout@v3

- name: Run go test
run: go test -v -race -covermode atomic ./...
9 changes: 0 additions & 9 deletions .gitpod.yml

This file was deleted.

21 changes: 21 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 Joshua Bezaleel Abednego

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
72 changes: 72 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Open Science Framework (OSF) SDK for Golang

[![Go Version](https://img.shields.io/github/go-mod/go-version/joshuabezaleel/go-osf)](https://github.com/joshuabezaleel/go-osf)
[![GoDoc](https://img.shields.io/static/v1?label=godoc&message=reference&color=blue)](https://pkg.go.dev/github.com/joshuabezaleel/go-osf@v0.0.3/osf)
[![tests](https://github.com/joshuabezaleel/go-osf/actions/workflows/tests.yaml/badge.svg)](https://github.com/joshuabezaleel/go-osf/actions/workflows/tests.yaml)
[![Go Report Card](https://goreportcard.com/badge/github.com/joshuabezaleel/go-osf)](https://goreportcard.com/report/github.com/joshuabezaleel/go-osf)

go-osf if a Go client library for accessing the [Open Science Framework (OSF)](https://osf.io) [API](https://developer.osf.io/).

## Installation

test change

go-osf makes use of the [generics](https://go.dev/doc/tutorial/generics), so it requires Go v1.18.

To use this library within a Go module project:

```
go get github.com/joshuabezaleel/go-osf
```

## Usage

An OSF access token is required to use this library. You can create one from the [OSF settings page](https://osf.io/settings/tokens). You can [create an account](https://osf.io/register) if you haven't had already.

The following code gets the first 100 public [preprints](https://osf.io/preprints/) from the OSF.

```go
package main

import (
"context"
"log"

"github.com/joshuabezaleel/go-osf/osf"
"golang.org/x/oauth2"
)

func main() {
ctx := context.Background()
ts := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: "your token here ..."},
)
tc := oauth2.NewClient(ctx, ts)

client := osf.NewClient(tc)

opts := &osf.PreprintsListOptions{
ListOptions: osf.ListOptions{
Page: 1,
PerPage: 100,
},
}
preprints, _, err := client.Preprints.ListPreprints(ctx, opts)
if err != nil {
log.Fatal(err)
}

for _, preprint := range preprints {
log.Printf("URL: %s", *preprint.Links.Html)
log.Printf("Title: %s", preprint.Title)
log.Printf("Description: %s", preprint.Description)
}

}
```

Head over to the [examples folder](examples) or [pkg.go.dev](https://pkg.go.dev/github.com/joshuabezaleel/go-osf) for more usage examples.

## License

This library is distributed under the MIT license found in the [LICENSE.txt](LICENSE.txt) file.
9 changes: 9 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# go-osf Examples

Before running any examples here, you need to export the OSF API token to `OSF_API_TOKEN` environment variable.

Then, run any example:

```
go run preprints/main.go
```
67 changes: 67 additions & 0 deletions examples/create_preprints/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
For this example, we use the most cited paper on the earth.

Source: https://pubmed.ncbi.nlm.nih.gov/14907713/
Paper: https://www.jbc.org/article/S0021-9258(19)52451-6/pdf

Before running this example, download the paper first:

wget "https://www.jbc.org/article/S0021-9258(19)52451-6/pdf" -O paper.pdf

*/

package main

import (
"context"
"log"
"os"
"time"

"github.com/davecgh/go-spew/spew"
"github.com/joshuabezaleel/go-osf/osf"
"golang.org/x/oauth2"
)

func main() {
ctx := context.Background()
ts := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: os.Getenv("OSF_API_TOKEN")},
)
tc := oauth2.NewClient(ctx, ts)

client := osf.NewClient(tc)

req := &osf.PreprintRequest{
PreprintProviderID: "osf",
Title: osf.StringPointer("PROTEIN MEASUREMENT WITH THE FOLIN PHENOL REAGENT"),
Description: osf.StringPointer("Since 1922 when Wu proposed the use of the Folin phenol reagent for the measurement of proteins (l), a number of modified analytical procedures ut.ilizing this reagent have been reported for the determination of proteins in serum (2-G), in antigen-antibody precipitates (7-9), and in insulin (10). Although the reagent would seem to be recommended by its great sensitivity and the simplicity of procedure possible with its use, it has not found great favor for general biochemical purposes. In the belief that this reagent, nevertheless, has considerable merit for certain application, but that its peculiarities and limitations need to be understood for its fullest exploitation, it has been studied with regard t.o effects of variations in pH, time of reaction, and concentration of reactants, permissible levels of reagents commonly used in handling proteins, and interfering subst.ances. Procedures are described for measuring protein in solution or after precipitation wit,h acids or other agents, and for the determination of as little as 0.2 y of protein."),
OriginalPublicationDate: osf.MustParseTime(time.RFC3339, "1951-05-28T00:00:00.000Z"),
Subjects: &[][]string{
{
"584240da54be81056cecaab0", // Life Sciences
"584240da54be81056cecac22", // Biochemistry, Biophysics, and Structural Biology
"584240d954be81056ceca961", // Biochemistry
},
},
Tags: &[]string{"protein measurement", "folin phenol reagent"},
HasDataLinks: osf.NotApplicable,
HasPreregLinks: osf.NotApplicable,
HasCOI: osf.BoolPointer(false),
IsPublished: osf.BoolPointer(false),
}

file, err := os.Open("paper.pdf")
if err != nil {
log.Fatal(err)
}
defer file.Close()

preprint, _, err := client.Preprints.CreatePreprint(ctx, req, file)

if err != nil {
log.Fatal(err)
}

spew.Dump(preprint)
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@ func main() {
tc := oauth2.NewClient(ctx, ts)

client := osf.NewClient(tc)
err := client.Citations.ListCitationsStyles(ctx)

file, _, err := client.Preprints.GetPreprintPrimaryFileByID(ctx, "xfdsr")
if err != nil {
log.Fatal(err)
}

err = client.Files.DownloadFile(ctx, "", "", file)
if err != nil {
log.Fatal(err)
}
}
35 changes: 35 additions & 0 deletions examples/files/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package main

import (
"context"
"log"
"os"

"github.com/davecgh/go-spew/spew"
"github.com/joshuabezaleel/go-osf/osf"
"golang.org/x/oauth2"
)

func main() {
ctx := context.Background()
ts := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: os.Getenv("OSF_API_TOKEN")},
)
tc := oauth2.NewClient(ctx, ts)

client := osf.NewClient(tc)
fileID := "553e69248c5e4a219919ea54"

file, _, err := client.Files.GetFileByID(ctx, fileID)
if err != nil {
log.Fatal(err)
}

spew.Dump(file)

err = client.Files.DownloadFile(ctx, "", "", file)
if err != nil {
log.Fatal(err)
}
// spew.Dump(res)
}
20 changes: 20 additions & 0 deletions examples/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module github.com/joshuabezaleel/go-osf/examples

go 1.18

require (
github.com/davecgh/go-spew v1.1.1
github.com/joshuabezaleel/go-osf v0.0.2
golang.org/x/oauth2 v0.0.0-20220411215720-9780585627b5
)

require (
github.com/golang/protobuf v1.4.2 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd // indirect
google.golang.org/appengine v1.6.6 // indirect
google.golang.org/protobuf v1.25.0 // indirect
)

replace github.com/joshuabezaleel/go-osf => ../
Loading