dropbox-sdk-0.3.1: A library to access the Dropbox HTTP API.

Safe HaskellSafe-Infered

Dropbox

Contents

Synopsis

Configuration

mkConfigSource

Arguments

:: Locale 
-> String

Your Dropbox app key

-> String

Your Dropbox app secret

-> AccessType

configAccessType

-> IO Config 

A convenience function that constructs a Config. It's in the IO monad because we read from a file to get the list of trusted SSL certificates, which is used to verify the server over SSL.

data Config Source

The configuration used to make API calls. You typically create one of these via the config helper function.

Constructors

Config 

Fields

configHosts :: Hosts

The hosts to connect to (just use hostsDefault).

configUserLocale :: Locale

The locale that the Dropbox service should use when returning user-visible strings.

configAppId :: AppId

Your app's key/secret

configAccessType :: AccessType

The type of folder access your Dropbox application uses.

Instances

data CertVerifier Source

How the server's SSL certificate will be verified.

Constructors

CertVerifier 

Fields

certVerifierName :: String

The human-friendly name of the policy (only for debug prints)

certVerifierFunc :: CertVerifierFunc

The function that implements certificate validation.

Instances

certVerifierInsecure :: CertVerifierSource

A dummy implementation that doesn't perform any verification.

certVerifierFromPemFile :: FilePath -> IO (Either String CertVerifier)Source

Reads certificates in PEM format from the given file and uses those as the roots when verifying certificates. This function basically just loads the certificates and delegates to certVerifierFromRootCerts for the actual checking.

certVerifierFromRootCertsSource

Arguments

:: [X509]

The set of trusted root certificates.

-> ByteString

The remote server's domain name.

-> [X509]

The certificate chain provided by the remote server.

-> IO TLSCertificateUsage 

A certificate validation routine. It's in IO to match what Enumerator expects, but we don't actually do any I/O.

data AppId Source

Your application's Dropbox "app key" and "app secret".

Constructors

AppId String String 

Instances

data Hosts Source

The set of hosts that serve the Dropbox API. Just use hostsDefault.

Constructors

Hosts 

Fields

hostsWeb :: String

The Dropbox API web host (for OAuth step 2)

hostsApi :: String

The Dropbox API endpoint for most non-content-transferring calls.

hostsApiContent :: String

The Dropbox API endpoint for most content-transferring calls.

Instances

hostsDefault :: HostsSource

The standard set of hosts that serve the Dropbox API. Used to create a Config.

data Locale Source

Specifies a locale (the string is a two-letter locale code)

Instances

localeEn :: LocaleSource

English (American) ("en").

localeEs :: LocaleSource

Spanish ("es").

localeFr :: LocaleSource

French ("fr").

localeDe :: LocaleSource

German ("de").

localeJp :: LocaleSource

Japanese ("jp").

data AccessType Source

The type of folder access your Dropbox application uses (https://www.dropbox.com/developers/start/core).

Constructors

AccessTypeDropbox

Full access to the user's entire Dropbox

AccessTypeAppFolder

Access to an application-specific "app folder" within the user's Dropbox

HTTP connection manager

type Manager = ManagerSource

The HTTP connection manager. Using the same Manager instance across multiple API calls

withManager :: (MonadBaseControl IO m, MonadThrow m, MonadUnsafeIO m, MonadIO m) => (Manager -> ResourceT m a) -> m aSource

A bracket around an HTTP connection manager. Uses default ManagerSettings as computed by managerSettings.

OAuth

data RequestToken Source

An OAuth request token (returned by authStart)

Constructors

RequestToken String String 

authStartSource

Arguments

:: Manager

The HTTP connection manager to use.

-> Config 
-> Maybe URL

The callback URL (optional)

-> IO (Either ErrorMessage (RequestToken, URL)) 

OAuth step 1. If successful, returns a RequestToken (to be used with authFinish eventually) and an authorization URL that you should redirect the user to next. If you provide a callback URL (optional), then the authorization URL you send the user to will redirect to your callback URL after the user authorizes your application.

data AccessToken Source

An OAuth request token (returned by authFinish, used to construct a Session)

Constructors

AccessToken String String 

authFinishSource

Arguments

:: Manager

The HTTP connection manager to use.

-> Config 
-> RequestToken

The RequestToken obtained from authStart

-> IO (Either ErrorMessage (AccessToken, String))

The AccessToken used to make Dropbox API calls and the user's Dropbox user ID.

OAuth step 3. Once you've directed the user to the authorization URL from authStart and the user has authorized your app, call this function to get a RequestToken, which is used to make Dropbox API calls.

data Session Source

Contains a Config and an AccessToken. Every API call (after OAuth is complete) requires this as an argument.

Get user account info

getAccountInfoSource

Arguments

:: Manager

The HTTP connection manager to use.

-> Session 
-> IO (Either ErrorMessage AccountInfo) 

Retrieve information about the user account your AccessToken is connected to.

data AccountInfo Source

Information about a user account.

Constructors

AccountInfo 

Fields

accountInfoUid :: Word64

Dropbox user ID

accountInfoDisplayName :: String

Full name (when displayed as a single string)

accountInfoCountry :: Maybe String

Two-letter country code, if available

accountInfoReferralUrl :: String

Dropbox referral link

accountInfoQuota :: Quota

Information about the storage quota

Get file/folder metadata

getMetadataSource

Arguments

:: (MonadBaseControl IO m, MonadThrow m, MonadUnsafeIO m, MonadIO m) 
=> Manager

The HTTP connection manager to use.

-> Session 
-> Path

The full path (relative to your DbAccessType root)

-> m (Either ErrorMessage Meta) 

Get the metadata for the file or folder at the given path.

getMetadataWithChildrenSource

Arguments

:: (MonadBaseControl IO m, MonadThrow m, MonadUnsafeIO m, MonadIO m) 
=> Manager

The HTTP connection manager to use.

-> Session 
-> Path

The full path (relative to your DbAccessType root)

-> Maybe Integer

A limit on folder contents (max: 10,000). If the path refers to a folder and this folder has more than the specified number of immediate children, the entire getMetadataWithChildren call will fail with an HTTP 406 error code. If unspecified, or if set to zero, the server will set this to 10,000.

-> m (Either ErrorMessage (Meta, Maybe FolderContents)) 

Get the metadata for the file or folder at the given path. If it's a folder, return the metadata for the folder's immediate children as well.

getMetadataWithChildrenIfChangedSource

Arguments

:: (MonadBaseControl IO m, MonadThrow m, MonadUnsafeIO m, MonadIO m) 
=> Manager

The HTTP connection manager to use.

-> Session 
-> Path 
-> Maybe Integer 
-> FolderHash

For folders, the returned child metadata will include a folderHash field that is a short identifier for the current state of the folder. If the FolderHash for the specified path hasn't change, this call will return Nothing, which indicates that the previously-retrieved metadata is still the latest.

-> m (Either ErrorMessage (Maybe (Meta, Maybe FolderContents))) 

Same as getMetadataWithChildren except it'll return Nothing if the FolderHash of the folder on Dropbox is the same as the FolderHash passed in.

data Meta Source

The metadata for a file or folder. MetaBase contains the metadata common to files and folders. MetaExtra contains the file-specific or folder-specific data.

Constructors

Meta MetaBase MetaExtra 

Instances

data MetaBase Source

Metadata common to both files and folders.

Constructors

MetaBase 

Fields

metaRoot :: AccessType

Matches the AccessType of the app that retrieved the metadata.

metaPath :: String

The full path (starting with a "/") of the file or folder, relative to metaRoot

metaIsDeleted :: Bool

Whether this metadata entry refers to a file that had been deleted when the entry was retrieved.

metaThumbnail :: Bool

Will be True if this file might have a thumbnail, and False if it definitely doesn't.

metaIcon :: String

The name of the icon used to illustrate this file type in Dropbox's icon library (https://www.dropbox.com/static/images/dropbox-api-icons.zip).

Instances

data MetaExtra Source

Extra metadata (in addition to the stuff that's common to files and folders).

Constructors

File FileExtra

Files have additional metadata

Folder

Folders do not have any additional metadata

data FolderContents Source

The metadata for the immediate children of a folder.

Constructors

FolderContents 

Fields

folderHash :: FolderHash

An identifier for the folder's metadata and children's metadata.

folderChildren :: [Meta]

The metadata for the immediate children of a folder.

data FileExtra Source

Extra metadata specific to files (and not folders)

Constructors

FileExtra 

Fields

fileBytes :: Integer

The file size (bytes)

fileHumanSize :: String

A human-readable representation of the file size, for example 15 bytes (localized according to Locale in Config)

fileRevision :: FileRevision

The revision of the file

fileModified :: UTCTime

When this file was added or last updated

newtype FolderHash Source

Represents an identifier for a folder's metadata and children's metadata. Can be used with getMetadataWithChildrenIfChanged to avoid downloading a folder's metadata and children's metadata if it hasn't changed.

Constructors

FolderHash String 

newtype FileRevision Source

Represents a file's revision (fileRevision).

Constructors

FileRevision String 

Upload/download files

getFileSource

Arguments

:: (MonadBaseControl IO m, MonadThrow m, MonadUnsafeIO m, MonadIO m) 
=> Manager

The HTTP connection manager to use.

-> Session 
-> Path

The full path (relative to your DbAccessType root)

-> Maybe FileRevision

The revision of the file to retrieve.

-> (Meta -> Sink ByteString (ResourceT m) r)

Given the file metadata, yield a Sink to process the response body

-> m (Either ErrorMessage (Meta, r))

This function returns whatever your Sink returns, paired up with the file metadata.

Gets a file's contents and metadata. If you just want the entire contents of a file as a single ByteString, use getFileBs.

getFileBsSource

Arguments

:: (MonadBaseControl IO m, MonadThrow m, MonadUnsafeIO m, MonadIO m) 
=> Manager

The HTTP connection manager to use.

-> Session 
-> Path

The full path (relative to your DbAccessType root)

-> Maybe FileRevision

The revision of the file to retrieve.

-> m (Either ErrorMessage (Meta, ByteString)) 

A variant of getFile that just returns a strict ByteString (instead of having you pass in a Sink to process the body.

putFileSource

Arguments

:: (MonadBaseControl IO m, MonadThrow m, MonadUnsafeIO m, MonadIO m) 
=> Manager

The HTTP connection manager to use.

-> Session 
-> Path

The full path (relative to your DbAccessType root)

-> WriteMode 
-> RequestBody m

The file contents.

-> m (Either ErrorMessage Meta) 

data WriteMode Source

Constructors

WriteModeAdd

If there is already a file at the specified path, rename the new file.

WriteModeUpdate FileRevision

Check that there is a file there with the given revision. If so, overwrite it. If not, rename the new file.

WriteModeForce

If there is already a file at the specified path, overwrite it.

Common data types

type Path = StringSource

Dropbox file and folder paths. Should always start with /.

data RequestBody m Source

An HTTP request body: an Int64 for the length and a Source that yields the actual data.

bsSink :: Monad m => Sink ByteString m ByteStringSource

A Sink that reads in ByteString chunks and constructs one concatenated ByteString