Skip to content

Instantly share code, notes, and snippets.

@cobalamin
Last active February 17, 2019 15:25
Show Gist options
  • Save cobalamin/0f6bd0955d0e54cb3cb38a9e15155b2a to your computer and use it in GitHub Desktop.
Save cobalamin/0f6bd0955d0e54cb3cb38a9e15155b2a to your computer and use it in GitHub Desktop.
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