Store the transaction ID locally, too.

This commit is contained in:
2018-12-17 20:30:11 -08:00
parent 7de91104b0
commit 47e8969290
2 changed files with 41 additions and 14 deletions

View File

@@ -7,18 +7,24 @@ import Json.Encode as Encode
type alias Username = String
type alias Password = String
type alias LoginInfo = (ApiToken, ApiUrl, Username)
type alias LoginInfo =
{ token : ApiToken
, apiUrl : ApiUrl
, username : Username
, transactionId : Int
}
encodeLoginInfo : LoginInfo -> String
encodeLoginInfo (t,a,u) = t ++ "," ++ a ++ "," ++ u
encodeLoginInfo {token, apiUrl, username, transactionId} =
token ++ "," ++ apiUrl ++ "," ++ username ++ "," ++ (String.fromInt transactionId)
decodeLoginInfo : String -> Maybe LoginInfo
decodeLoginInfo s = case String.indexes "," s of
[ fst, snd ] -> Just
( (String.slice 0 fst s)
, (String.slice (fst + 1) snd s)
, (String.dropLeft (snd + 1) s)
)
[ fst, snd, thd ] -> Just <| LoginInfo
(String.slice 0 fst s)
(String.slice (fst + 1) snd s)
(String.slice (snd + 1) thd s)
(Maybe.withDefault 0 <| String.toInt <| String.dropLeft (thd + 1) s)
_ -> Nothing
type alias LoginResponse =