Add part4

This commit is contained in:
Richard Feldman
2018-04-30 05:51:20 -04:00
parent 29fbd5c1c1
commit 202fde8eb4
240 changed files with 34585 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
module Data.AuthToken exposing (AuthToken, decoder, encode, withAuthorization)
import HttpBuilder exposing (RequestBuilder, withHeader)
import Json.Decode as Decode exposing (Decoder)
import Json.Encode as Encode exposing (Value)
type AuthToken
= AuthToken String
encode : AuthToken -> Value
encode (AuthToken token) =
Encode.string token
decoder : Decoder AuthToken
decoder =
Decode.string
|> Decode.map AuthToken
withAuthorization : Maybe AuthToken -> RequestBuilder a -> RequestBuilder a
withAuthorization maybeToken builder =
case maybeToken of
Just (AuthToken token) ->
builder
|> withHeader "authorization" ("Token " ++ token)
Nothing ->
builder