api

package
v1.59.1 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2022 License: MIT Imports: 7 Imported by: 1

Documentation

Overview

Package api has type definitions and code related to API-calls for the HiDrive-API.

Index

Constants

View Source
const (
	HiDriveObjectTypeDirectory = "dir"
	HiDriveObjectTypeFile      = "file"
	HiDriveObjectTypeSymlink   = "symlink"
)

possible types for HiDriveObject

Variables

View Source
var (
	HiDriveObjectNoMetadataFields            = []string{"name", "type"}
	HiDriveObjectWithMetadataFields          = append(HiDriveObjectNoMetadataFields, "id", "size", "mtime", "chash")
	HiDriveObjectWithDirectoryMetadataFields = append(HiDriveObjectWithMetadataFields, "nmembers")
	DirectoryContentFields                   = []string{"nmembers"}
)

Some presets for different amounts of information that can be requested for fields; it is recommended to only request the information that is actually needed.

Functions

This section is empty.

Types

type DirectoryContent

type DirectoryContent struct {
	TotalCount int64           `json:"nmembers"`
	Entries    []HiDriveObject `json:"members"`
}

DirectoryContent describes the content of a directory.

func (*DirectoryContent) UnmarshalJSON

func (d *DirectoryContent) UnmarshalJSON(data []byte) error

UnmarshalJSON turns JSON into DirectoryContent and introduces specific default-values where necessary.

type Error

type Error struct {
	Code        json.Number `json:"code"`
	ContextInfo json.RawMessage
	Message     string `json:"msg"`
}

Error is returned from the API when things go wrong.

func (*Error) Error

func (e *Error) Error() string

Error returns a string for the error and satisfies the error interface.

type HiDriveObject

type HiDriveObject struct {
	Type         string `json:"type"`
	ID           string `json:"id"`
	ParentID     string `json:"parent_id"`
	Name         string `json:"name"`
	Path         string `json:"path"`
	Size         int64  `json:"size"`
	MemberCount  int64  `json:"nmembers"`
	ModifiedAt   Time   `json:"mtime"`
	ChangedAt    Time   `json:"ctime"`
	MetaHash     string `json:"mhash"`
	MetaOnlyHash string `json:"mohash"`
	NameHash     string `json:"nhash"`
	ContentHash  string `json:"chash"`
	IsTeamfolder bool   `json:"teamfolder"`
	Readable     bool   `json:"readable"`
	Writable     bool   `json:"writable"`
	Shareable    bool   `json:"shareable"`
	MIMEType     string `json:"mime_type"`
}

HiDriveObject describes a folder, a symlink or a file. Depending on the type and content, not all fields are present.

func (*HiDriveObject) ModTime

func (i *HiDriveObject) ModTime() time.Time

ModTime returns the modification time of the HiDriveObject.

func (*HiDriveObject) UnmarshalJSON

func (i *HiDriveObject) UnmarshalJSON(data []byte) error

UnmarshalJSON turns JSON into HiDriveObject and introduces specific default-values where necessary.

type QueryParameters

type QueryParameters struct {
	url.Values
}

QueryParameters represents the parameters passed to an API-call.

func NewQueryParameters

func NewQueryParameters() *QueryParameters

NewQueryParameters initializes an instance of QueryParameters and returns a pointer to it.

func (*QueryParameters) AddFields

func (p *QueryParameters) AddFields(prefix string, fields ...string)

AddFields sets the appropriate parameter to access the given fields. The given fields will be appended to any other existing fields.

func (*QueryParameters) AddList

func (p *QueryParameters) AddList(key string, separator string, values ...string)

AddList adds the given values as a list with each value separated by the separator. It appends to any existing values associated with key.

func (*QueryParameters) SetFileInDirectory

func (p *QueryParameters) SetFileInDirectory(filePath string)

SetFileInDirectory sets the appropriate parameters to specify a path to a file in a directory. This is used by requests that work with paths for files that do not exist yet. (For example when creating a file). Most requests use the format produced by SetPath(...).

func (*QueryParameters) SetPath

func (p *QueryParameters) SetPath(objectPath string)

SetPath sets the appropriate parameters to access the given path.

func (*QueryParameters) SetTime

func (p *QueryParameters) SetTime(key string, value time.Time) error

SetTime sets the key to the time-value. It replaces any existing values.

type Time

type Time time.Time

Time represents date and time information for the API.

func (*Time) MarshalJSON

func (t *Time) MarshalJSON() ([]byte, error)

MarshalJSON turns Time into JSON (in Unix-time/UTC).

func (*Time) UnmarshalJSON

func (t *Time) UnmarshalJSON(data []byte) error

UnmarshalJSON turns JSON into Time.

Jump to

Keyboard shortcuts

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