]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Text/Parsers/Client.sh
ElEve...
[gargantext.git] / src / Gargantext / Text / Parsers / Client.sh
1 {-# LANGUAGE DataKinds #-}
2 {-# LANGUAGE DeriveGeneric #-}
3 {-# LANGUAGE TypeOperators #-}
4 {-# LANGUAGE OverloadedStrings #-}
5 {-# LANGUAGE NoImplicitPrelude #-}
6
7
8 module Gargantext.Text.Parsers.Isidore where
9
10 import Data.Text (Text)
11 import Data.Either
12 import Gargantext.Prelude
13 import Data.Aeson
14 import Data.Proxy
15 import GHC.Generics
16 import Network.HTTP.Client (newManager)
17 import Network.HTTP.Client.TLS (tlsManagerSettings)
18 import Servant.API
19 import Servant.Client
20
21
22 type IsidoreAPI = "sparql" :> Capture "query" Text :> Get '[JSON] [IsidoreDoc]
23
24
25 data IsidoreDoc =
26 IsidoreDoc {title :: Maybe Text}
27 deriving (Show, Generic)
28
29
30 instance FromJSON IsidoreDoc
31 instance ToJSON IsidoreDoc
32
33 isidoreDocsApi :: Proxy IsidoreAPI
34 isidoreDocsApi = Proxy
35
36 isidoreDocs :: ClientM [IsidoreDoc]
37 isidoreDocs = client isidoreDocsApi
38
39 getIsidoreDocs :: IO [IsidoreDoc]
40 getIsidoreDocs = do
41 manager' <- newManager tlsManagerSettings
42 res <- runClientM isidoreDocs $ mkClientEnv manager' $ BaseUrl Https "https://www.rechercheisidore.fr" 8080 ""
43 case res of
44 Left _ -> panic "err"
45 Right res' -> pure res'