acd

package module
v0.0.0-...-9264d0f Latest Latest
Warning

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

Go to latest
Published: May 23, 2015 License: ISC Imports: 14 Imported by: 3

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 = "0.1.0"
)

Variables

This section is empty.

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.

Types

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) GetInfo

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

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)

Gets account quota and storage availability information.

func (*AccountService) GetUsage

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

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"`
}

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
	// 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.

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.

type Folder

type Folder struct {
	*Node
}

Folder represents a folder on the Amazon Cloud Drive.

func (*Folder) GetAllChildren

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

Gets the list of all children.

func (*Folder) GetChildren

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

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)

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

func (*Folder) GetFolder

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

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

func (*Folder) GetNode

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

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

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"`
	ContentProperties *struct {
		Size *uint64 `json:"size"`
	} `json:"contentProperties"`
	// 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 (*Node) GetMetadata

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

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

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) 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)

Gets the list of all nodes.

func (*NodesService) GetNodes

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

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)

Gets the root folder of the Amazon Cloud Drive.

type UsageNumbers

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

Jump to

Keyboard shortcuts

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