2022-04-17 21:04:13 +02:00
|
|
|
{-# LANGUAGE DataKinds #-}
|
|
|
|
|
{-# LANGUAGE TypeOperators #-}
|
|
|
|
|
|
2022-04-19 23:11:06 +02:00
|
|
|
module Onomap.Stoepel (districts, districtStatistics, states, stateStatistics, runStoepel) where
|
2022-04-17 21:04:13 +02:00
|
|
|
|
|
|
|
|
import Data.Proxy
|
|
|
|
|
import Data.Text (Text)
|
|
|
|
|
import Network.HTTP.Client (Manager)
|
|
|
|
|
import Servant.API
|
|
|
|
|
import Servant.Client
|
2022-04-19 23:11:06 +02:00
|
|
|
import Onomap.Types (Area, ByArea)
|
2022-04-17 21:04:13 +02:00
|
|
|
|
|
|
|
|
type StoepelAPI =
|
2022-04-19 23:11:06 +02:00
|
|
|
"content" :> "de" :> "districts.json" :> Get '[JSON] [Area]
|
|
|
|
|
:<|> "api" :> "clusters" :> "district" :> QueryParam "name" Text :> Get '[JSON] (ByArea Int)
|
|
|
|
|
:<|> "content" :> "de" :> "states.json" :> Get '[JSON] [Area]
|
|
|
|
|
:<|> "api" :> "clusters" :> "state" :> QueryParam "name" Text :> Get '[JSON] (ByArea Int)
|
2022-04-17 21:04:13 +02:00
|
|
|
|
|
|
|
|
stoepelApi :: Proxy StoepelAPI
|
|
|
|
|
stoepelApi = Proxy
|
|
|
|
|
|
2022-04-19 23:11:06 +02:00
|
|
|
districts :: ClientM [Area]
|
|
|
|
|
states :: ClientM [Area]
|
|
|
|
|
districtStatistics :: Maybe Text -> ClientM (ByArea Int)
|
|
|
|
|
stateStatistics :: Maybe Text -> ClientM (ByArea Int)
|
2022-04-17 21:04:13 +02:00
|
|
|
districts :<|> districtStatistics :<|> states :<|> stateStatistics = client stoepelApi
|
|
|
|
|
|
|
|
|
|
runStoepel :: Manager -> ClientM a -> IO a
|
|
|
|
|
runStoepel manager' c = do
|
|
|
|
|
x <- runClientM c (mkClientEnv manager' (BaseUrl Https "geogen.stoepel.net" 443 ""))
|
|
|
|
|
case x of
|
|
|
|
|
Left err -> error $ show err
|
|
|
|
|
Right a -> return a
|