dwapi

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: May 24, 2022 License: Apache-2.0 Imports: 9 Imported by: 1

Documentation

Overview

Package dwapi makes it easy to use data.world's REST API (https://apidocs.data.world/api) with Go.

Users can create and update datasets, projects, and metadata; query datasets using SQL and SPARQL; and download and upload files.

Index

Examples

Constants

View Source
const (
	DELETE = "DELETE"
	GET    = "GET"
	PATCH  = "PATCH"
	POST   = "POST"
	PUT    = "PUT"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	BaseURL string
	Token   string

	Dataset *DatasetService
	DOI     *DoiService
	File    *FileService
	Insight *InsightService
	Project *ProjectService
	Query   *QueryService
	Stream  *StreamService
	User    *UserService
	Webhook *WebhookService
}

func NewClient

func NewClient(token string) *Client

type DatasetCreateRequest

type DatasetCreateRequest struct {
	Description string              `json:"description,omitempty"`
	Files       []FileCreateRequest `json:"files,omitempty"`
	License     string              `json:"license,omitempty"`
	Summary     string              `json:"summary,omitempty"`
	Tags        []string            `json:"tags,omitempty"`
	Title       string              `json:"title"`
	Visibility  string              `json:"visibility"`
}

type DatasetCreateResponse

type DatasetCreateResponse struct {
	Message string `json:"message,omitempty"`
	URI     string `json:"uri"`
}

type DatasetOrProjectIdentifier

type DatasetOrProjectIdentifier struct {
	ID    string `json:"id"`
	Owner string `json:"owner"`
}

type DatasetReplaceRequest

type DatasetReplaceRequest struct {
	Description string              `json:"description,omitempty"`
	Files       []FileCreateRequest `json:"files,omitempty"`
	License     string              `json:"license,omitempty"`
	Summary     string              `json:"summary,omitempty"`
	Tags        []string            `json:"tags,omitempty"`
	Title       string              `json:"title"`
	Visibility  string              `json:"visibility"`
}

type DatasetService

type DatasetService struct {
	// contains filtered or unexported fields
}

func (*DatasetService) AddFilesFromURLs

func (s *DatasetService) AddFilesFromURLs(owner, datasetid string, body *[]FileCreateRequest) (
	response SuccessResponse, err error)

AddFilesFromURLs adds files from URLs to a dataset. This method allows files published on the web to be added to a data.world dataset via their URL. This method can also be used to retrieve data via web APIs, with advanced options for HTTP method, request payload and authentication.

The source URL will be stored so you can easily update your file anytime it changes via the `Sync now` button on the dataset page or by calling `Dataset.Sync()`.

func (*DatasetService) AssociateDOI

func (s *DatasetService) AssociateDOI(owner, datasetid, doi string) (response SuccessResponse, err error)

AssociateDOI associates a DOI (Digital Object Identifier) with a dataset.

func (*DatasetService) AssociateDOIWithVersion

func (s *DatasetService) AssociateDOIWithVersion(owner, datasetid, versionid, doi string) (
	response SuccessResponse, err error)

AssociateDOIWithVersion associates a DOI (Digital Object Identifier) with a version of a dataset.

func (*DatasetService) Contributing

func (s *DatasetService) Contributing() (response []DatasetSummaryResponse, err error)

Contributing lists the datasets that the currently authenticated user has access to because they are a contributor.

func (*DatasetService) Create

func (s *DatasetService) Create(owner string, body *DatasetCreateRequest) (response DatasetCreateResponse, err error)

Create a dataset and associated data.

Example
owner := "dataset-owner"
request := DatasetCreateRequest{
	Title:       "My Awesome Dataset",
	Description: "A short description",
	Summary:     "A long description",
	Tags:        []string{"first", "puppies and kittens"},
	License:     "PDDL",
	Visibility:  "PRIVATE",
}
response, err := dw.Dataset.Create(owner, &request)
if err != nil {
	log.Fatal(err)
}
fmt.Println("Dataset URI:", response.URI)
Output:

func (*DatasetService) CreateOrReplace

func (s *DatasetService) CreateOrReplace(owner, id string, body *DatasetReplaceRequest) (
	response SuccessResponse, err error)

CreateOrReplace attempts to create a dataset with the given id, and will reset the dataset if it already exists, redefining all of its attributes.

func (*DatasetService) Delete

func (s *DatasetService) Delete(owner, datasetid string) (response SuccessResponse, err error)

Delete a dataset and associated data.

func (*DatasetService) DeleteDOI

func (s *DatasetService) DeleteDOI(owner, datasetid, doi string) (response SuccessResponse, err error)

DeleteDOI deletes a DOI (Digital Object Identifier) associated with a version of a dataset.

func (*DatasetService) DeleteDOIAssociatedWithVersion

func (s *DatasetService) DeleteDOIAssociatedWithVersion(owner, datasetid, versionid, doi string) (
	response SuccessResponse, err error)

DeleteDOIAssociatedWithVersion deletes a DOI (Digital Object Identifier) associated with a version of a dataset.

func (*DatasetService) Download

func (s *DatasetService) Download(owner, datasetid, filename string) (response io.Reader, err error)

Download downloads a .zip file containing all files within a dataset as originally uploaded.

Prefer `Query.ExecuteSQL()` or `Query.ExecuteSPARQL()` for retrieving clean and structured data.

func (*DatasetService) DownloadAndSave

func (s *DatasetService) DownloadAndSave(owner, datasetid, path string) (response SuccessResponse, err error)

DownloadAndSave downloads a .zip file containing all files within a dataset as originally uploaded, and saves the results to a file.

Prefer `Query.ExecuteSQL()` or `Query.ExecuteSPARQL()` for retrieving clean and structured data.

func (*DatasetService) DownloadAndSaveFile

func (s *DatasetService) DownloadAndSaveFile(owner, datasetid, filename, path string) (
	response SuccessResponse, err error)

DownloadAndSaveFile downloads a file within the dataset as originally uploaded, and saves the results to a file.

Prefer `Query.ExecuteSQL()` or `Query.ExecuteSPARQL()` for retrieving clean and structured data.

func (*DatasetService) DownloadFile

func (s *DatasetService) DownloadFile(owner, datasetid, filename string) (response io.Reader, err error)

DownloadFile downloads a file within the dataset as originally uploaded.

Prefer `Query.ExecuteSQL()` or `Query.ExecuteSPARQL()` for retrieving clean and structured data.

func (*DatasetService) Liked

func (s *DatasetService) Liked() (response []DatasetSummaryResponse, err error)

Liked lists the datasets that the currently authenticated user has liked (bookmarked).

func (*DatasetService) ListQueries

func (s *DatasetService) ListQueries(owner, datasetid string) (response []QuerySummaryResponse, err error)

ListQueries lists the saved queries associated with a dataset.

Query definitions will be returned, not the query results. To retrieve the query results, use `Query.ExecuteSavedQuery`.

func (*DatasetService) Owned

func (s *DatasetService) Owned() (response []DatasetSummaryResponse, err error)

Owned lists the datasets that the currently authenticated user has access to because they are the owner.

func (*DatasetService) Retrieve

func (s *DatasetService) Retrieve(owner, datasetid string) (response DatasetSummaryResponse, err error)

Retrieve fetches a dataset.

The definition will be returned, not the associated data. Use `Query.ExecuteSQL()` or `Query.ExecuteSPARQL()` to query the data. You can also download the original files with `Dataset.Download` or `Dataset.DownloadFile`.

func (*DatasetService) RetrieveVersion

func (s *DatasetService) RetrieveVersion(owner, datasetid, versionid string) (
	response DatasetSummaryResponse, err error)

Retrieve fetches a version of a dataset.

The definition will be returned, not the associated data. Use `Query.ExecuteSQL()` or `Query.ExecuteSPARQL()` to query the data. You can also download the original files with `Dataset.Download` or `Dataset.DownloadFile`.

func (*DatasetService) Sync

func (s *DatasetService) Sync(owner, datasetid string) (response SuccessResponse, err error)

Sync files within a dataset. This method will process the latest data available for files added from URLs or via streams.

func (*DatasetService) Update

func (s *DatasetService) Update(owner, id string, body *DatasetUpdateRequest) (response SuccessResponse, err error)

Update a dataset.

func (*DatasetService) UploadFile

func (s *DatasetService) UploadFile(owner, id, filename, path string, expandArchive bool) (
	response SuccessResponse, err error)

UploadFile uploads one file at a time to a dataset.

type DatasetSummaryResponse

type DatasetSummaryResponse struct {
	AccessLevel string                    `json:"accessLevel"`
	Created     string                    `json:"created"`
	Description string                    `json:"description,omitempty"`
	Dois        []DigitalObjectIdentifier `json:"dois,omitempty"`
	Files       []FileSummaryResponse     `json:"files,omitempty"`
	ID          string                    `json:"id"`
	IsProject   bool                      `json:"isProject"`
	License     string                    `json:"license,omitempty"`
	Owner       string                    `json:"owner"`
	Status      string                    `json:"status"`
	Summary     string                    `json:"summary,omitempty"`
	Tags        []string                  `json:"tags,omitempty"`
	Title       string                    `json:"title"`
	Updated     string                    `json:"updated"`
	Version     string                    `json:"version"`
	VersionDois []DigitalObjectIdentifier `json:"versionDois,omitempty"`
	Visibility  string                    `json:"visibility"`
}

type DatasetUpdateRequest

type DatasetUpdateRequest struct {
	Description string              `json:"description,omitempty"`
	Files       []FileCreateRequest `json:"files,omitempty"`
	License     string              `json:"license,omitempty"`
	Summary     string              `json:"summary,omitempty"`
	Tags        []string            `json:"tags,omitempty"`
	Title       string              `json:"title,omitempty"`
	Visibility  string              `json:"visibility,omitempty"`
}

type DigitalObjectIdentifier

type DigitalObjectIdentifier struct {
	Created string `json:"created"`
	Doi     string `json:"doi"`
}

type DoiService

type DoiService struct {
	// contains filtered or unexported fields
}

func (*DoiService) Associate

func (s *DoiService) Associate(owner, datasetid, doi string) (response SuccessResponse, err error)

Associate a DOI (Digital Object Identifier) with a dataset.

func (*DoiService) AssociateWithVersion

func (s *DoiService) AssociateWithVersion(owner, datasetid, versionid, doi string) (
	response SuccessResponse, err error)

AssociateWithVersion associates a DOI (Digital Object Identifier) with a version of dataset.

func (*DoiService) Delete

func (s *DoiService) Delete(owner, datasetid, doi string) (response SuccessResponse, err error)

Delete a DOI (Digital Object Identifier) associated with a dataset.

func (*DoiService) DeleteAssociatedWithVersion

func (s *DoiService) DeleteAssociatedWithVersion(owner, datasetid, versionid, doi string) (
	response SuccessResponse, err error)

DeleteAssociatedWithVersion deletes a DOI (Digital Object Identifier) associated with a dataset.

type FileCreateRequest

type FileCreateRequest struct {
	Description string                          `json:"description,omitempty"`
	Labels      []string                        `json:"labels,omitempty"`
	Name        string                          `json:"name"`
	Source      FileSourceCreateOrUpdateRequest `json:"source"`
}

type FileService

type FileService struct {
	// contains filtered or unexported fields
}

func (*FileService) AddFilesFromURLs

func (s *FileService) AddFilesFromURLs(owner, id string, body *[]FileCreateRequest) (
	response SuccessResponse, err error)

AddFilesFromURLs adds files from URLs to a dataset. This method allows files published on the web to be added to a data.world dataset via their URL. This method can also be used to retrieve data via web APIs, with advanced options for HTTP method, request payload and authentication.

The source URL will be stored so you can easily update your file anytime it changes via the `Sync now` button on the dataset page or by calling `File.Sync()`.

Example
owner := "dataset-owner"
datasetid := "my-awesome-dataset"
file := FileCreateRequest{
	Name:        "my-file.csv",
	Description: "A description for my test file.",
	Source: FileSourceCreateOrUpdateRequest{
		URL: "http://mysite.com/my-file.csv",
	},
}
files := []FileCreateRequest{
	file,
}

_, err := dw.File.AddFilesFromURLs(owner, datasetid, &files)
if err != nil {
	log.Fatal(err)
}
Output:

func (*FileService) Delete

func (s *FileService) Delete(owner, id, filename string) (response SuccessResponse, err error)

Delete a single file from a dataset.

func (*FileService) Download

func (s *FileService) Download(owner, id, filename string) (response io.ReadCloser, err error)

Download a file within the dataset as originally uploaded.

Prefer `Query.ExecuteSQL()` or `Query.ExecuteSPARQL()` for retrieving clean and structured data.

func (*FileService) DownloadAndSave

func (s *FileService) DownloadAndSave(owner, id, filename, path string) (response SuccessResponse, err error)

DownloadAndSave downloads a file within the dataset as originally uploaded, and saves the results to a file.

Prefer `Query.ExecuteSQL()` or `Query.ExecuteSPARQL()` for retrieving clean and structured data.

Example
owner := "dataset-owner"
datasetid := "my-awesome-dataset"
filename := "my-file.csv"
savePath := "./my-file.csv"

_, err := dw.File.DownloadAndSave(owner, datasetid, filename, savePath)
if err != nil {
	log.Fatal(err)
}
Output:

func (*FileService) DownloadAndSaveDataset

func (s *FileService) DownloadAndSaveDataset(owner, id, path string) (response SuccessResponse, err error)

DownloadAndSaveDataset downloads a .zip file containing all files within a dataset as originally uploaded, and saves the results to a file.

Prefer `Query.ExecuteSQL()` or `Query.ExecuteSPARQL()` for retrieving clean and structured data.

Example
owner := "dataset-owner"
datasetid := "my-awesome-dataset"
savePath := "./my-file.zip"

_, err := dw.File.DownloadAndSaveDataset(owner, datasetid, savePath)
if err != nil {
	log.Fatal(err)
}
Output:

func (*FileService) DownloadDataset

func (s *FileService) DownloadDataset(owner, id string) (response io.ReadCloser, err error)

DownloadDataset downloads a .zip file containing all files within a dataset as originally uploaded.

Prefer `Query.ExecuteSQL()` or `Query.ExecuteSPARQL()` for retrieving clean and structured data.

func (*FileService) Sync

func (s *FileService) Sync(owner, id string) (response SuccessResponse, err error)

Sync files within a dataset. This method will process the latest data available for files added from URLs or via streams.

func (*FileService) Upload

func (s *FileService) Upload(owner, id, filename, path string, expandArchive bool) (
	response SuccessResponse, err error)

Upload one file at a time to a dataset.

Example
owner := "dataset-owner"
datasetid := "my-awesome-dataset"
filename := "my-file.csv"
filepath := "./my-file.csv"

_, err := dw.File.Upload(owner, datasetid, filename, filepath, false)
if err != nil {
	log.Fatal(err)
}
Output:

func (*FileService) UploadStream

func (s *FileService) UploadStream(owner, id, filename string, body io.Reader, expandArchive bool) (
	response SuccessResponse, err error)

UploadStream uploads the contents of an io.Reader to a file in a dataset.

Example
owner := "dataset-owner"
datasetid := "my-awesome-dataset"
filename := "my-file.csv"
s := []string{"first_name,last_name", "Abe,Marcos", "Abby,Johnson"}
sj := strings.Join(s, "\n")
body := strings.NewReader(sj)

_, err := dw.File.UploadStream(owner, datasetid, filename, body, false)
if err != nil {
	log.Fatal(err)
}
Output:

type FileSourceCreateOrUpdateRequest

type FileSourceCreateOrUpdateRequest struct {
	Authorization  WebAuthorization    `json:"authorization,omitempty"`
	Credentials    WebCredentials      `json:"credentials,omitempty"`
	ExpandArchive  bool                `json:"expandArchive,omitempty"`
	Method         string              `json:"method,omitempty"`
	OauthToken     OauthTokenReference `json:"oauthToken,omitempty"`
	RequestEntity  string              `json:"requestEntity,omitempty"`
	RequestHeaders interface{}         `json:"requestHeaders,omitempty"`
	URL            string              `json:"url,omitempty"`
}

type FileSourceResponse

type FileSourceResponse struct {
	Authorization   WebAuthorization    `json:"authorization,omitempty"`
	Credentials     WebCredentials      `json:"credentials,omitempty"`
	ExpandArchive   bool                `json:"expandArchive,omitempty"`
	Method          string              `json:"method,omitempty"`
	SyncStatus      string              `json:"syncStatus"`
	SyncSummary     []string            `json:"labels,omitempty"`
	LastSyncFailure string              `json:"lastSyncFailure,omitempty"`
	LastSyncStart   string              `json:"lastSyncStart,omitempty"`
	LastSyncSuccess string              `json:"lastSyncSuccess,omitempty"`
	OauthToken      OauthTokenReference `json:"oauthToken,omitempty"`
	RequestEntity   string              `json:"requestEntity,omitempty"`
	RequestHeaders  interface{}         `json:"requestHeaders,omitempty"`
	URL             string              `json:"url,omitempty"`
}

type FileSummaryResponse

type FileSummaryResponse struct {
	Created     string             `json:"created"`
	Description string             `json:"description,omitempty"`
	Labels      []string           `json:"labels,omitempty"`
	Name        string             `json:"name"`
	SizeInBytes uint               `json:"sizeInBytes,omitempty"`
	Source      FileSourceResponse `json:"source,omitempty"`
	Updated     string             `json:"updated"`
}

type InsightBody

type InsightBody struct {
	EmbedURL     string `json:"embedUrl,omitempty"`
	ImageURL     string `json:"imageUrl,omitempty"`
	MarkdownBody string `json:"markdownBody,omitempty"`
}

type InsightCreateRequest

type InsightCreateRequest struct {
	Body            InsightBody `json:"body"`
	DataSourceLinks []string    `json:"dataSourceLinks,omitempty"`
	Description     string      `json:"description,omitempty"`
	SourceLink      string      `json:"sourceLink,omitempty"`
	Thumbnail       string      `json:"thumbnail,omitempty"`
	Title           string      `json:"title"`
}

type InsightCreateResponse

type InsightCreateResponse struct {
	Message string `json:"message,omitempty"`
	URI     string `json:"uri"`
}

type InsightReplaceRequest

type InsightReplaceRequest struct {
	Body            InsightBody `json:"body"`
	DataSourceLinks []string    `json:"dataSourceLinks,omitempty"`
	Description     string      `json:"description,omitempty"`
	SourceLink      string      `json:"sourceLink,omitempty"`
	Thumbnail       string      `json:"thumbnail,omitempty"`
	Title           string      `json:"title"`
}

type InsightService

type InsightService struct {
	// contains filtered or unexported fields
}

func (*InsightService) Create

func (s *InsightService) Create(owner, projectid string, body *InsightCreateRequest) (
	response InsightCreateResponse, err error)

Create a new insight.

func (*InsightService) Delete

func (s *InsightService) Delete(owner, projectid, insightid string) (response SuccessResponse, err error)

Delete an insight.

func (*InsightService) List

func (s *InsightService) List(owner, projectid string) (response []InsightSummaryResponse, err error)

List insights associated with a project.

func (*InsightService) Replace

func (s *InsightService) Replace(owner, projectid, insightid string, body *InsightReplaceRequest) (
	response SuccessResponse, err error)

Replace an insight.

func (*InsightService) Retrieve

func (s *InsightService) Retrieve(owner, projectid, insightid string) (response InsightSummaryResponse, err error)

Retrieve fetches an insight.

func (*InsightService) RetrieveVersion

func (s *InsightService) RetrieveVersion(owner, projectid, insightid, versionid string) (
	response InsightSummaryResponse, err error)

RetrieveVersion fetches a version of an insight.

func (*InsightService) Update

func (s *InsightService) Update(owner, projectid, insightid string, body *InsightUpdateRequest) (
	response SuccessResponse, err error)

Update an insight.

Note that only elements included in the request will be updated. All omitted elements will remain untouched.

type InsightSummaryResponse

type InsightSummaryResponse struct {
	Author          string      `json:"author"`
	Body            InsightBody `json:"body"`
	Created         string      `json:"created"`
	DataSourceLinks []string    `json:"dataSourceLinks,omitempty"`
	Description     string      `json:"description,omitempty"`
	ID              string      `json:"id"`
	SourceLink      string      `json:"sourceLink,omitempty"`
	Thumbnail       string      `json:"thumbnail,omitempty"`
	Title           string      `json:"title"`
	Updated         string      `json:"updated"`
	Version         string      `json:"version"`
}

type InsightUpdateRequest

type InsightUpdateRequest struct {
	Body            InsightBody `json:"body,omitempty"`
	DataSourceLinks []string    `json:"dataSourceLinks,omitempty"`
	Description     string      `json:"description,omitempty"`
	SourceLink      string      `json:"sourceLink,omitempty"`
	Thumbnail       string      `json:"thumbnail,omitempty"`
	Title           string      `json:"title,omitempty"`
}

type LinkedDatasetCreateOrUpdateRequest

type LinkedDatasetCreateOrUpdateRequest struct {
	ID    string `json:"id"`
	Owner string `json:"owner"`
}

type LinkedDatasetSummaryResponse

type LinkedDatasetSummaryResponse struct {
	AccessLevel string   `json:"accessLevel"`
	Created     string   `json:"created"`
	Description string   `json:"description,omitempty"`
	ID          string   `json:"id"`
	License     string   `json:"license,omitempty"`
	Owner       string   `json:"owner"`
	Summary     string   `json:"summary,omitempty"`
	Tags        []string `json:"tags,omitempty"`
	Title       string   `json:"title"`
	Updated     string   `json:"updated"`
	Version     string   `json:"version"`
	Visibility  string   `json:"visibility"`
}

type OauthTokenReference

type OauthTokenReference struct {
	ID    string `json:"id"`
	Owner string `json:"owner"`
	Site  string `json:"site"`
}

type ProjectCreateOrUpdateRequest

type ProjectCreateOrUpdateRequest struct {
	Files          []FileCreateRequest                  `json:"files,omitempty"`
	License        string                               `json:"license,omitempty"`
	LinkedDatasets []LinkedDatasetCreateOrUpdateRequest `json:"linkedDatasets,omitempty"`
	Objective      string                               `json:"objective,omitempty"`
	Summary        string                               `json:"summary,omitempty"`
	Tags           []string                             `json:"tags,omitempty"`
	Title          string                               `json:"title"`
	Visibility     string                               `json:"visibility"`
}

type ProjectCreateResponse

type ProjectCreateResponse struct {
	Message string `json:"message,omitempty"`
	URI     string `json:"uri"`
}

type ProjectService

type ProjectService struct {
	// contains filtered or unexported fields
}

func (*ProjectService) AddFilesFromURLs

func (s *ProjectService) AddFilesFromURLs(owner, projectid string, body *[]FileCreateRequest) (
	response SuccessResponse, err error)

AddFilesFromURLs adds files from URLs to a project. This method allows files published on the web to be added to a data.world dataset via their URL. This method can also be used to retrieve data via web APIs, with advanced options for HTTP method, request payload and authentication.

The source URL will be stored so you can easily update your file anytime it changes via the `Sync now` button on the dataset page or by calling `Project.Sync()`.

func (*ProjectService) Contributing

func (s *ProjectService) Contributing() (response []ProjectSummaryResponse, err error)

Contributing lists the projects that the currently authenticated user has access to because they are a contributor.

func (*ProjectService) Create

func (s *ProjectService) Create(owner string, body *ProjectCreateOrUpdateRequest) (
	response ProjectCreateResponse, err error)

Create a project and associated data.

func (*ProjectService) CreateOrReplace

func (s *ProjectService) CreateOrReplace(owner, projectid string, body *ProjectCreateOrUpdateRequest) (
	response SuccessResponse, err error)

CreateOrReplace attempts to create a project with the given id, and will reset the project if it already exists, redefining all of its attributes.

func (*ProjectService) Delete

func (s *ProjectService) Delete(owner, projectid string) (response SuccessResponse, err error)

Delete a project and associated data.

func (*ProjectService) Download

func (s *ProjectService) Download(owner, projectid, filename string) (response io.Reader, err error)

Download downloads a .zip file containing all files within a project as originally uploaded.

Prefer `Query.ExecuteSQL()` or `Query.ExecuteSPARQL()` for retrieving clean and structured data.

func (*ProjectService) DownloadAndSave

func (s *ProjectService) DownloadAndSave(owner, projectid, path string) (response SuccessResponse, err error)

DownloadAndSave downloads a .zip file containing all files within a project as originally uploaded, and saves the results to a file.

Prefer `Query.ExecuteSQL()` or `Query.ExecuteSPARQL()` for retrieving clean and structured data.

func (*ProjectService) DownloadAndSaveFile

func (s *ProjectService) DownloadAndSaveFile(owner, projectid, filename, path string) (
	response SuccessResponse, err error)

DownloadAndSaveFile downloads a file within the project as originally uploaded, and saves the results to a file.

Prefer `Query.ExecuteSQL()` or `Query.ExecuteSPARQL()` for retrieving clean and structured data.

func (*ProjectService) DownloadFile

func (s *ProjectService) DownloadFile(owner, projectid, filename string) (response io.Reader, err error)

DownloadFile downloads a file within the project as originally uploaded.

Prefer `Query.ExecuteSQL()` or `Query.ExecuteSPARQL()` for retrieving clean and structured data.

func (*ProjectService) Liked

func (s *ProjectService) Liked() (response []ProjectSummaryResponse, err error)

Liked lists the projects that the currently authenticated user has liked (bookmarked).

func (*ProjectService) LinkDataset

func (s *ProjectService) LinkDataset(owner, projectid, linkedDatasetOwner, linkedDatasetid string) (
	response SuccessResponse, err error)

LinkDataset adds a linked dataset to a project.

func (*ProjectService) ListQueries

func (s *ProjectService) ListQueries(owner, projectid string) (response []QuerySummaryResponse, err error)

ListQueries lists the saved queries associated with a project.

Query definitions will be returned, not the query results. To retrieve the query results, use `Query.ExecuteSavedQuery`.

func (*ProjectService) Owned

func (s *ProjectService) Owned() (response []ProjectSummaryResponse, err error)

Owned lists the projects that the currently authenticated user has access to because they are the owner.

func (*ProjectService) Retrieve

func (s *ProjectService) Retrieve(owner, projectid string) (response ProjectSummaryResponse, err error)

Retrieve fetches a project.

The definition will be returned, not the associated data. Use `Query.ExecuteSQL()` or `Query.ExecuteSPARQL()` to query the data. You can also download the original files with `Project.Download` or `Project.DownloadFile`.

func (*ProjectService) RetrieveVersion

func (s *ProjectService) RetrieveVersion(owner, projectid, versionid string) (
	response ProjectSummaryResponse, err error)

Retrieve fetches a version of a project.

The definition will be returned, not the associated data. Use `Query.ExecuteSQL()` or `Query.ExecuteSPARQL()` to query the data. You can also download the original files with `Project.Download` or `Project.DownloadFile`.

func (*ProjectService) Sync

func (s *ProjectService) Sync(owner, projectid string) (response SuccessResponse, err error)

Sync files within a project. This method will process the latest data available for files added from URLs or via streams.

func (*ProjectService) UnlinkDataset

func (s *ProjectService) UnlinkDataset(owner, projectid, linkedDatasetOwner, linkedDatasetid string) (
	response SuccessResponse, err error)

UnlinkDataset removes a linked dataset from a project.

func (*ProjectService) Update

func (s *ProjectService) Update(owner, id string, body *ProjectCreateOrUpdateRequest) (
	response SuccessResponse, err error)

Update a project.

func (*ProjectService) UploadFile

func (s *ProjectService) UploadFile(owner, id, filename, path string, expandArchive bool) (
	response SuccessResponse, err error)

UploadFile uploads one file at a time to a project.

type ProjectSummaryResponse

type ProjectSummaryResponse struct {
	AccessLevel    string                         `json:"accessLevel"`
	Created        string                         `json:"created"`
	Files          []FileSummaryResponse          `json:"files,omitempty"`
	ID             string                         `json:"id"`
	License        string                         `json:"license,omitempty"`
	LinkedDatasets []LinkedDatasetSummaryResponse `json:"linkedDatasets,omitempty"`
	Objective      string                         `json:"objective,omitempty"`
	Owner          string                         `json:"owner"`
	Status         string                         `json:"status"`
	Summary        string                         `json:"summary,omitempty"`
	Tags           []string                       `json:"tags,omitempty"`
	Title          string                         `json:"title"`
	Updated        string                         `json:"updated"`
	Version        string                         `json:"version"`
	Visibility     string                         `json:"visibility"`
}

type QueryCreateRequest

type QueryCreateRequest struct {
	Name      string `json:"name"`
	Content   string `json:"content"`
	Language  string `json:"language"`
	Published bool   `json:"published,omitempty"`
}

type QueryParameter

type QueryParameter struct {
	Type     string `json:"type,omitempty"`
	Datatype string `json:"datatype,omitempty"`
}

type QueryService

type QueryService struct {
	// contains filtered or unexported fields
}

func (*QueryService) CreateSavedQueryInDataset

func (s *QueryService) CreateSavedQueryInDataset(owner, datasetid string, body *QueryCreateRequest) (
	response QuerySummaryResponse, err error)

CreateSavedQueryInDataset creates a saved query in the specified dataset.

func (*QueryService) CreateSavedQueryInProject

func (s *QueryService) CreateSavedQueryInProject(owner, projectid string, body *QueryCreateRequest) (
	response QuerySummaryResponse, err error)

CreateSavedQueryInProject creates a saved query in the specified project.

func (*QueryService) DeleteSavedQueryInDataset

func (s *QueryService) DeleteSavedQueryInDataset(owner, datasetid, queryid string) (
	response SuccessResponse, err error)

DeleteSavedQueryInDataset deletes a saved query in the specified dataset.

func (*QueryService) DeleteSavedQueryInProject

func (s *QueryService) DeleteSavedQueryInProject(owner, projectid, queryid string) (
	response SuccessResponse, err error)

DeleteSavedQueryInProject deletes a saved query in the specified project.

func (*QueryService) ExecuteSPARQL

func (s *QueryService) ExecuteSPARQL(owner, id, acceptType string, body *SPARQLQueryRequest) (
	response io.ReadCloser, err error)

ExecuteSPARQL runs a SPARQL query against a dataset or data project.

SPARQL results are available in a variety of formats. See https://apidocs.data.world/api/queries/sparqlpost for the full list of return types.

func (*QueryService) ExecuteSPARQLAndSave

func (s *QueryService) ExecuteSPARQLAndSave(owner, id, acceptType, path string, body *SPARQLQueryRequest) (
	response SuccessResponse, err error)

ExecuteSPARQLAndSave runs a SPARQL query against a dataset or data project and saves the results to a file.

SPARQL results are available in a variety of formats. See https://apidocs.data.world/api/queries/sparqlpost for the full list of return types.

func (*QueryService) ExecuteSQL

func (s *QueryService) ExecuteSQL(owner, id, acceptType string, body *SQLQueryRequest) (
	response io.ReadCloser, err error)

ExecuteSQL runs a SQL query against a dataset or data project.

SQL results are available in a variety of formats. See https://apidocs.data.world/api/queries/sqlpost for the full list of return types.

func (*QueryService) ExecuteSQLAndSave

func (s *QueryService) ExecuteSQLAndSave(owner, id, acceptType, path string, body *SQLQueryRequest) (
	response SuccessResponse, err error)

ExecuteSQLAndSave runs a SQL query against a dataset or data project and saves the results to a file.

SQL results are available in a variety of formats. See https://apidocs.data.world/api/queries/sqlpost for the full list of return types.

Example
owner := "dataset-owner"
id := "my-awesome-dataset"
acceptType := "text/csv"
savePath := "./query-results.csv"
body := SQLQueryRequest{
	Query:              "SELECT * FROM Tables",
	IncludeTableSchema: false,
}

_, err := dw.Query.ExecuteSQLAndSave(owner, id, acceptType, savePath, &body)
if err != nil {
	log.Fatal(err)
}
Output:

func (*QueryService) ExecuteSavedQuery

func (s *QueryService) ExecuteSavedQuery(queryid, acceptType string, body *SavedQueryExecutionRequest) (
	response io.ReadCloser, err error)

ExecuteSavedQuery runs a saved query against a dataset or data project.

SPARQL results are available in a variety of formats. See https://apidocs.data.world/api/queries/executequery for the full list of return types.

func (*QueryService) ExecuteSavedQueryAndSave

func (s *QueryService) ExecuteSavedQueryAndSave(queryid, acceptType, path string, body *SavedQueryExecutionRequest) (
	response SuccessResponse, err error)

ExecuteSavedQueryAndSave runs a saved query against a dataset or data project and saves the results to a file.

SPARQL results are available in a variety of formats. See https://apidocs.data.world/api/queries/executequery for the full list of return types.

func (*QueryService) ListQueriesAssociatedWithDataset

func (s *QueryService) ListQueriesAssociatedWithDataset(owner, datasetid string) (
	response []QuerySummaryResponse, err error)

ListQueries lists the saved queries associated with a dataset.

Query definitions will be returned, not the query results. To retrieve the query results, use `Query.ExecuteSavedQuery`.

func (*QueryService) ListQueriesAssociatedWithProject

func (s *QueryService) ListQueriesAssociatedWithProject(owner, projectid string) (
	response []QuerySummaryResponse, err error)

ListQueries lists the saved queries associated with a project.

Query definitions will be returned, not the query results. To retrieve the query results, use `Query.ExecuteSavedQuery`.

func (*QueryService) Retrieve

func (s *QueryService) Retrieve(queryid string) (response QuerySummaryResponse, err error)

Retrieve fetches a saved query.

Query definitions will be returned, not the query results. To retrieve the query results, use `Query.ExecuteSavedQuery`.

func (*QueryService) RetrieveVersion

func (s *QueryService) RetrieveVersion(queryid, versionid string) (response QuerySummaryResponse, err error)

RetrieveVersion fetches a version of a saved query.

Query definitions will be returned, not the query results. To retrieve the query results, use `Query.ExecuteSavedQuery`.

func (*QueryService) UpdateSavedQueryInDataset

func (s *QueryService) UpdateSavedQueryInDataset(owner, datasetid, queryid string, body *QueryUpdateRequest) (
	response QuerySummaryResponse, err error)

UpdateSavedQueryInDataset updates a saved query in the specified dataset.

func (*QueryService) UpdateSavedQueryInProject

func (s *QueryService) UpdateSavedQueryInProject(owner, datasetid, queryid string, body *QueryUpdateRequest) (
	response QuerySummaryResponse, err error)

UpdateSavedQueryInProject updates a saved query in the specified project.

type QuerySummaryResponse

type QuerySummaryResponse struct {
	Body       string                    `json:"body,omitempty"`
	Created    string                    `json:"created,omitempty"`
	ID         string                    `json:"id,omitempty"`
	Language   string                    `json:"language,omitempty"`
	Name       string                    `json:"name,omitempty"`
	Owner      string                    `json:"owner,omitempty"`
	Updated    string                    `json:"updated,omitempty"`
	Version    string                    `json:"version,omitempty"`
	Parameters map[string]QueryParameter `json:"parameters,omitempty"`
}

type QueryUpdateRequest

type QueryUpdateRequest struct {
	Name      string `json:"name"`
	Content   string `json:"content"`
	Published bool   `json:"published,omitempty"`
}

type SPARQLQueryRequest

type SPARQLQueryRequest struct {
	Query string `json:"query"`
}

type SQLQueryRequest

type SQLQueryRequest struct {
	Query              string `json:"query"`
	IncludeTableSchema bool   `json:"includeTableSchema,omitempty"`
}

type SavedQueryExecutionRequest

type SavedQueryExecutionRequest struct {
	Parameters         map[string]string `json:"parameters,omitempty"`
	IncludeTableSchema bool              `json:"includeTableSchema,omitempty"`
	MaxRows            float64           `json:"maxRows,omitempty"`
}

type StreamSchema

type StreamSchema struct {
	PrimaryKeyFields []string `json:"primaryKeyFields,omitempty"`
	SequenceField    string   `json:"sequenceField,omitempty"`
}

type StreamSchemaUpdateRequest

type StreamSchemaUpdateRequest struct {
	PrimaryKeyFields []string `json:"primaryKeyFields,omitempty"`
	SequenceField    string   `json:"sequenceField,omitempty"`
	UpdateMethod     string   `json:"updateMethod"`
}

type StreamService

type StreamService struct {
	// contains filtered or unexported fields
}

func (*StreamService) Append

func (s *StreamService) Append(owner, id, streamid string, body io.Reader) (response SuccessResponse, err error)

Append JSON data to a stream associated with a dataset.

data.world streams are append-only by default. Alternatively, if a primary key is specified (see: `Stream.SetOrUpdateSchema()`), data.world will replace records with the same primary key value.

Streams don’t need to be created before you can append data to them. They will be created on-demand. Either when the first record is appended or when the schema is defined.

Multiple records can be appended at once by using `application/json-l` as the request content type.

Data uploaded to a dataset via a stream is not immediately processed. Instead, it is processed automatically in accordance with the dataset settings (default: daily) or as a result of calling `File.Sync()`.

Once processed, the contents of a stream will appear as a .jsonl file.

Example
type Language struct {
	Name string
	Year int
	URL  string
}

python := Language{
	Name: "Python",
	Year: 1991,
	URL:  "http://python.org",
}

golang := Language{
	Name: "Go",
	Year: 2009,
	URL:  "http://golang.org",
}

l1, _ := json.Marshal(python)
l2, _ := json.Marshal(golang)

ls := [][]byte{l1, l2}
b := bytes.Join(ls, []byte("\n"))

body := bytes.NewReader(b)
owner := testClientOwner
id := "my-awesome-dataset"
streamid := "my-stream"

_, err := dw.Stream.Append(owner, id, streamid, body)
if err != nil {
	log.Fatal(err)
}
Output:

func (*StreamService) Delete

func (s *StreamService) Delete(owner, id, streamid string) (response SuccessResponse, err error)

Delete all records previously appended to a stream.

func (*StreamService) RetrieveSchema

func (s *StreamService) RetrieveSchema(owner, id, streamid string) (response StreamSchema, err error)

RetrieveSchema fetches a stream’s schema.

func (*StreamService) SetOrUpdateSchema

func (s *StreamService) SetOrUpdateSchema(owner, id, streamid string, body *StreamSchemaUpdateRequest) (
	response SuccessResponse, err error)

SetOrUpdateSchema sets or updates a stream’s schema. The schema of a stream defines its primary key(s) and sort/sequence field.

data.world streams are append-only by default. Alternatively, if a primary key is specified, data.world will replace records with the same primary key value. data.world will sort records by sequence field value and will discard all but the last record appended for each given primary key value.

The updateMethod parameter specifies how data.world should handle existing records when the schema is updated. Currently, the only updateMethod supported is TRUNCATED. data.world will discard all records when the schema is updated.

Example
owner := testClientOwner
id := "my-awesome-dataset"
streamid := "my-stream"
body := StreamSchemaUpdateRequest{
	PrimaryKeyFields: []string{"id"},
	SequenceField:    "creation_time",
	UpdateMethod:     "TRUNCATE",
}

_, err := dw.Stream.SetOrUpdateSchema(owner, id, streamid, &body)
if err != nil {
	log.Fatal(err)
}
Output:

type Subscription

type Subscription struct {
	Dataset DatasetOrProjectIdentifier `json:"dataset,omitempty"`
	Events  []string                   `json:"events"`
	Project DatasetOrProjectIdentifier `json:"project,omitempty"`
	User    UserIdentifier             `json:"user,omitempty"`
}

type SubscriptionCreateRequest

type SubscriptionCreateRequest struct {
	Events []string `json:"events"`
}

type SuccessResponse

type SuccessResponse struct {
	Message string `json:"message,omitempty"`
}

type UserIdentifier

type UserIdentifier struct {
	ID string `json:"id"`
}

type UserInfoResponse

type UserInfoResponse struct {
	AvatarURL   string `json:"avatarUrl,omitempty"`
	Created     string `json:"created"`
	DisplayName string `json:"displayName,omitempty"`
	ID          string `json:"id"`
	Updated     string `json:"updated"`
}

type UserService

type UserService struct {
	// contains filtered or unexported fields
}

func (*UserService) DatasetsContributing

func (s *UserService) DatasetsContributing() (response []DatasetSummaryResponse, err error)

DatasetsContributing lists the datasets that the currently authenticated user has access to because they are a contributor.

func (*UserService) DatasetsLiked

func (s *UserService) DatasetsLiked() (response []DatasetSummaryResponse, err error)

DatasetsLiked lists the datasets that the currently authenticated user has liked (bookmarked).

func (*UserService) DatasetsOwned

func (s *UserService) DatasetsOwned() (response []DatasetSummaryResponse, err error)

DatasetsOwned lists the datasets that the currently authenticated user has access to because they are the owner.

func (*UserService) ProjectsContributing

func (s *UserService) ProjectsContributing() (response []ProjectSummaryResponse, err error)

ProjectsContributing lists the projects that the currently authenticated user has access to because they are a contributor.

func (*UserService) ProjectsLiked

func (s *UserService) ProjectsLiked() (response []ProjectSummaryResponse, err error)

ProjectsLiked lists the projects that the currently authenticated user has liked (bookmarked).

func (*UserService) ProjectsOwned

func (s *UserService) ProjectsOwned() (response []ProjectSummaryResponse, err error)

ProjectsOwned lists the datasets that the currently authenticated user has access to because they are the owner.

func (*UserService) Retrieve

func (s *UserService) Retrieve(agentid string) (response UserInfoResponse, err error)

Retrieve the user profile information for the specified account.

func (*UserService) Self

func (s *UserService) Self() (response UserInfoResponse, err error)

Self retrieves the user profile information of the currently authenticated user.

type WebAuthorization

type WebAuthorization struct {
	Credentials string `json:"credentials,omitempty"`
	Type        string `json:"type"`
}

type WebCredentials

type WebCredentials struct {
	Password string `json:"password,omitempty"`
	User     string `json:"user"`
}

type WebhookService

type WebhookService struct {
	// contains filtered or unexported fields
}

func (*WebhookService) List

func (s *WebhookService) List() (response []Subscription, err error)

List the webhook subscriptions associated with the currently authenticated user.

func (*WebhookService) RetrieveAccountSubscription

func (s *WebhookService) RetrieveAccountSubscription(user string) (response Subscription, err error)

RetrieveAccountSubscription fetches the webhook subscription based on the currently authenticated user and the given organization or user account.

func (*WebhookService) RetrieveDatasetSubscription

func (s *WebhookService) RetrieveDatasetSubscription(owner, datasetid string) (response Subscription, err error)

RetrieveDatasetSubscription fetches the webhook subscription associated with the currently authenticated user and to the given dataset.

func (*WebhookService) RetrieveProjectSubscription

func (s *WebhookService) RetrieveProjectSubscription(owner, projectid string) (response Subscription, err error)

RetrieveProjectSubscription fetches the webhook subscription associated with the currently authenticated user and to the given project.

func (*WebhookService) SubscribeToAccount

func (s *WebhookService) SubscribeToAccount(user string, body *SubscriptionCreateRequest) (
	response SuccessResponse, err error)

SubscribeToAccount creates a webhook subscription associated with the currently authenticated user and to the given organization or user account.

func (*WebhookService) SubscribeToDataset

func (s *WebhookService) SubscribeToDataset(owner, datasetid string, body *SubscriptionCreateRequest) (
	response SuccessResponse, err error)

SubscribeToDataset creates a webhook subscription associated with the currently authenticated user and to the given dataset.

func (*WebhookService) SubscribeToProject

func (s *WebhookService) SubscribeToProject(owner, projectid string, body *SubscriptionCreateRequest) (
	response SuccessResponse, err error)

SubscribeToProject creates a webhook subscription associated with the currently authenticated user and to the given project.

func (*WebhookService) UnsubscribeFromAccount added in v0.2.0

func (s *WebhookService) UnsubscribeFromAccount(user string) (response SuccessResponse, err error)

UnsubscribeFromAccount deletes a webhook subscription associated with the currently authenticated user and to the given organization or user account.

func (*WebhookService) UnsubscribeFromDataset added in v0.2.0

func (s *WebhookService) UnsubscribeFromDataset(owner, datasetid string) (response SuccessResponse, err error)

UnsubscribeFromDataset deletes a webhook subscription associated with the currently authenticated user and to the given dataset.

func (*WebhookService) UnsubscribeFromProject added in v0.2.0

func (s *WebhookService) UnsubscribeFromProject(owner, projectid string) (response SuccessResponse, err error)

UnsubscribeFromProject deletes a webhook subscription associated with the currently authenticated user and to the given project.

Jump to

Keyboard shortcuts

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