acd

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2015 License: MIT Imports: 17 Imported by: 0

README

Amazon Cloud Drive client for Go

Build Status GoDoc

Amazon Cloud Drive uses oAuth 2.0 for authentication. The token server takes care of the oAuth authentication. For your convenience, an instance of the server is deployed at:

https://go-acd.appspot.com

Install

This project is go-gettable:

go get gopkg.in/acd.v0/...

Usage

In order to use this library, you must authenticate through the token server.

CLI

Run acd help for usage.

Library

Consult the Godoc for information on how to use the library.

Contributions

This repository does not accept pull requests. All contributions must go through Phabricator. Please refer to Arcanist Quick Start to install arc and learn basic commands.

Credits

Although this project was built from scratch, it was inspired by the following:

License

Refer to the LICENSE file.

Documentation

Overview

Package acd represent an Amazon Cloud Drive client.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultCacheFile

func DefaultCacheFile() string

DefaultCacheFile returns the default path for the cache file. This is os-dependent setting.

func DefaultConfigFile

func DefaultConfigFile() string

DefaultConfigFile returns the default path for the configuration file. This is os-dependent setting.

func DefaultTokenFile

func DefaultTokenFile() string

DefaultTokenFile returns the default path for the token file. This is os-dependent setting.

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 AccountUsage

type AccountUsage struct {
	LastCalculated time.Time `json:"lastCalculated"`

	Doc struct {
		Billable struct {
			Bytes uint64 `json:"bytes"`
			Count uint32 `json:"count"`
		} `json:"billable"`
		Total struct {
			Bytes uint64 `json:"bytes"`
			Count uint32 `json:"count"`
		} `json:"total"`
	} `json:"doc"`

	Other struct {
		Billable struct {
			Bytes uint64 `json:"bytes"`
			Count uint32 `json:"count"`
		} `json:"billable"`
		Total struct {
			Bytes uint64 `json:"bytes"`
			Count uint32 `json:"count"`
		} `json:"total"`
	} `json:"other"`

	Photo struct {
		Billable struct {
			Bytes uint64 `json:"bytes"`
			Count uint32 `json:"count"`
		} `json:"billable"`
		Total struct {
			Bytes uint64 `json:"bytes"`
			Count uint32 `json:"count"`
		} `json:"total"`
	} `json:"photo"`

	Video struct {
		Billable struct {
			Bytes uint64 `json:"bytes"`
			Count uint32 `json:"count"`
		} `json:"billable"`
		Total struct {
			Bytes uint64 `json:"bytes"`
			Count uint32 `json:"count"`
		} `json:"total"`
	} `json:"video"`
}

AccountUsage represents information about the account usage.

type Client

type Client struct {
	// NodeTree is the tree of nodes as stored on the drive. This tree should
	// be fetched using (*Client).FetchNodeTree() as soon the client is
	// created.
	NodeTree *node.Tree
	// contains filtered or unexported fields
}

Client provides a client for Amazon Cloud Drive.

func New

func New(configFile string) (*Client, error)

New returns a new Amazon Cloud Drive "acd" Client. configFile must exist and must be a valid JSON decodable into Config.

func (*Client) CheckResponse

func (c *Client) CheckResponse(res *http.Response) error

CheckResponse validates the response from the Amazon Cloud Drive API. It does that by looking at the response's status code and it returns an error for any code lower than 200 or greater than 300

func (*Client) Close

func (c *Client) Close() error

Close finalizes the acd.

func (*Client) Do

func (c *Client) Do(r *http.Request) (*http.Response, error)

Do invokes net/http.Client.Do(). Refer to net/http.Client.Do() for documentation.

func (*Client) Download

func (c *Client) Download(path string) (io.ReadCloser, error)

Download returns an io.ReadCloser for path. The caller is responsible for closing the body.

func (*Client) DownloadFolder

func (c *Client) DownloadFolder(localPath, remotePath string, recursive bool) error

DownloadFolder downloads an entire folder to a path, if recursive is true, it will also download all subfolders.

func (*Client) FetchNodeTree

func (c *Client) FetchNodeTree() error

FetchNodeTree fetches and caches the NodeTree.

func (*Client) GetAccountInfo

func (c *Client) GetAccountInfo() (*AccountInfo, error)

GetAccountInfo returns AccountInfo about the current account.

func (*Client) GetAccountQuota

func (c *Client) GetAccountQuota() (*AccountQuota, error)

GetAccountQuota returns AccountQuota about the current account.

func (*Client) GetAccountUsage

func (c *Client) GetAccountUsage() (*AccountUsage, error)

GetAccountUsage returns AccountUsage about the current account.

func (*Client) GetContentURL

func (c *Client) GetContentURL(path string) string

GetContentURL returns the content url.

func (*Client) GetMetadataURL

func (c *Client) GetMetadataURL(path string) string

GetMetadataURL returns the metadata url.

func (*Client) GetNodeTree

func (c *Client) GetNodeTree() *node.Tree

GetNodeTree returns the NodeTree.

func (*Client) List

func (c *Client) List(path string) (node.Nodes, error)

List returns nodes.Nodes for all of the nodes underneath the path. It's up to the caller to differentiate between a file, a folder or an asset by using (*node.Node).IsFile(), (*node.Node).IsDir() and/or (*node.Node).IsAsset(). A dir has sub-nodes accessible via (*node.Node).Nodes, you do not need to call this this function for every sub-node.

func (*Client) Upload

func (c *Client) Upload(filename string, overwrite bool, r io.Reader) error

Upload uploads io.Reader to the path defined by the filename. It will create any non-existing folders.

func (*Client) UploadFolder

func (c *Client) UploadFolder(localPath, remotePath string, recursive, overwrite bool) error

UploadFolder uploads an entire folder. If recursive is true, it will recurse through the entire filetree under localPath. If overwrite is false and an existing file with the same md5 was found, an error will be returned.

type Config

type Config struct {
	// TokenFile represents the file containing the oauth settings which must
	// be present on disk and has permissions 0600. The file is used by the
	// token package to produce a valid access token by calling the oauthServer
	// with the refresh token.  The default oauth server is hosted at
	// https://go-acd.appspot.com with the source code available at
	// https://github.com/go-acd/oauth-server.  It's currently not possible to
	// change the oauth-server. Please feel free to add this feature if you
	// have a use-case for it.
	TokenFile string `json:"tokenFile"`

	// CacheFile represents the file used by the client to cache the NodeTree.
	// This file is not assumed to be present and will be created on the first
	// run. It is gob-encoded node.Node.
	CacheFile string `json:"cacheFile"`

	// Timeout configures the HTTP Client with a timeout after which the client
	// will cancel the request and return. A timeout of 0 (the default) means
	// no timeout. See http://godoc.org/net/http#Client for more information.
	Timeout time.Duration `json:"timeout"`
}

Config represents the clients configuration.

Directories

Path Synopsis
cmd
acd
Package integrationtest is the integration test of the library.
Package integrationtest is the integration test of the library.
internal
log
Package log provides a common logging package for ACD with logging level.
Package log provides a common logging package for ACD with logging level.
Package node represents the Amazon Cloud Drive nodes documented at https://developer.amazon.com/public/apis/experience/cloud-drive/content/nodes It also provides the Tree struct which allows you to refer to the entire filesystem as a file tree as defined by the Amazon documentation.
Package node represents the Amazon Cloud Drive nodes documented at https://developer.amazon.com/public/apis/experience/cloud-drive/content/nodes It also provides the Tree struct which allows you to refer to the entire filesystem as a file tree as defined by the Amazon documentation.
Package token represents an oauth2.TokenSource which has the ability to refresh the access token through the oauth server.
Package token represents an oauth2.TokenSource which has the ability to refresh the access token through the oauth server.

Jump to

Keyboard shortcuts

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