Skip to content

Commit

Permalink
rename some variables
Browse files Browse the repository at this point in the history
  • Loading branch information
mfenner committed May 8, 2024
1 parent 4948b76 commit 61b67d5
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 27 deletions.
10 changes: 5 additions & 5 deletions cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ var listCmd = &cobra.Command{
}

if str != "" && from == "crossref" {
data, err = crossref.LoadList(str)
data, err = crossref.LoadAll(str)
} else if str != "" && from == "crossrefxml" {
data, err = crossrefxml.LoadList(str)
data, err = crossrefxml.LoadAll(str)
} else if str != "" && from == "datacite" {
data, err = datacite.LoadList(str)
data, err = datacite.LoadAll(str)
} else if from == "crossref" {
data, err = crossref.FetchList(number, member, type_, sample, hasORCID, hasROR, hasReferences, hasRelation, hasAbstract, hasAward, hasLicense, hasArchive)
data, err = crossref.FetchAll(number, member, type_, sample, hasORCID, hasROR, hasReferences, hasRelation, hasAbstract, hasAward, hasLicense, hasArchive)
} else if from == "datacite" {
data, err = datacite.FetchList(number, sample)
data, err = datacite.FetchAll(number, sample)
}
if err != nil {
fmt.Println(err)
Expand Down
4 changes: 2 additions & 2 deletions cmd/sample.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ var sampleCmd = &cobra.Command{
var err error
sample := true
if from == "crossref" {
data, err = crossref.FetchList(number, member, type_, sample, hasORCID, hasROR, hasReferences, hasRelation, hasAbstract, hasAward, hasLicense, hasArchive)
data, err = crossref.FetchAll(number, member, type_, sample, hasORCID, hasROR, hasReferences, hasRelation, hasAbstract, hasAward, hasLicense, hasArchive)
} else if from == "datacite" {
data, err = datacite.FetchList(number, sample)
data, err = datacite.FetchAll(number, sample)
}
if err != nil {
fmt.Println(err)
Expand Down
13 changes: 13 additions & 0 deletions commonmeta/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,25 @@
package commonmeta

import (
"bufio"
"encoding/json"
"errors"
"io"
"os"
"path"
)

type Reader struct {
r *bufio.Reader
}

// NewReader returns a new Reader that reads from r.
func NewReader(r io.Reader) *Reader {
return &Reader{
r: bufio.NewReader(r),
}
}

// ContributorRoles list of contributor roles defined in commonmeta schema.
//
// from commonmeta schema
Expand Down
13 changes: 13 additions & 0 deletions commonmeta/writer.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
package commonmeta

import (
"bufio"
"encoding/json"
"fmt"
"io"

"github.com/front-matter/commonmeta/schemautils"
"github.com/xeipuuv/gojsonschema"
)

type Writer struct {
w *bufio.Writer
}

// NewWriter returns a new Writer that writes to w.
func NewWriter(w io.Writer) *Writer {
return &Writer{
w: bufio.NewWriter(w),
}
}

// Write writes commonmeta metadata.
func Write(data Data) ([]byte, []gojsonschema.ResultError) {
output, err := json.Marshal(data)
Expand Down
26 changes: 19 additions & 7 deletions crossref/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package crossref

import (
"bufio"
"encoding/json"
"errors"
"fmt"
Expand All @@ -24,6 +25,17 @@ import (
"github.com/front-matter/commonmeta/utils"
)

type Reader struct {
r *bufio.Reader
}

// NewReader returns a new Reader that reads from r.
func NewReader(r io.Reader) *Reader {
return &Reader{
r: bufio.NewReader(r),
}
}

// Content is the struct for the message in tge JSON response from the Crossref API
type Content struct {
ID string `json:"id"`
Expand Down Expand Up @@ -255,11 +267,11 @@ func Fetch(str string) (commonmeta.Data, error) {
return data, nil
}

// FetchList gets the metadata for a list of works from the Crossref API and converts it to the Commonmeta format
func FetchList(number int, member string, _type string, sample bool, hasORCID bool, hasROR bool, hasReferences bool, hasRelation bool, hasAbstract bool, hasAward bool, hasLicense bool, hasArchive bool) ([]commonmeta.Data, error) {
// FetchAll gets the metadata for a list of works from the Crossref API and converts it to the Commonmeta format
func FetchAll(number int, member string, _type string, sample bool, hasORCID bool, hasROR bool, hasReferences bool, hasRelation bool, hasAbstract bool, hasAward bool, hasLicense bool, hasArchive bool) ([]commonmeta.Data, error) {

var data []commonmeta.Data
content, err := GetList(number, member, _type, sample, hasORCID, hasROR, hasReferences, hasRelation, hasAbstract, hasAward, hasLicense, hasArchive)
content, err := GetAll(number, member, _type, sample, hasORCID, hasROR, hasReferences, hasRelation, hasAbstract, hasAward, hasLicense, hasArchive)
if err != nil {
return data, err
}
Expand Down Expand Up @@ -317,8 +329,8 @@ func Get(pid string) (Content, error) {
return response.Message, err
}

// GetList gets the metadata for a list of works from the Crossref API
func GetList(number int, member string, _type string, sample bool, hasORCID bool, hasROR bool, hasReferences bool, hasRelation bool, hasAbstract bool, hasAward bool, hasLicense bool, hasArchive bool) ([]Content, error) {
// GetAll gets the metadata for a list of works from the Crossref API
func GetAll(number int, member string, _type string, sample bool, hasORCID bool, hasROR bool, hasReferences bool, hasRelation bool, hasAbstract bool, hasAward bool, hasLicense bool, hasArchive bool) ([]Content, error) {
// the envelope for the JSON response from the Crossref API
type Response struct {
Status string `json:"status"`
Expand Down Expand Up @@ -392,8 +404,8 @@ func Load(filename string) (commonmeta.Data, error) {
return data, nil
}

// LoadList loads the metadata for a list of works from a JSON file and converts it to the Commonmeta format
func LoadList(filename string) ([]commonmeta.Data, error) {
// LoadAll loads the metadata for a list of works from a JSON file and converts it to the Commonmeta format
func LoadAll(filename string) ([]commonmeta.Data, error) {
var data []commonmeta.Data
var content []Content
var err error
Expand Down
8 changes: 4 additions & 4 deletions crossref/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func ExampleQueryURL() {
// https://api.crossref.org/works?filter=member%3A340%2Ctype%3Ajournal-article&order=desc&rows=10&sort=published
}

func TestGetList(t *testing.T) {
func TestGetAll(t *testing.T) {
t.Parallel()

type testCase struct {
Expand All @@ -143,12 +143,12 @@ func TestGetList(t *testing.T) {
{number: 2, member: "", _type: "", sample: true},
}
for _, tc := range testCases {
got, err := crossref.GetList(tc.number, tc.member, tc._type, true, false, false, false, false, false, false, false, false)
got, err := crossref.GetAll(tc.number, tc.member, tc._type, true, false, false, false, false, false, false, false, false)
if err != nil {
t.Errorf("GetList (%v): error %v", tc.number, err)
t.Errorf("GetAll (%v): error %v", tc.number, err)
}
if diff := cmp.Diff(tc.number, len(got)); diff != "" {
t.Errorf("GetList mismatch (-want +got):\n%s", diff)
t.Errorf("GetAll mismatch (-want +got):\n%s", diff)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions crossrefxml/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -1180,8 +1180,8 @@ func Load(filename string) (commonmeta.Data, error) {
return data, nil
}

// LoadList loads the metadata for a list of works from an XML file and converts it to the Commonmeta format
func LoadList(filename string) ([]commonmeta.Data, error) {
// LoadAll loads the metadata for a list of works from an XML file and converts it to the Commonmeta format
func LoadAll(filename string) ([]commonmeta.Data, error) {
type Response struct {
ListRecords struct {
Record []struct {
Expand Down
14 changes: 7 additions & 7 deletions datacite/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,10 +274,10 @@ func Fetch(str string) (commonmeta.Data, error) {
return data, nil
}

// FetchList gets the metadata for a list of works from the DataCite API and returns Commonmeta metadata.
func FetchList(number int, sample bool) ([]commonmeta.Data, error) {
// FetchAll gets the metadata for a list of works from the DataCite API and returns Commonmeta metadata.
func FetchAll(number int, sample bool) ([]commonmeta.Data, error) {
var data []commonmeta.Data
content, err := GetList(number, sample)
content, err := GetAll(number, sample)
if err != nil {
return data, err
}
Expand Down Expand Up @@ -306,8 +306,8 @@ func Load(filename string) (commonmeta.Data, error) {
return data, nil
}

// LoadList loads a list of DataCite metadata from a JSON string and returns Commonmeta metadata.
func LoadList(filename string) ([]commonmeta.Data, error) {
// LoadAll loads a list of DataCite metadata from a JSON string and returns Commonmeta metadata.
func LoadAll(filename string) ([]commonmeta.Data, error) {
var data []commonmeta.Data

response, err := ReadJSONLines(filename)
Expand Down Expand Up @@ -717,8 +717,8 @@ func GetContributor(v ContentContributor) commonmeta.Contributor {
}
}

// GetList gets the metadata for a list of works from the DataCite API
func GetList(number int, sample bool) ([]Content, error) {
// GetAll gets the metadata for a list of works from the DataCite API
func GetAll(number int, sample bool) ([]Content, error) {
// the envelope for the JSON response from the DataCite API
type Response struct {
Data []Content `json:"data"`
Expand Down

0 comments on commit 61b67d5

Please sign in to comment.