Last active
February 17, 2019 15:25
-
-
Save cobalamin/0f6bd0955d0e54cb3cb38a9e15155b2a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Stuff exposing (..) | |
import UrlParser exposing (..) | |
import String | |
import Erl | |
import Dict exposing (Dict) | |
type alias Params = | |
Dict String String | |
type Route | |
= AuthCodeRoute Params | |
| UserPageRoute Int | |
params = | |
custom ("PARAMS") | |
(Erl.parse >> .query >> Ok) | |
parser : Parser (Route -> a) a | |
parser = | |
oneOf | |
[ format AuthCodeRoute (s "authCode" </> params) | |
, format UserPageRoute (s "user" </> int) | |
] | |
userPageTest = parse identity parser "user/42/" | |
-- Ok (UserPageRoute 42) | |
authCodeTest = parse identity parser "authCode/?code=31337abc" | |
-- Ok (AuthCodeRoute (Dict.fromList [("code", "31337abc")])) | |
authCodeTest2 = parse identity parser "authCode/?error=Authentication%20failed" | |
-- Ok (AuthCodeRoute (Dict.fromList [("error","Authentication failed")])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment