Rename more stuff
This commit is contained in:
31
intro/part10/src/Data/AuthToken.elm
Normal file
31
intro/part10/src/Data/AuthToken.elm
Normal 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
|
||||
Reference in New Issue
Block a user