avh4/elm-dropbox/2.0.0

NOTE: this package is not compatible with Elm 0.19.1

Dropbox

Dropbox API

See the official Dropbox documentation at https://www.dropbox.com/developers/documentation/http/documentation

{ init : Location -> ( model, Cmd msg )
, update : msg -> model -> ( model, Cmd msg )
, subscriptions : model -> Sub msg
, view : model -> Html msg
, onAuth : AuthorizeResult -> msg
}
-> Program Never model (Msg msg)

This provides the simplest way to integrate Dropbox authentication. Using Dropbox.program will handle parsing the authentication response from the authentication redirect so that you don't have to do it manually.

{ init : flags -> Location -> ( model, Cmd msg )
, update : msg -> model -> ( model, Cmd msg )
, subscriptions : model -> Sub msg
, view : model -> Html msg
, onAuth : AuthorizeResult -> msg
}
-> Program flags model (Msg msg)

This provides the simplest way to integrate Dropbox authentication with flags. Using Dropbox.programWithFlags will handle parsing the authentication response from the authentication redirect so that you don't have to do it manually.

type Msg msg

The message type for an app that uses Dropbox.program

Authorization

type alias AuthorizeRequest =
{ clientId : String
, state : Maybe String
, requireRole : Maybe Role
, forceReapprove : Bool
, disableSignup : Bool
, locale : Maybe String
, forceReauthentication : Bool
}

Request parameters for Dropbox OAuth 2.0 authorization requests.

See https://www.dropbox.com/developers/documentation/http/documentation#oauth2-authorize

Note: redirect_uri is not present here because it is provided directly to Dropbox.authorize or Dropbox.authorizationUrl.

= DropboxAuthorizeErr AuthorizeError
| AuthorizeOk
{ userAuth : UserAuth
, accountId : String
, state : Maybe String
}
| UnknownAccessTokenErr
{ accessToken : String
, tokenType : String
, accountId : String
, state : Maybe String
}

Return value of the authorize endpoint, which is the data Dropbox returns via the redirect URL.

You can get the AuthorizeResult by using Dropbox.program, or by using parseAuthorizeResult if you need to manually parse the redirect URL.

See https://www.dropbox.com/developers/documentation/http/documentation#oauth2-authorize

Note: uid is not provided because it is deprecated. See https://www.dropbox.com/developers/documentation/http/documentation#oauth2-authorize

type alias AuthorizeError =
{ error : String
, errorDescription : String
, state : Maybe String
}

Return value of the authorize endpoint when authentication fails. See AuthorizeResult.

See https://www.dropbox.com/developers/documentation/http/documentation#oauth2-authorize

A user authentication token that can be used to authenticate API calls

See https://www.dropbox.com/developers/reference/auth-types#user

encodeUserAuth : UserAuth -> Value

Encode a UserAuth to JSON.

You should consider the resulting value to be opaque and only read it using decodeUserAuth.

WARNING: To protect your users' security, you must not transmit the resulting value off the user's device. This function exists to allow persisting the auth token to localStorage or other storage that is local to the user's device and private to your application. You should not send this value to your own server (if you think you need that, you should use a different OAuth flow involving your Dropox app's app secret instead of using implicit grant).

decodeUserAuth : Decoder UserAuth

Decode a UserAuth encoded with encodeUserAuth.

NOTE: See the security warning in encodeUserAuth.

If you have an auth token as a String and need to convert it to a UserAuth, see authorizationFromAccessToken.

authorizationUrl : AuthorizeRequest -> String -> String

The Dropbox OAuth 2.0 authorization URL. Typically you will just want to use authorize instead, which will initiate the authorization.

See https://www.dropbox.com/developers/reference/oauth-guide

redirectUriFromLocation : Location -> String

Generate a redirect URI from a Navigation.Location.

Typically you will want to use Dropbox.authorize, which will do this automatically. You may want to use this if you need to manually manage the OAuth flow.

authorizationFromAccessToken : String -> UserAuth

Create a UserAuth from a Dropbox access token.

You can use this during development, using the "generated access token" from the settings page of your Dropbox app.

You should not use this in a production app. Instead, you should use the normal authorization flow and use program or parseAuthorizeResult.

parseAuthorizeResult : Location -> Maybe AuthorizeResult

Read an AuthorizeResult from the page location.

Typically you will want to use Dropbox.program instead, which will do this automatically. You may want to use this if you need to manually manage the OAuth flow.

Auth

tokenRevoke : UserAuth -> Request ()

Disables the access token used to authenticate the call.

See https://www.dropbox.com/developers/documentation/http/documentation#auth-token-revoke

Files

= FileMeta FileMetadata
| FolderMeta FolderMetadata
| DeletedMeta DeletedMetadata

Metadata union type

type alias FileMetadata =
{ name : String
, id : String
, clientModified : Date
, serverModified : Date
, rev : String
, size : Int
, pathLower : Maybe String
, pathDisplay : Maybe String
, parentSharedFolderId : Maybe String
, mediaInfo : Maybe MediaInfo
, sharingInfo : Maybe FileSharingInfo
, propertyGroups : Maybe (List PropertyGroup)
, hasExplicitSharedMembers : Maybe Bool
, contentHash : Maybe String
}

File metadata

WARNING: elm-dropbox may give the incorrect values for size, since Elm currently does not provide a way to parse and represent 64-bit integers.

type alias FolderMetadata =
{ name : String
, id : String
, pathLower : Maybe String
, pathDisplay : Maybe String
, parentSharedFolderId : Maybe String
, sharedFolderId : Maybe String
, sharingInfo : Maybe FileSharingInfo
, propertyGroups : Maybe (List PropertyGroup)
}

Folder metadata

type alias DeletedMetadata =
{ name : String
, pathLower : Maybe String
, pathDisplay : Maybe String
, parentSharedFolderId : Maybe String
}

Deleted item metadata

download : UserAuth -> DownloadRequest -> Task DownloadError DownloadResponse
type alias DownloadRequest =
{ path : String }

Request parameteres for download

Note: there is no rev field because it is deprecated. See https://www.dropbox.com/developers/documentation/http/documentation#files-download

type alias DownloadResponse =
{ content : String
, name : String
, id : String
, clientModified : Date
, serverModified : Date
, rev : String
, size : Int
, pathLower : Maybe String
, pathDisplay : Maybe String
, parentSharedFolderId : Maybe String
, mediaInfo : Maybe MediaInfo
, sharingInfo : Maybe FileSharingInfo
, propertyGroups : Maybe (List PropertyGroup)
, hasExplicitSharedMembers : Maybe Bool
, contentHash : Maybe String
}

Return value for download

WARNING: elm-dropbox may give the incorrect values for size, since Elm currently does not provide a way to parse and represent 64-bit integers.

= PathDownloadError LookupError
| OtherDownloadError String Value
| OtherDownloadFailure Error
= MalformedPathLookup (Maybe String)
| NotFound
| NotFile
| NotFolder
| RestrictedContent
| OtherLookupError String Value
upload : UserAuth -> UploadRequest -> Task UploadError FileMetadata

Create a new file with the contents provided in the request.

See https://www.dropbox.com/developers/documentation/http/documentation#files-upload

type alias UploadRequest =
{ path : String
, mode : WriteMode
, autorename : Bool
, clientModified : Maybe Date
, mute : Bool
, content : String
}

Request parameters for upload

= Add
| Overwrite
| Update String
= Path UploadWriteFailed
| OtherUploadError String Value
| OtherUploadFailure Error
type alias UploadWriteFailed =
{ reason : WriteError
, uploadSessionId : String
}
= MalformedPathWrite (Maybe String)
| Conflict WriteConflictError
| NoWritePermission
| InsufficientSpace
| DisallowedName
| TeamFolder
| OtherWriteError String Value
UserAuth
-> ListFolderRequest
-> Task ListFolderError ListFolderResponse
UserAuth
-> ListFolderContinueRequest
-> Task ListFolderContinueError ListFolderResponse
type alias ListFolderRequest =
{ path : String
, recursive : Bool
, includeMediaInfo : Bool
, includeDeleted : Bool
, includeHasExplicitSharedMembers : Bool
}

Request parameters for listFolder

type alias ListFolderResponse =
{ entries : List Metadata
, cursor : String
, hasMore : Bool
}
= PathListError LookupError
| OtherListError String Value
| OtherListFailure Error
= PathListContinueError LookupError
| ExpiredCursorError
| OtherListContinueError String Value
| OtherListContinueFailure Error

Additional information if the file is a photo or video.

See https://www.dropbox.com/developers/documentation/http/documentation#files-upload

type alias PhotoMetadata =
{ dimensions : Maybe Dimensions
, location : Maybe GpsCoordinates
, timeTaken : Maybe Date
}
type alias VideoMetadata =
{ dimensions : Maybe Dimensions
, location : Maybe GpsCoordinates
, timeTaken : Maybe Date
, duration : Maybe Int
}

Metadata for a video.

See https://www.dropbox.com/developers/documentation/http/documentation#files-upload

WARNING: elm-dropbox may give the incorrect values for duration, since Elm currently does not provide a way to parse and represent 64-bit integers.

type alias Dimensions =
{ height : Int
, width : Int
}

Dimensions for a photo or video.

See https://www.dropbox.com/developers/documentation/http/documentation#files-upload

WARNING: elm-dropbox may give the incorrect values, since Elm currently does not provide a way to parse and represent 64-bit integers.

type alias GpsCoordinates =
{ latitude : Float
, longitude : Float
}
type alias FileSharingInfo =
{ readOnly : Bool
, parentSharedFolderId : String
, modifiedBy : Maybe String
}

Sharing info for a file which is contained by a shared folder.

See https://www.dropbox.com/developers/documentation/http/documentation#files-upload

type alias PropertyGroup =
{ templateId : String
, fields : Dict String String
}

Collection of custom properties in filled property templates.

See https://www.dropbox.com/developers/documentation/http/documentation#files-upload