acd

package module
v0.0.0-...-687e635 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2024 License: ISC Imports: 15 Imported by: 0

README

go-acd Build Status

Go library for accessing the Amazon Cloud Drive.

This library is the basis for acdcli.

Still work in progress. Focusing on read-only operations at first. Refer to the milestones and issues for planned features.

Documentation

Index

Constants

View Source
const (
	// LibraryVersion is the current version of this library
	LibraryVersion = "0.1.0"
)

Variables

View Source
var (
	// ErrorNodeNotFound is returned from GetFile, GetFolder, GetNode
	ErrorNodeNotFound = errors.New("Node not found")
)

Functions

func CheckResponse

func CheckResponse(r *http.Response) error

CheckResponse checks the API response for errors, and returns them if present. A response is considered an error if it has a status code outside the 200 range.

func EscapeForFilter

func EscapeForFilter(s string) string

EscapeForFilter escapes an abitrary string for use as a filter query parameter.

Special characters that are part of the query syntax will be escaped. The list of special characters are:

+ - & | ! ( ) { } [ ] ^ ' " ~ * ? : \

Additionally, space will be escaped. Characters are escaped by using \ before the character.

Types

type AccountEndpoints

type AccountEndpoints struct {
	CustomerExists bool   `json:"customerExists"`
	ContentURL     string `json:"contentUrl"`
	MetadataURL    string `json:"metadataUrl"`
}

AccountEndpoints represents information about the current customer's endpoints

type AccountInfo

type AccountInfo struct {
	TermsOfUse *string `json:"termsOfUse"`
	Status     *string `json:"status"`
}

AccountInfo represents information about an Amazon Cloud Drive account.

type AccountQuota

type AccountQuota struct {
	Quota          *uint64    `json:"quota"`
	LastCalculated *time.Time `json:"lastCalculated"`
	Available      *uint64    `json:"available"`
}

AccountQuota represents information about the account quotas.

type AccountService

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

AccountService provides access to the account related functions in the Amazon Cloud Drive API.

See: https://developer.amazon.com/public/apis/experience/cloud-drive/content/account

func (*AccountService) GetEndpoints

func (s *AccountService) GetEndpoints() (*AccountEndpoints, *http.Response, error)

GetEndpoints retrives the current endpoints for this customer

It also updates the endpoints in the client

func (*AccountService) GetInfo

func (s *AccountService) GetInfo() (*AccountInfo, *http.Response, error)

GetInfo provides information about the current user account like the status and the accepted “Terms Of Use”.

func (*AccountService) GetQuota

func (s *AccountService) GetQuota() (*AccountQuota, *http.Response, error)

GetQuota gets account quota and storage availability information.

func (*AccountService) GetUsage

func (s *AccountService) GetUsage() (*AccountUsage, *http.Response, error)

GetUsage gets Account Usage information broken down by content category.

type AccountUsage

type AccountUsage struct {
	LastCalculated *time.Time     `json:"lastCalculated"`
	Other          *CategoryUsage `json:"other"`
	Doc            *CategoryUsage `json:"doc"`
	Photo          *CategoryUsage `json:"photo"`
	Video          *CategoryUsage `json:"video"`
}

AccountUsage represents information about the account usage.

type CategoryUsage

type CategoryUsage struct {
	Total    *UsageNumbers `json:"total"`
	Billable *UsageNumbers `json:"billable"`
}

CategoryUsage defines Total and Billable UsageNumbers

type ChangeSet

type ChangeSet struct {
	Checkpoint string  `json:"checkpoint"`
	Nodes      []*Node `json:"nodes"`
	Reset      bool    `json:"reset"`
	StatusCode int     `json:"statusCode"`
	End        bool    `json:"end"`
}

A ChangeSet is collection of node changes as received from the Changes API

type ChangesOptions

type ChangesOptions struct {
	Checkpoint    string `json:"checkpoint,omitempty"`
	ChunkSize     int    `json:"chunkSize,omitempty"`
	MaxNodes      int    `json:"maxNodes,omitempty"`
	IncludePurged bool   `json:"includePurged,omitempty,string"`
}

ChangesOptions contains all possible arguments for the Changes API

type ChangesService

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

ChangesService provides access to incemental changes in the Amazon Cloud Drive API.

See: https://developer.amazon.com/public/apis/experience/cloud-drive/content/changes

func (*ChangesService) GetChanges

func (s *ChangesService) GetChanges(opts *ChangesOptions) ([]*ChangeSet, *http.Response, error)

GetChanges returns all the changes since opts.Checkpoint

func (*ChangesService) GetChangesChan

func (s *ChangesService) GetChangesChan(opts *ChangesOptions, ch chan<- *ChangeSet) (*http.Response, error)

GetChangesChan gets all the changes since opts.Checkpoint sending each ChangeSet to the channel. The provided channel is closed before returning

func (*ChangesService) GetChangesFunc

func (s *ChangesService) GetChangesFunc(opts *ChangesOptions, f func(*ChangeSet, error) error) (*http.Response, error)

GetChangesFunc gets all the changes since opts.Checkpoint and calls f with the ChangeSet or the error received. If f returns a non nil value, GetChangesFunc exits and returns the given error.

type Client

type Client struct {

	// Metadata URL for API requests. Defaults to the public Amazon Cloud Drive API.
	// MetadataURL should always be specified with a trailing slash.
	MetadataURL *url.URL

	// Content URL for API requests. Defaults to the public Amazon Cloud Drive API.
	// ContentURL should always be specified with a trailing slash.
	ContentURL *url.URL

	// User agent used when communicating with the API.
	UserAgent string

	// Services used for talking to different parts of the API.
	Account *AccountService
	Nodes   *NodesService
	Changes *ChangesService
	// contains filtered or unexported fields
}

A Client manages communication with the Amazon Cloud Drive API.

func NewClient

func NewClient(httpClient *http.Client) *Client

NewClient returns a new Amazon Cloud Drive API client. If a nil httpClient is provided, http.DefaultClient will be used. To use API methods which require authentication, provide an http.Client that will perform the authentication for you (such as that provided by the golang.org/x/oauth2 library).

func (*Client) Do

func (c *Client) Do(req *http.Request, v interface{}) (*http.Response, error)

Do sends an API request and returns the API response. The API response is JSON decoded and stored in the value pointed to by v, or returned as an error if an API error has occurred. If v implements the io.Writer interface, the raw response body will be written to v, without attempting to first decode it. If v is nil then the resp.Body won't be closed - this is your responsibility.

func (*Client) NewContentRequest

func (c *Client) NewContentRequest(method, urlStr string, body interface{}) (*http.Request, error)

NewContentRequest creates an API request for content. A relative URL can be provided in urlStr, in which case it is resolved relative to the ContentURL of the Client. Relative URLs should always be specified without a preceding slash. If specified, the value pointed to by body is JSON encoded and included as the request body.

func (*Client) NewMetadataRequest

func (c *Client) NewMetadataRequest(method, urlStr string, body interface{}) (*http.Request, error)

NewMetadataRequest creates an API request for metadata. A relative URL can be provided in urlStr, in which case it is resolved relative to the MetadataURL of the Client. Relative URLs should always be specified without a preceding slash. If specified, the value pointed to by body is JSON encoded and included as the request body.

type File

type File struct {
	*Node
}

File represents a file on the Amazon Cloud Drive.

func (*File) Download

func (f *File) Download(path string) (*http.Response, error)

Download fetches the content of file f and stores it into the file pointed to by path. Errors if the file at path already exists. Does not create the intermediate directories in path.

func (*File) Open

func (f *File) Open() (in io.ReadCloser, resp *http.Response, err error)

Open the content of the file f for read

You must call in.Close() when finished

func (*File) OpenHeaders

func (f *File) OpenHeaders(headers map[string]string) (in io.ReadCloser, resp *http.Response, err error)

OpenHeaders opens the content of the file f for read

Extra headers for the GET can be passed in in headers

You must call in.Close() when finished

func (*File) OpenTempURL

func (f *File) OpenTempURL(client *http.Client) (in io.ReadCloser, resp *http.Response, err error)

OpenTempURL opens the content of the file f for read from the TempURL

Pass in an http Client (without authorization) for the download.

You must call in.Close() when finished

func (*File) OpenTempURLHeaders

func (f *File) OpenTempURLHeaders(client *http.Client, headers map[string]string) (in io.ReadCloser, resp *http.Response, err error)

OpenTempURLHeaders opens the content of the file f for read from the TempURL

Pass in an http Client (without authorization) for the download.

You must call in.Close() when finished

func (*File) Overwrite

func (f *File) Overwrite(in io.Reader) (*File, *http.Response, error)

Overwrite updates the file contents from in

func (*File) OverwriteSized deprecated

func (f *File) OverwriteSized(in io.Reader, _ int64) (*File, *http.Response, error)

OverwriteSized updates the file contents from in

Deprecated: no longer needed - just use Overwrite

type Folder

type Folder struct {
	*Node
}

Folder represents a folder on the Amazon Cloud Drive.

func FolderFromId

func FolderFromId(ID string, service *NodesService) *Folder

FolderFromId constructs a skeleton Folder from an Id and a NodeService

func (*Folder) CreateFolder

func (f *Folder) CreateFolder(name string) (*Folder, *http.Response, error)

CreateFolder makes a new folder with the given name.

The new Folder is returned

func (*Folder) GetAllChildren

func (f *Folder) GetAllChildren(opts *NodeListOptions) ([]*Node, *http.Response, error)

GetAllChildren gets the list of all children.

func (*Folder) GetChildren

func (f *Folder) GetChildren(opts *NodeListOptions) ([]*Node, *http.Response, error)

GetChildren gets a list of children, up until the limit (either default or the one set in opts).

func (*Folder) GetFile

func (f *Folder) GetFile(name string) (*File, *http.Response, error)

GetFile gets the file by name. It is an error if not exactly one file is found.

If it isn't found then it returns the error ErrorNodeNotFound

func (*Folder) GetFolder

func (f *Folder) GetFolder(name string) (*Folder, *http.Response, error)

GetFolder gets the subfolder by name. It is an error if not exactly one subfolder is found.

If it isn't found then it returns the error ErrorNodeNotFound

func (*Folder) GetNode

func (f *Folder) GetNode(name string) (*Node, *http.Response, error)

GetNode gets the node by name. It is an error if not exactly one node is found.

If it isn't found then it returns the error ErrorNodeNotFound

func (*Folder) Put

func (f *Folder) Put(in io.Reader, name string) (*File, *http.Response, error)

Put stores the data read from in at path as name on the Amazon Cloud Drive. Errors if the file already exists on the drive.

func (*Folder) PutSized deprecated

func (f *Folder) PutSized(in io.Reader, _ int64, name string) (*File, *http.Response, error)

PutSized stores the data read from in at path as name on the Amazon Cloud Drive. Errors if the file already exists on the drive.

Deprecated: no longer needed - just use Put

func (*Folder) Upload

func (f *Folder) Upload(path, name string) (*File, *http.Response, error)

Upload stores the content of file at path as name on the Amazon Cloud Drive. Errors if the file already exists on the drive.

func (*Folder) WalkNodes

func (f *Folder) WalkNodes(names ...string) (*Node, []*http.Response, error)

WalkNodes walks the given node hierarchy, getting each node along the way, and returns the deepest node. If an error occurs, returns the furthest successful node and the list of HTTP responses.

type Node

type Node struct {
	Id                *string  `json:"id"`
	Name              *string  `json:"name"`
	Kind              *string  `json:"kind"`
	ModifiedDate      *string  `json:"modifiedDate"`
	Parents           []string `json:"parents"`
	Status            *string  `json:"status"`
	ContentProperties *struct {
		Size        *uint64 `json:"size"`
		Md5         *string `json:"md5"`
		ContentType *string `json:"contentType"`
	} `json:"contentProperties"`
	TempURL string `json:"tempLink"`
	// contains filtered or unexported fields
}

Node represents a digital asset on the Amazon Cloud Drive, including files and folders, in a parent-child relationship. A node contains only metadata (e.g. folder) or it contains metadata and content (e.g. file).

func NodeFromId

func NodeFromId(ID string, service *NodesService) *Node

NodeFromId constructs a skeleton Node from an Id and a NodeService

func (*Node) AddParent

func (n *Node) AddParent(newParentID string) (*http.Response, error)

AddParent adds an additional parent to Node n. Can return a 409 Conflict if there's already a file or folder below the new parent with the same name as Node n.

func (*Node) GetMetadata

func (n *Node) GetMetadata() (string, error)

GetMetadata return a pretty-printed JSON string of the node's metadata

func (*Node) GetTempURL

func (n *Node) GetTempURL() (*http.Response, error)

GetTempURL sets the TempURL for the node passed in if it isn't already set

func (*Node) IsFile

func (n *Node) IsFile() bool

IsFile returns whether the node represents a file.

func (*Node) IsFolder

func (n *Node) IsFolder() bool

IsFolder returns whether the node represents a folder.

func (*Node) RemoveParent

func (n *Node) RemoveParent(parentID string) (*http.Response, error)

RemoveParent removes a parent from Node n. If all parents are removed, the file is instead attached to the absolute root folder of AmazonDrive.

func (*Node) Rename

func (n *Node) Rename(newName string) (*Node, *http.Response, error)

Rename node

func (*Node) ReplaceParent

func (n *Node) ReplaceParent(oldParentID string, newParentID string) (*http.Response, error)

ReplaceParent puts Node n below a new parent while removing the old one at the same time. This is equivalent to calling AddParent and RemoveParent sequentially, but only needs one REST call. Can return a 409 Conflict if there's already a file or folder in the new location with the same name as Node n.

func (*Node) Restore

func (n *Node) Restore() (*Node, *http.Response, error)

Restore moves a previously trashed Node n back into all its connected parents

func (*Node) Trash

func (n *Node) Trash() (*http.Response, error)

Trash places Node n into the trash. If the node is a directory it places it and all of its contents into the trash.

func (*Node) Typed

func (n *Node) Typed() interface{}

Typed returns the Node typed as either File or Folder.

type NodeListOptions

type NodeListOptions struct {
	Limit   uint   `url:"limit,omitempty"`
	Filters string `url:"filters,omitempty"`
	Sort    string `url:"sort,omitempty"`

	// Token where to start for next page (internal)
	StartToken string `url:"startToken,omitempty"`
	// contains filtered or unexported fields
}

NodeListOptions holds the options when getting a list of nodes, such as the filter, sorting and pagination.

type NodesService

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

NodesService provides access to the nodes in the Amazon Cloud Drive API.

See: https://developer.amazon.com/public/apis/experience/cloud-drive/content/nodes

func (*NodesService) GetAllNodes

func (s *NodesService) GetAllNodes(opts *NodeListOptions) ([]*Node, *http.Response, error)

GetAllNodes gets the list of all nodes.

func (*NodesService) GetNodes

func (s *NodesService) GetNodes(opts *NodeListOptions) ([]*Node, *http.Response, error)

GetNodes gets a list of nodes, up until the limit (either default or the one set in opts).

func (*NodesService) GetRoot

func (s *NodesService) GetRoot() (*Folder, *http.Response, error)

GetRoot gets the root folder of the Amazon Cloud Drive.

type UsageNumbers

type UsageNumbers struct {
	Bytes *uint64 `json:"bytes"`
	Count *uint64 `json:"count"`
}

UsageNumbers defines Bytes and Count for a metered count

Jump to

Keyboard shortcuts

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