Commit 3b06f228 authored by Mael NICOLAS's avatar Mael NICOLAS

stuck on the "" | {} fromJSON instance

parent 5136b6b8
......@@ -12,8 +12,9 @@ main = do
manager' <- newManager tlsManagerSettings
res <- runClientM
(search
(Just 1)
(Just JSON)
(Just "colza")
(Just "poison")
(Nothing))
(mkClientEnv manager' $ BaseUrl Https "api.isidore.science" 443 "resource")
case res of
......
......@@ -21,6 +21,7 @@ description: Please see the README on GitHub at <https://github.com/gith
dependencies:
- base >= 4.7 && < 5
- aeson
- servant
- servant-client
- text
......
......@@ -11,8 +11,56 @@ import Servant.Client
import Data.Proxy(Proxy(..))
import Data.ByteString.Lazy (ByteString)
import Data.Aeson
import qualified Data.Text as T
data LocalContent = LocalContent
{
_lang :: T.Text,
_content :: T.Text
}
deriving (Show)
instance FromJSON LocalContent where
parseJSON (Object o) = LocalContent <$>
(o .: "@xml:lang")
<*> (o .: "$")
data Author = Author
{
_firstName :: T.Text,
_lastName :: T.Text
}
deriving (Show)
instance FromJSON Author where
parseJSON (Object o) = Author <$>
(o .: "firstName")
<*> (o .: "lastName")
data MayBeLocal = Local LocalContent | NonLocal T.Text
deriving (Show)
data IsidoreDoc = IsidoreDoc
{
_title :: MayBeLocal,
_abstract :: MayBeLocal,
_authors :: [Author]
}
deriving (Show)
instance FromJSON IsidoreDoc where
parseJSON (Object o) = IsidoreDoc <$>
(responseReplies >>= (.: "title") )
<*> (responseReplies >>= (.: "abstract"))
<*> (responseReplies >>= (.: "enrichedCreators") >>= (.: "creator"))
where responseReplies = (o .: "response")
>>= (.: "replies")
>>= (.: "content")
>>= (.: "reply")
>>= (.: "isidore")
data Output = JSON
instance ToHttpApiData Output where
......@@ -22,6 +70,7 @@ type ISIDOREAPI = Search
-- search?q=colza&output=json&replies=1&author=jm&
type Search = "search"
:> QueryParam "replies" Int
:> QueryParam "output" Output
:> QueryParam "q" T.Text
:> QueryParam "author" T.Text
......@@ -30,6 +79,6 @@ type Search = "search"
isidoreAPI :: Proxy ISIDOREAPI
isidoreAPI = Proxy
search :: Maybe Output -> Maybe T.Text -> Maybe T.Text -> ClientM T.Text
search :: Maybe Int -> Maybe Output -> Maybe T.Text -> Maybe T.Text -> ClientM T.Text
search = client isidoreAPI
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment