crossrefapi

package module
v1.0.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 26, 2024 License: BSD-3-Clause Imports: 14 Imported by: 3

README

crossrefapi

This is a go package for working with the CrossRef API. It is inspired by the an excellent CrossRefAPI Python package listed in the CrossRef API docs. This package is meant to follow the "polite" guidelines for interacting with the public API at api.crossref.org.

Go package example

    appName := path.Base(os.Args[0])
    client, err := crossrefapi.NewCrossRefClient(appName, "jane.doe@library.example.edu")
    if err != nil {
        // handle error...
    }
    works, err := client.Works("10.1037/0003-066x.59.1.29")
   
    if err != nil {
        // handle error...
    }
    // continue processing your "works" result...

You can compare two copies of a "works" response and see what has changed.


    appName := path.Base(os.Args[0])
    client, err := crossrefapi.NewCrossRefClient(appName, "jane.doe@library.example.edu")
    if err != nil {
        // handle error...
    }
    newWorks, err := client.Works("10.1037/0003-066x.59.1.29")
    if err != nil {
        // handle error...
    }
    // Fetch our previously saved works document.
    src, err := os.ReadFile("0003-066x.59.1.29.json")
    if err != nil {
        // handle error...
    }
    oldWorks := new(crossrefapi.Works)
    if err := json.Unmarshal(src, &oldWorks); err != nil {
        // handle error...
    }
    src, err = oldWorks.DiffAsJSON(newWorks)
    if err != nil {
        // handle error...
    }
    fmt.Println("Diff for 10.1037/0003-066x.59.1.29")
    fmt.Printf("\n%s\n", src)

Command line example

    crossrefapi -mailto="jane.doe@library.example.edu" works "10.1037/0003-066x.59.1.29"

Reference

Documentation

Index

Constants

View Source
const (
	// Version number of release
	Version = "1.0.7"

	// ReleaseDate, the date version.go was generated
	ReleaseDate = "2024-02-26"

	// ReleaseHash, the Git hash when version.go was generated
	ReleaseHash = "df9e4d1"

	LicenseText = `` /* 1524-byte string literal not displayed */

)

Variables

This section is empty.

Functions

func FmtHelp added in v1.0.3

func FmtHelp(src string, appName string, version string, releaseDate string, releaseHash string) string

FmtHelp lets you process a text block with simple curly brace markup.

func JsonDecode added in v1.0.6

func JsonDecode(src []byte, obj interface{}) error

Custom JSON decoder so we can treat numbers easier

func MarshalObject added in v1.0.6

func MarshalObject(obj interface{}, prefix string, indent string) ([]byte, error)

MarshalObject provide a custom json encoder to solve a an issue with HTML entities getting converted to UTF-8 code points by json.Marshal() in recent versions of go (~= go1.21).

Types

type Assertion added in v1.0.1

type Assertion struct {
	Group *Group `json:"group,omitempty"`
	Label string `json:"label,omitempty"`
	Name  string `json:"name,omitempty"`
	Value string `json:"value,omitempty"`
}

func (*Assertion) IsSame added in v1.0.1

func (a *Assertion) IsSame(t *Assertion) bool

type ClinicalTrailNumber added in v1.0.1

type ClinicalTrailNumber struct {
	ClinicalTrailNumber string `json:"clinical-trail-number,omitempty"`
	Registry            string `json:"registry,omitempty"`
	Type                string `json:"type,omitempty"`
}

func (*ClinicalTrailNumber) IsSame added in v1.0.1

type ContentDomain added in v1.0.1

type ContentDomain struct {
	Domain               []string `json:"domain,omitempty"`
	CrossmarkRestriction bool     `json:"crossmark-restriction,omitempty"`
}

func (*ContentDomain) IsSame added in v1.0.1

func (c *ContentDomain) IsSame(t *ContentDomain) bool

type CrossRefClient

type CrossRefClient struct {
	AppName           string
	MailTo            string `json:"mailto"`
	API               string `json:"api"`
	RateLimitLimit    int    `json:"limit"`
	RateLimitInterval int    `json:"interval"`
	LimtCount         int    `json:"limit"`
	Status            string
	StatusCode        int
	LastRequest       time.Time `json:"last_request"`
}

func NewCrossRefClient

func NewCrossRefClient(appName string, mailTo string) (*CrossRefClient, error)

NewCrossRefClient creates a client and makes a request and returns the JSON source as a []byte or error if their is a problem.

func (*CrossRefClient) Types

func (c *CrossRefClient) Types() (Object, error)

Types returns the list of supported types as a Object

func (*CrossRefClient) TypesJSON

func (c *CrossRefClient) TypesJSON() ([]byte, error)

TypesJSON return a list of types in JSON source

func (*CrossRefClient) Works

func (c *CrossRefClient) Works(doi string) (*Works, error)

Works return the Work unmarshaled into a Object (i.e. map[string]interface{})

func (*CrossRefClient) WorksJSON

func (c *CrossRefClient) WorksJSON(doi string) ([]byte, error)

WorksJSON return the work JSON source or error for a client and DOI

type DateObject added in v1.0.1

type DateObject struct {
	// DateParts holds a date an an array of Year, Month and Day integer values
	DateParts [][]int `json:"date-parts,omitempty"`
	// DateTime holds a date/time stamp, e.g. 2023-03-28T18:43:06.364Z
	DateTime string `json:"date-time,omitempty"`
	// Olds an integer representation of a timestamp, Unix epoch?
	Timestamp int64 `json:"timestamp,omitempty"`
}

DateObject is a date/timestamp/action timestamp of when something happened. It is used repeated in the message object

func (*DateObject) IsSame added in v1.0.1

func (do *DateObject) IsSame(t *DateObject) bool

IsSame checks if the date objects represent the same date. NOTE: if both objects are nil, they are considered the same.

type DateRange added in v1.0.1

type DateRange struct {
	StartDate *DateObject `json:"start-date,omitempty"`
	EndDate   *DateObject `json:"end-date,omitempty"`
}

func (*DateRange) IsSame added in v1.0.1

func (f *DateRange) IsSame(t *DateRange) bool

type Funder added in v1.0.1

type Funder struct {
	Name          string   `json:"name,omitempty"`
	DOI           string   `json:"DOI,omitempty"`
	DoiAssertedBy string   `json:"doi-asserted-by,omitempty"`
	Award         []string `json:"award,omitempty"`
}

func (*Funder) IsSame added in v1.0.1

func (f *Funder) IsSame(t *Funder) bool

IsSame checks if two works object are the same. NOTE: if both objects are nil, they are considered the same.

type Group added in v1.0.1

type Group struct {
	Label string `json:"label,omitempty"`
	Name  string `json:"name,omitempty"`
}

func (*Group) IsSame added in v1.0.1

func (g *Group) IsSame(t *Group) bool

type Identifier added in v1.0.1

type Identifier struct {
	Label      string `json:"label,omitempty"`
	Name       string `json:"name,omitempty"`
	Type       string `json:"type,omitempty"`
	Value      string `json:"value,omitempty"`
	IdType     string `json:"id-type,omitempty"`
	Id         string `json:"id,omitempty"`
	AssertedBy string `json:"asserted-by,omitempty"`
}

func (*Identifier) IsSame added in v1.0.1

func (i *Identifier) IsSame(t *Identifier) bool

IsSame checks if two works object are the same. NOTE: if both objects are nil, they are considered the same.

type JournalIssue added in v1.0.1

type JournalIssue struct {
	Issue string `json:"issue,omitempty"`
}

func (*JournalIssue) IsSame added in v1.0.1

func (i *JournalIssue) IsSame(t *JournalIssue) bool

type License added in v1.0.1

type License struct {
	URL            string      `json:"URL,omitempty"`
	Start          *DateObject `json:"start,omitempty"`
	DelayInDays    int         `json:"delay-in-days,omitempty"`
	ContentVersion string      `json:"content-version,omitempty"`
}

func (*License) IsSame added in v1.0.1

func (lic *License) IsSame(t *License) bool
type Link struct {
	URL                 string `json:"URL,omitempty"`
	ContentType         string `json:"content-type,omitempty"`
	ContentVersion      string `json:"content-version,omitempty"`
	IntendedApplication string `json:"intended-application,omitempty"`
}

func (*Link) IsSame added in v1.0.1

func (l *Link) IsSame(t *Link) bool

type Message added in v1.0.1

type Message struct {
	// Institutional information
	Institution []*Organization `json:"institution,omitempty"`
	// Indexed described when the work was last indexed
	Indexed *DateObject `json:"indexed,omitempty"`
	// Posted is when the work was posted to the API??
	Posted *DateObject `json:"posted,omitempty"`
	// PublisherLocation, where they are located as a string
	PublisherLocation string `json:"publisher-location,omitempty"`
	// UpdateTo ????
	UpdateTo []*Updated `json:"updated-to,omitempty"`
	// StandardsBody, ???
	StandardsBody       []*Organization        `json:"standards-body,omitempty"`
	EditionNumber       string                 `json:"edition-number,omitempty"`
	GroupTitle          string                 `json:"group-title,omitempty"`
	Publisher           string                 `json:"publisher,omitempty"`
	Issue               string                 `json:"issue,omitempty"`
	IsbnType            []*Identifier          `json:"isbn-type,omitempty"`
	License             []*License             `json:"license,omitempty"`
	Funder              []*Funder              `json:"funder,omitempty"`
	ContentDomain       *ContentDomain         `json:"content-domain,omitempty"`
	Chair               []*Person              `json:"chair,omitempty"`
	ShortContainerTitle []string               `json:"short-container-title,omitempty"`
	Accepted            *DateObject            `json:"accepted,omitempty"`
	ContentUpdated      *DateObject            `json:"content-updated,omitempty"`
	PublishedPrint      *DateObject            `json:"published-print,omitempty"`
	Abstract            string                 `json:"abstract,omitempty"`
	DOI                 string                 `json:"doi,omitempty"`
	Type                string                 `json:"type,omitempty"`
	Created             *DateObject            `json:"created,omitempty"`
	Approved            *DateObject            `json:"approved,omitempty"`
	Page                string                 `json:"page,omitempty"`
	UpdatePolicy        string                 `json:"update-policy,omitempty"`
	Source              string                 `json:"source,omitempty"`
	Title               []string               `json:"title,omitempty"`
	Prefix              string                 `json:"prefix,omitempty"`
	Volume              string                 `json:"volume,omitempty"`
	ClinicalTrailNumber *ClinicalTrailNumber   `json:"clinical-trail-number,omitempty"`
	Author              []*Person              `json:"author,omitempty"`
	Member              string                 `json:"member,omitempty"`
	ContentCreated      *DateObject            `json:"content-created,omitempty"`
	PublishedOnline     *DateObject            `json:"published-online,omitempty"`
	Reference           []*Reference           `json:"reference,omitempty"`
	ContainerTitle      []string               `json:"container-title,omitempty"`
	Review              *Review                `json:"review,omitempty"`
	OriginalTitle       []string               `json:"original-title,omitempty"`
	Language            string                 `json:"language,omitempty"`
	Link                []*Link                `json:"link,omitempty"`
	Deposited           *DateObject            `json:"deposited,omitempty"`
	Score               int                    `json:"score,omitempty"`
	Degree              string                 `json:"degree,omitempty"`
	SubTitle            []string               `json:"subtitle,omitempty"`
	Translator          []*Person              `json:"translator,omitempty"`
	FreeToRead          *DateRange             `json:"free-to-read,omitempty"`
	Editor              []*Person              `json:"editor,omitempty"`
	ComponentNumber     string                 `json:"component-number,omitempty"`
	ShortTitle          []string               `json:"short-title,omitempty"`
	Issued              *DateObject            `json:"issued,omitempty"`
	ISBN                []string               `json:"isbn,omitempty"`
	ReferenceCount      int                    `json:"reference-count,omitempty"`
	PartNumber          string                 `json:"part-number,omitempty"`
	JournalIssue        *JournalIssue          `json:"journal-issue,omitempty"`
	ArticleNumber       string                 `json:"article-number,omitempty"`
	AlternativeId       []string               `json:"alternative-id,omitempty"`
	URL                 string                 `json:"URL,omitempty"`
	Archive             []string               `json:"archive,omitempty"`
	Relation            map[string][]*Property `json:"relation,omitempty"`
	ISSN                []string               `json:"issn,omitempty"`
	IssnType            []*Identifier          `json:"issn-type,omitempty"`
	Subject             []string               `json:"subject,omitempty"`
	PublishedOther      *DateObject            `json:"published-other,omitempty"`
	Published           *DateObject            `json:"published,omitempty"`
	Assertion           []*Assertion           `json:"assertion,omitempty"`
}

func (*Message) Changes added in v1.0.1

func (msg *Message) Changes(t *Message) *Message

Changes takes the current Message, a new version of the Message and returns a Message object with the new Message object containing only the new elements.

func (*Message) Diff added in v1.0.1

func (msg *Message) Diff(t *Message) (*Message, *Message)

Diff takes the current Message, a new version of the Message and two Message objects one holding the old values and another holding the new values.

func (*Message) DiffAsJSON added in v1.0.1

func (msg *Message) DiffAsJSON(t *Message) ([]byte, error)

DiffAsJSON performs a Diff and returns the results as a JSON array where the first element (index 0) is the old object's values and the second (index 1) is the updated values

func (*Message) IsSame added in v1.0.1

func (msg *Message) IsSame(t *Message) bool

IsSame checks if two works object are the same. NOTE: if both objects are nil, they are considered the same.

type Object

type Object = map[string]interface{}

Object is the general holder of what get back after unmarshaling json

type Organization added in v1.0.1

type Organization struct {
	IDs        []*Identifier `json:"id,omitempty"`
	Name       string        `json:"name,omitempty"`
	Place      []string      `json:"place,omitempty"`
	Department []string      `json:"department,omitempty"`
	Acronym    []string      `json:"acronym,omitempty"`
}

func (*Organization) IsSame added in v1.0.1

func (org *Organization) IsSame(t *Organization) bool

IsSame checks if two works object are the same. NOTE: if both objects are nil, they are considered the same.

type Person added in v1.0.1

type Person struct {
	ORCID              string          `json:"ORCID,omitempty"`
	Suffix             string          `json:"suffix,omitempty"`
	Given              string          `json:"given,omitempty"`
	Family             string          `json:"family,omitempty"`
	Affiliation        []*Organization `json:"affiliation,omitempty"`
	Name               string          `json:"name,omitempty"`
	AuthenticatedOrcid bool            `json:"authenticated-orcid,omitempty"`
	Prefix             string          `json:"prefix,omitempty"`
	Sequence           string          `json:"sequence,omitempty"`
}

func (*Person) IsSame added in v1.0.1

func (p *Person) IsSame(t *Person) bool

type Property added in v1.0.1

type Property struct {
	IdType     string `json:"id-type,omitempty"`
	Id         string `json:"id,omitempty"`
	AssertedBy string `json:"asserted-by,omitempty"`
}

func (*Property) IsSame added in v1.0.1

func (p *Property) IsSame(t *Property) bool

type Reference added in v1.0.1

type Reference struct {
	ISSN               string `json:"issn,omitempty"`
	StandardsBody      string `json:"standards-body,omitempty"`
	Issue              string `json:"issue,omitempty"`
	Key                string `json:"key,omitempty"`
	SeriesTitle        string `json:"series-title,omitempty"`
	IsbnType           string `json:"isbn-type,omitempty"`
	DoiAssertedBy      string `json:"doi-asserted-by,omitempty"`
	FirstPage          string `json:"first-page,omitempty"`
	ISBN               string `json:"isbn,omitempty"`
	DOI                string `json:"doi,omitempty"`
	Component          string `json:"component,omitempty"`
	ArticleTitle       string `json:"article-title,omitempty"`
	VolumeTitle        string `json:"volume-title,omitempty"`
	Volume             string `json:"volume,omitempty"`
	Author             string `json:"author,omitempty"`
	StandardDesignator string `json:"standard-designator,omitempty"`
	Year               string `json:"year,omitempty"`
	Unstructured       string `json:"unstructured,omitempty"`
	Edition            string `json:"edition,omitempty"`
	JournalTitle       string `json:"journal-title,omitempty"`
	IssnType           string `json:"issn-type,omitempty"`
}

func (*Reference) IsSame added in v1.0.1

func (ref *Reference) IsSame(t *Reference) bool

IsSame checks of the reference object are the same. NOTE: if both objects are nil, they are considered the same.

type Review added in v1.0.1

type Review struct {
	Type                       string `json:"type,omitempty"`
	RunningNumber              string `json:"running-number,omitempty"`
	RevisionRound              string `json:"revision-round,omitempty"`
	Stage                      string `json:"stage,omitempty"`
	CompetingInterestStatement string `json:"competing-interest-statement,omitempty"`
	Recommendation             string `json:"recommendation,omitempty"`
	Language                   string `json:"language,omitempty"`
}

func (*Review) IsSame added in v1.0.1

func (r *Review) IsSame(t *Review) bool

type Updated added in v1.0.1

type Updated struct {
	Label   string      `json:"label,omitempty"`
	DOI     string      `json:"doi,omitempty"`
	Type    string      `json:"type,omitempty"`
	Updated *DateObject `json:"updated,omitempty"`
}

func (*Updated) IsSame added in v1.0.1

func (u *Updated) IsSame(t *Updated) bool

type Works added in v1.0.1

type Works struct {
	Status         string   `json:"status,omitempty"`
	MessageType    string   `json:"message-type,omitempty"`
	MessageVersion string   `json:"message-version,omitempty"`
	Message        *Message `json:"message,omitempty"`
}

Works is a representation retrieved the CrossRef REST API using the Works path and a DOI. This is based on documentaiton at https://api.crossref.org/swagger-ui/index.html#/Works/get_works__doi_ Captured on 2023-03-28, RSD

NOTE: structure in documentation appears wrong, my test records indicate that some things listed as array of string are really just strings and visa versa.

func (*Works) Diff added in v1.0.1

func (work *Works) Diff(t *Works) (*Works, *Works)

Diff works returns the fields that differ

func (*Works) DiffAsJSON added in v1.0.1

func (work *Works) DiffAsJSON(t *Works) ([]byte, error)

DiffAsJSON performs a Diff and returns the results as a JSON array where the first element (index 0) is the old object's values and the second (index 1) is the updated values

func (*Works) IsSame added in v1.0.1

func (work *Works) IsSame(t *Works) bool

IsSame checks if two works object have the same content. NOTE: if both are nil then true is returned. Only compares the works' type and message attributes are compared.

Directories

Path Synopsis
cmd
crossrefapi
crossrefapi.go is a command line tool for access the CrossRef API given a specific DOI.
crossrefapi.go is a command line tool for access the CrossRef API given a specific DOI.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL