Documentation
¶
Overview ¶
Package zenodo provides a Go interface to the Zenodo REST API.
More informations on:
Index ¶
- type AccessRight
- type Client
- func (cli *Client) Create(ctx context.Context, meta Metadata, files ...fs.File) (Deposition, error)
- func (cli *Client) Delete(ctx context.Context, id int) error
- func (cli *Client) Deposition(ctx context.Context, id int) (dep Deposition, err error)
- func (cli *Client) Depositions(ctx context.Context) iter.Seq2[Deposition, error]
- func (cli *Client) Discard(ctx context.Context, id int) (dep Deposition, err error)
- func (cli *Client) Edit(ctx context.Context, id int) (o Deposition, err error)
- func (cli *Client) NewVersion(ctx context.Context, id int, meta Metadata, files ...fs.File) (o Deposition, err error)
- func (cli *Client) Publish(ctx context.Context, id int) (dep Deposition, err error)
- func (cli *Client) Update(ctx context.Context, id int, meta Metadata) (dep Deposition, err error)
- type Contributor
- type Creator
- type Custom
- type Deposition
- type File
- type Files
- type ImageType
- type Links
- type Metadata
- type Option
- type PreReserveDOI
- type ProgrammingLanguage
- type PublicationType
- type RelatedID
- type URL
- type UploadType
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AccessRight ¶
type AccessRight string
const ( OpenAccess AccessRight = "open" EmbargoedAccess AccessRight = "embargoed" RestrictedAccess AccessRight = "restricted" ClosedAccess AccessRight = "closed" )
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a Zenodo client.
Example ¶
package main
import (
"context"
"fmt"
"log"
"codeberg.org/sbinet/zenodo"
)
func main() {
const (
token = "s3cr3t-t0k3n"
endpoint = "https://zenodo.org"
)
cli, err := zenodo.New(endpoint, token, zenodo.WithUserAgent("go-zenodo/v0.0.1"))
if err != nil {
log.Fatalf("could not create Zenodo client: %v", err)
}
var (
ctx = context.Background()
did int
)
for dep, err := range cli.Depositions(ctx) {
if err != nil {
log.Fatalf("could not iterate over depositions: %v", err)
}
fmt.Printf("deposition: id=%d, DOI=%q title=%q", dep.ID, dep.DOI, dep.Title)
did = dep.ID
}
dep, err := cli.Deposition(ctx, did)
if err != nil {
log.Fatalf("could not retrieve deposition %d from Zenodo: %v", did, err)
}
fmt.Printf("deposition: id=%d, DOI=%q title=%q", dep.ID, dep.DOI, dep.Title)
}
Example (Create) ¶
package main
import (
"context"
"fmt"
"log"
"codeberg.org/sbinet/zenodo"
)
func main() {
const (
token = "s3cr3t-t0k3n"
endpoint = "https://zenodo.org"
)
cli, err := zenodo.New(endpoint, token)
if err != nil {
log.Fatalf("could not create Zenodo client: %v", err)
}
meta := zenodo.Metadata{
Title: "go-zenodo",
UploadType: zenodo.Software,
Description: "A simple client for Zenodo, in Go",
Creators: []zenodo.Creator{{Name: "Jane Doe", Affiliation: "ACME"}},
}
ctx := context.Background()
dep, err := cli.Create(ctx, meta)
if err != nil {
log.Fatalf("could not create new deposition: %v", err)
}
id := dep.ID
fmt.Printf("created deposition: id=%d, DOI=%q title=%q", id, dep.DOI, dep.Title)
meta.Title = "Exciting Go-Zenodo client"
dep, err = cli.Update(ctx, id, meta)
_, err = cli.Publish(ctx, dep.ID)
if err != nil {
log.Fatalf("could not publish deposition: %v", err)
}
}
func New ¶
New creates a zenodo client for the provided zenodo server URL and authentication token.
Example:
cli, err := New("https://zenodo.org", "s3cr3t")
func (*Client) Delete ¶
Delete deletes the provided deposition. Note that only unpublished depositions may be deleted.
See:
https://developers.zenodo.org/#delete
func (*Client) Deposition ¶
Deposition retrieves the deposition identified by the provided id.
func (*Client) Depositions ¶
Depositions iterates over all depositions for the current authenticated user.
func (*Client) Discard ¶
Discard discards changes in the current editing session.
See:
https://developers.zenodo.org/#discard
func (*Client) Edit ¶
Edit unlocks an already submitted deposition for edition. See:
https://developers.zenodo.org/#edit
func (*Client) NewVersion ¶
func (cli *Client) NewVersion(ctx context.Context, id int, meta Metadata, files ...fs.File) (o Deposition, err error)
NewVersion creates a new version for the deposition id, with the provided metadata and files.
See:
https://developers.zenodo.org/#new-version
type Contributor ¶
type Contributor string
const ( ContactPerson Contributor = "contactperson" DataCollector Contributor = "datacollector" DataCurator Contributor = "datacurator" DataManager Contributor = "datamanager" Distributor Contributor = "distributor" Editor Contributor = "editor" HostingInstitution Contributor = "hostinginstitution" Producer Contributor = "producer" ProjectLeader Contributor = "projectleader" ProjectManager Contributor = "projectmanager" ProjectMember Contributor = "projectmember" RegistrationAgency Contributor = "registrationagency" RegistrationAuthority Contributor = "registrationauthority" RelatedPerson Contributor = "relatedperson" Researcher Contributor = "researcher" ResearchGroup Contributor = "researchgroup" RightsHolder Contributor = "rightsholder" Supervisor Contributor = "supervisor" Sponsor Contributor = "sponsor" WorkPackageLeader Contributor = "workpackageleader" OtherContributor Contributor = "other" )
type Creator ¶
type Creator struct {
Name string `json:"name,omitzero"` // Name of the creator in the format Family name, given names
Type Contributor `json:"type,omitzero"` // Type of the contributor
Affiliation string `json:"affiliation,omitzero"` // Affiliation of the creator
ORCID string `json:"orcid,omitzero"` // ORCID identifier of creator
GND string `json:"gnd,omitzero"` // GND identifier of creator
}
type Custom ¶
type Custom struct {
CodeRepository string `json:"code:codeRepository,omitzero"`
ProgrammingLanguages []ProgrammingLanguage `json:"code:programmingLanguage,omitzero"`
}
type Deposition ¶
type Deposition struct {
ID int `json:"id,omitzero"` // Deposition identifier
DOI string `json:"doi,omitzero"` // Digital Object Identifier
DOIURL URL `json:"doi_url,omitzero"` // Persistent link to the published deposition.
Owner int `json:"owner,omitzero"` // User identifier of the owner of the deposition.
Title string `json:"title,omitzero"` // Title of deposition (automatically set from metadata).
ConceptRecID string `json:"conceptrecid,omitzero"`
ConceptDOI string `json:"conceptdoi,omitzero"`
RecordID int `json:"record_id,omitzero"` // Record identifier. Zero if the deposition is not published.
// State of the deposition.
// - "inprogress": Deposition metadata can be updated. If deposition is also unsubmitted
// files can be updated as well.
// - "done": Deposition has been published.
// - "error": Deposition is in an error state - contact Zenodo support.
State string `json:"state,omitzero"`
Submitted bool `json:"submitted,omitzero"` // True if the deposition has been published, False otherwise
Created time.Time `json:"created,omitzero"` // Creation time of deposition
Modified time.Time `json:"modified,omitzero"` // Modification time of deposition
Files []File `json:"files,omitzero"` // List of deposition files resources
Links Links `json:"links,omitzero"`
// Deposition metadata
Metadata Metadata `json:"metadata,omitzero"`
}
type Links ¶
type Links struct {
Self URL `json:"self,omitzero"`
HTML URL `json:"html,omitzero"`
DOI URL `json:"doi,omitzero"`
ParentDOI URL `json:"parent_doi,omitzero"`
Badge URL `json:"badge,omitzero"`
ConceptBadge URL `json:"conceptbadge,omitzero"`
Files URL `json:"files,omitzero"`
LatestDraft URL `json:"latest_draft,omitzero"`
LatestDraftHTML URL `json:"latest_draft_html,omitzero"`
Publish URL `json:"publish,omitzero"`
Bucket URL `json:"bucket,omitzero"`
Edit URL `json:"edit,omitzero"`
Discard URL `json:"discard,omitzero"`
NewVersion URL `json:"newversion,omitzero"`
Record URL `json:"record,omitzero"`
RecordHTML URL `json:"record_html,omitzero"`
Latest URL `json:"latest,omitzero"`
LatestHTML URL `json:"latest_html,omitzero"`
}
type Metadata ¶
type Metadata struct {
Title string `json:"title,omitzero"`
DOI string `json:"doi,omitzero"`
PublicationDate string `json:"publication_date,omitzero"`
Description string `json:"description,omitzero"`
AccessRight AccessRight `json:"access_right,omitzero"`
Creators []Creator `json:"creators,omitzero"`
RelatedIDs []RelatedID `json:"related_identifiers,omitzero"`
Version string `json:"version,omitzero"`
Custom Custom `json:"custom,omitzero"`
License string `json:"license,omitzero"`
JournalTitle string `json:"journal_title,omitzero"`
JournalVolume string `json:"journal_volume,omitzero"`
ConferenceAcronym string `json:"conference_acronym,omitzero"`
ImprintPublisher string `json:"imprint_publisher,omitzero"`
UploadType UploadType `json:"upload_type,omitzero"`
PublicationType PublicationType `json:"publication_type,omitzero"`
ImageType ImageType `json:"image_type,omitzero"`
PreReserveDOI PreReserveDOI `json:"prereserve_doi,omitzero"`
}
type Option ¶
Option configures how a Zenodo client should be created.
func WithUserAgent ¶
WithUserAgent modifies the default user agent for the Zenodo client.
type PreReserveDOI ¶
type ProgrammingLanguage ¶
type PublicationType ¶
type PublicationType string
const ( AnnotationCollection PublicationType = "annotationcollection" Book PublicationType = "book" Section PublicationType = "section" ConferencePaper PublicationType = "conferencepaper" DataManagementPlan PublicationType = "datamanagementplan" Article PublicationType = "article" Patent PublicationType = "patent" PrePrint PublicationType = "preprint" Deliverable PublicationType = "deliverable" Mileston PublicationType = "milestone" Proposal PublicationType = "proposal" Report PublicationType = "report" SoftwareDocumentation PublicationType = "softwaredocumentation" TaxonomicTreatment PublicationType = "taxonomictreatment" TechnicalNote PublicationType = "technicalnote" Thesis PublicationType = "thesis" WorkingPaper PublicationType = "workingpaper" OtherPublicationType PublicationType = "other" )
type UploadType ¶
type UploadType string
const ( Publication UploadType = "publication" Poster UploadType = "poster" Presentation UploadType = "presentation" Dataset UploadType = "dataset" Image UploadType = "image" Video UploadType = "video" Software UploadType = "software" Lesson UploadType = "lesson" PhysicalObject UploadType = "physicalobject" OtherUploadType UploadType = "other" )