This is an alternative site for discovering Elm packages. You may be looking for the official Elm package site instead.
Unofficial Dropbox API for Elm
version 2.0.0
license MIT
native-modules False
elm-version 0.18.0 <= v < 0.19.0
Tag 2.0.0
Committed At 2018-03-13 02:27:09 UTC
mgold/elm-date-format 1.3.0 <= v < 2.0.0 1.8.0
elm-lang/navigation 2.1.0 <= v < 3.0.0 2.1.0
elm-lang/http 1.0.0 <= v < 2.0.0 1.0.0
elm-lang/html 2.0.0 <= v < 3.0.0 2.0.0
elm-lang/core 5.1.1 <= v < 6.0.0 5.1.1
elm-community/maybe-extra 4.0.0 <= v < 5.0.0 4.0.0
elm-community/json-extra 2.1.0 <= v < 3.0.0 2.7.0
ccapndave/elm-update-extra 3.0.0 <= v < 4.0.0 3.0.0
NoRedInk/elm-decode-pipeline 3.0.0 <= v < 4.0.0 3.0.1

Modules

README

Unofficial Dropbox API for Elm.

Demo

https://avh4.github.io/elm-dropbox/

Usage

The Dropbox API uses OAuth 2.0 for authentication. To authenticate the user, you will need to send them to the approrpiate authentication URL, which can be done with Dropbox.authorize. But to create the authorization URL, you will need to provide the Navigation.Location of the current page.

First, set up your Model to store the current page's location:

elm-package install elm-lang/navigation
import Navigation

type alias Model =
    { ...
    , location : Navigation.Location
    }

initialModel : Navigation.Location -> Model
initialModel location =
    { ...
    , location = location
    }

Dropbox authentication requires a "client id", also called the "app key". can be found on the Dropbox Developers page for your app. Links: your Dropbox apps, creat a new Dropbox app You will need to get the client id/app key of your existing app, or create a new app.

Now, you can create a Msg that will initiate Dropbox login:

elm-package install avh4/elm-dropbox
import Dropbox

type Msg
    = ...
    | LogInToDropbox

update : Msg -> Model -> (Model, Cmd Msg)
update msg model =
    case msg of
        ...
        LogInToDropbox ->
            ( model
            , Dropbox.authorize
                { clientId = "MY_CLIENT_ID"
                , state = Nothing
                , requireRole = Nothing
                , forceReapprove = False
                , disableSignup = False
                , locale = Nothing
                , forceReauthentication = False
                }
                model.location
            )

view : Model -> Html Msg
view model =
    ...
    Html.button
        [ Html.Events.onClick LogInToDropbox ]
        [ Html.text "Log in with Dropbox" ]

When authentication completes, Dropbox will redirect to the current page, providing the authentication details in the URL's fragment identifier . You can use Dropbox.program to automatically parse the redirect response (it also will help you get the Navigation.Location to store in your model).

import Dropbox

type Msg
    = ...
    | AuthResponse Dropbox.AuthorizeResult

main : Program Never Model (Dropbox.Msg Msg)
main =
    Dropbox.program
        { init = \location -> ( initialModel location, Cmd.none )
        , update = update
        , subscriptions = subscriptions
        , view = view
        , onAuth = AuthResponse
        }

You can now handle the auth response and take the resulting Dropbox.UserAuth and use it to make API requests. See the documentation for the full list of supported API calls. Typically you will take the Dropbox.UserAuth and store it in your model for later use. You may also want to persist it in local storage so that it can be used on future visits to your app.

import Dropbox

type alias Model =
    { ...
    , dropboxAuth : Maybe Dropbox.UserAuth
    }

type Msg
    = ...
    | FetchFileResponse (Result Dropbox.DownloadError Dropbox.DownloadResponse)

update : Msg -> Model -> (Model, Cmd Msg)
update msg model =
    case msg of
        ...
        AuthResponse (Dropbox.AuthorizeOk auth) ->
            ( { model | dropboxAuth = Just auth.userAuth }
            , Dropbox.download auth.userAuth
                { path : "/data_file_to_load.json" }
                |> Task.attempt FetchFileResponse
            )