mcapi

package module
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2024 License: MIT Imports: 14 Imported by: 3

README

gomcapi

Go version of MCAPI

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DatasetLicenseAttribution = "Attribution License (ODC-By)"
View Source
var DatasetLicenseOpenDataset = "Open Database License (ODC-ODbL)"
View Source
var DatasetLicensePublicDomain = "Public Domain Dedication and License (PDDL)"

Functions

This section is empty.

Types

type APIError

type APIError struct {
	StatusCode int
	Status     string
}

APIError is an error that stores the StatusCode and Status from the response.

func NewAPIError

func NewAPIError(resp *resty.Response) *APIError

NewAPIError creates an instance of APIError from a resty.Response. It extracts the StatusCode and Status from the response.

func (*APIError) Error

func (e *APIError) Error() string

Error implements the Error interface.

type Attribute

type Attribute struct {
	Name  string `json:"name"`
	Value any    `json:"value"`
	Unit  string `json:"unit"`
}

type Author

type Author struct {
	Name         string `json:"name"`
	Email        string `json:"email"`
	Affiliations string `json:"affiliations"`
}

type Client

type Client struct {
	APIKey  string
	BaseURL string
	// contains filtered or unexported fields
}

Client is REST client for the Materials Commons API.

func NewClient

func NewClient(args *ClientArgs) *Client

NewClient creates a new client, sets the Accept and Content-Type headers to "application/json", and sets the Authorization header to the token. It does a small amount of cleaning on the BaseURL by removing the trailing slashes in the baseURL so the API can construct paths easier.

func (*Client) CreateActivity

func (c *Client) CreateActivity(req CreateActivityRequest) (*mcmodel.Activity, error)

CreateActivity creates a new activity based on the provided CreateActivityRequest struct.

func (*Client) CreateDataset

func (c *Client) CreateDataset(projectID int, req CreateOrUpdateDatasetRequest) (*mcmodel.Dataset, error)

CreateDataset creates a new dataset within the specified project. It takes a projectID and a CreateOrUpdateDatasetRequest as parameters. It returns a pointer to the created Dataset object or an error, if any occurs.

func (*Client) CreateDirectoryByPath added in v0.0.3

func (c *Client) CreateDirectoryByPath(projectID int, path string) (*mcmodel.File, error)

CreateDirectoryByPath creates a directory at the specified path within the given project. If the directory already exists, it returns the existing directory. It takes a project ID and a path as parameters and returns the created directory or an error.

func (*Client) CreateEntity

func (c *Client) CreateEntity(req CreateEntityRequest) (*mcmodel.Entity, error)

CreateEntity creates a new entity based on the provided request and returns the created entity or an error. The category in the request must be either 'experimental' or 'computational'. Defaults to 'experimental'.

func (*Client) CreateEntityState

func (c *Client) CreateEntityState(projectID, entityID, activityID int, req CreateEntityStateRequest) (*mcmodel.Entity, error)

CreateEntityState creates a new entity state associated with the provided project, entity, and activity IDs.

func (*Client) CreateExperiment added in v0.0.3

func (c *Client) CreateExperiment(request CreateExperimentRequest) (*mcmodel.Experiment, error)

CreateExperiment creates a new experiment based on the given CreateExperimentRequest.

func (*Client) CreateProject

func (c *Client) CreateProject(req CreateProjectRequest) (*mcmodel.Project, error)

CreateProject creates a new project with the specified parameters in CreateProjectRequest and returns the created project.

func (*Client) DeleteProject added in v0.0.3

func (c *Client) DeleteProject(id int) error

DeleteProject deletes a project identified by the provided ID. It makes a DELETE request to the API endpoint corresponding to the given project ID. Returns an error if the project could not be deleted or if there is any issue with the request.

func (*Client) DepositDataset added in v0.0.3

func (c *Client) DepositDataset(projectID int, req DepositDatasetRequest) (*mcmodel.Dataset, error)

DepositDataset deposits a dataset in a specified project given the project ID and request details. It creates the dataset, uploads files into a unique directory, and sets file selection for the dataset.

func (*Client) GetDataset

func (c *Client) GetDataset(projectID int, datasetID int) (*mcmodel.Dataset, error)

func (*Client) GetFileByPath added in v0.0.3

func (c *Client) GetFileByPath(projectID int, path string) (*mcmodel.File, error)

GetFileByPath fetches a file from a project given the specified project ID and file path. It returns a pointer to the file and an error if the fetch operation fails.

func (*Client) GetProject

func (c *Client) GetProject(id int) (*mcmodel.Project, error)

GetProject retrieves the project details for the given project ID. It returns a pointer to the Project object and an error, if any.

func (*Client) ListDatasets added in v0.0.4

func (c *Client) ListDatasets(projectID int) ([]mcmodel.Dataset, error)

ListDatasets lists all the datasets in a project

func (*Client) ListProjects added in v0.0.4

func (c *Client) ListProjects() ([]mcmodel.Project, error)

ListProjects lists all the projects a user is a member of

func (*Client) MintDOIForDataset added in v0.0.4

func (c *Client) MintDOIForDataset(projectID, datasetID int) (*mcmodel.Dataset, error)

MintDOIForDataset mints a new (findable) DOI for the dataset and assigns the DOI to it.

func (*Client) PublishDataset

func (c *Client) PublishDataset(projectID int, datasetID int) (*mcmodel.Dataset, error)

PublishDataset publishes a specified dataset by its datasetID in a particular project identified by projectID. Returns the published Dataset object or an error if the operation fails.

func (*Client) SetDebug added in v0.0.3

func (c *Client) SetDebug(on bool)

func (*Client) UnpublishDataset

func (c *Client) UnpublishDataset(projectID int, datasetID int) (*mcmodel.Dataset, error)

UnpublishDataset unpublishes a dataset associated with a specified project and dataset ID, returning the updated dataset or an error if the operation fails.

func (*Client) UpdateDataset

func (c *Client) UpdateDataset(projectID int, datasetID int, req CreateOrUpdateDatasetRequest) (*mcmodel.Dataset, error)

UpdateDataset updates an existing dataset for the given project. Takes in a projectID, datasetID, and a CreateOrUpdateDatasetRequest object. Returns the updated Dataset object or an error if the update fails.

func (*Client) UpdateDatasetFileSelection added in v0.0.3

func (c *Client) UpdateDatasetFileSelection(projectID, datasetID int, fileSelection DatasetFileSelection) (*mcmodel.Dataset, error)

UpdateDatasetFileSelection updates the file selection criteria for a specified dataset within a project. It includes and excludes specified files and directories based on the DatasetFileSelection object.

func (*Client) UploadFile

func (c *Client) UploadFile(projectID, directoryID int, filePath string) (*mcmodel.File, error)

UploadFile uploads a file to the specified project and directory. Parameters: - projectID: ID of the project to which the file will be uploaded. - directoryID: ID of the directory within the project where the file will be stored. - filePath: Local path of the file to be uploaded. Returns: - *mcmodel.File: Uploaded file metadata if the operation is successful. - error: Describes the error encountered during file upload.

func (*Client) UploadFileTo added in v0.0.3

func (c *Client) UploadFileTo(projectID int, filePath string, projectPath string) (*mcmodel.File, error)

UploadFileTo uploads a file to a specified project directory path. If the project directory path is blank then it uploads the file to the project root. If the directory does not exist, it creates it.

type ClientArgs

type ClientArgs struct {
	APIKey  string
	BaseURL string
}

ClientArgs are the arguments when creating the client. You specify the URL to the server and the API Key for the user. If BaseURL is blank then it defaults to https://materialscommons.org/api.

type CreateActivityRequest

type CreateActivityRequest struct {
	Name         string      `json:"name"`
	Description  string      `json:"description"`
	ProjectID    int         `json:"project_id"`
	ExperimentID int         `json:"experiment_id"`
	Attributes   []Attribute `json:"attributes"`
}

type CreateEntityRequest

type CreateEntityRequest struct {
	Name         string      `json:"name"`
	Category     string      `json:"category"`
	Description  string      `json:"description"`
	Summary      string      `json:"summary"`
	ExperimentID int         `json:"experiment_id"`
	ProjectID    int         `json:"project_id"`
	ActivityID   int         `json:"activity_id"`
	Attributes   []Attribute `json:"attributes"`
}

type CreateEntityStateRequest

type CreateEntityStateRequest struct {
	Current    bool        `json:"current"`
	Attributes []Attribute `json:"attributes"`
}

type CreateExperimentRequest added in v0.0.3

type CreateExperimentRequest struct {
	Name        string `json:"name"`
	Description string `json:"description"`
	Summary     string `json:"summary"`
	ProjectID   int    `json:"project_id"`
}

type CreateOrUpdateDatasetRequest

type CreateOrUpdateDatasetRequest struct {
	Name        string   `json:"name"`
	Description string   `json:"description"`
	Summary     string   `json:"summary"`
	License     string   `json:"license"`
	Funding     string   `json:"funding"`
	Experiments []int    `json:"experiments"`
	Communities []int    `json:"communities"`
	Tags        []Tag    `json:"tags"`
	Authors     []Author `json:"ds_authors"`
}

type CreateProjectRequest

type CreateProjectRequest struct {
	Name        string `json:"name"`
	Description string `json:"description"`
	Summary     string `json:"summary"`
}

type DataWrapper

type DataWrapper struct {
	Data any `json:"data"`
}

DataWrapper wraps json responses that have a data key before getting to the data, eg {"data": {"id": 1,... }}. It is used to get at the underlying data object.

type DatasetFileSelection added in v0.0.3

type DatasetFileSelection struct {
	IncludeFiles []string `json:"include_files"`
	ExcludeFiles []string `json:"exclude_files"`
	IncludeDirs  []string `json:"include_dirs"`
	ExcludeDirs  []string `json:"exclude_dirs"`
}

type DatasetFileUpload added in v0.0.3

type DatasetFileUpload struct {
	Description string `json:"description"`
	File        string `json:"file"`
	Directory   string `json:"directory"`
}

type DatasetMetadata added in v0.0.3

type DatasetMetadata struct {
	Name        string      `json:"name"`
	Description string      `json:"description"`
	Summary     string      `json:"summary"`
	License     string      `json:"license"`
	Funding     string      `json:"funding"`
	Communities []int       `json:"communities"`
	Authors     []Author    `json:"authors"`
	Tags        []Tag       `json:"tags"`
	DOI         string      `json:"doi"`
	Papers      []Paper     `json:"papers"`
	Attributes  []Attribute `json:"attributes"`
}

type DepositDatasetRequest added in v0.0.3

type DepositDatasetRequest struct {
	Files    []DatasetFileUpload `json:"files"`
	Metadata DatasetMetadata     `json:"metadata"`
}

type ErrorResponse added in v0.0.3

type ErrorResponse struct {
	Error string `json:"error"`
}

type Paper added in v0.0.3

type Paper struct {
	Name      string `json:"name"`
	Reference string `json:"reference"`
	DOI       string `json:"doi"`
	URL       string `json:"url"`
}

type Tag

type Tag struct {
	Value string `json:"value"`
}

Jump to

Keyboard shortcuts

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