Commit bb8919de authored by Alexandre Delanoë's avatar Alexandre Delanoë

[Reading] cosmetics

parent 98ffb24a
...@@ -15,9 +15,21 @@ runIstexAPIClient cmd = do ...@@ -15,9 +15,21 @@ runIstexAPIClient cmd = do
runClientM cmd (mkClientEnv manager' $ BaseUrl Https "api.istex.fr" 443 "document") runClientM cmd (mkClientEnv manager' $ BaseUrl Https "api.istex.fr" 443 "document")
getMetadataWith :: Text -> Maybe Int -> IO (Either ClientError Documents) getMetadataWith :: Text -> Maybe Int -> IO (Either ClientError Documents)
getMetadataWith q l = do getMetadataWith q n = do
runIstexAPIClient $ runIstexAPIClient $
search search
(Just "author,title,abstract,publicationDate,refBibs") (Just "author,title,abstract,publicationDate,refBibs")
l n
(Just q) (Just q)
type Query = Text
runTest :: Query -> Maybe Int -> IO ()
runTest query n = do
res <- getMetadataWith query n
case res of
(Left err) -> print $ show err
(Right val) -> do
print val
...@@ -18,9 +18,8 @@ import qualified Data.Text as T ...@@ -18,9 +18,8 @@ import qualified Data.Text as T
import qualified Control.Lens as L import qualified Control.Lens as L
data Author = Author data Author = Author
{ { _author_name :: T.Text
_author_name :: T.Text, , _author_affiliations :: [T.Text]
_author_affiliations :: [T.Text]
} deriving (Show, Generic) } deriving (Show, Generic)
L.makeLenses ''Author L.makeLenses ''Author
...@@ -29,57 +28,51 @@ instance FromJSON Author where ...@@ -29,57 +28,51 @@ instance FromJSON Author where
Author <$> (o .: "name") <*> (o .: "affiliations" <|> pure []) Author <$> (o .: "name") <*> (o .: "affiliations" <|> pure [])
data Source = Source data Source = Source
{ { _source_title :: Maybe T.Text
_source_title :: Maybe T.Text, , _source_authors :: [Author]
_source_authors :: [Author], , _source_publicationDate :: Maybe Int
_source_publicationDate :: Maybe Int
} deriving (Show, Generic) } deriving (Show, Generic)
L.makeLenses ''Source L.makeLenses ''Source
instance FromJSON Source where instance FromJSON Source where
parseJSON (Object o) = parseJSON (Object o) =
Source <$> Source <$> (o .:? "title")
(o .:? "title")
<*> (o .: "author") <*> (o .: "author")
<*> do pPubDate <- (o .:? "publicationDate") <*> do pPubDate <- (o .:? "publicationDate")
return $ (read . T.unpack) <$> pPubDate return $ (read . T.unpack) <$> pPubDate
data Document = Document data Document = Document
{ { _document_id :: T.Text
_document_id :: T.Text, , _document_title :: Maybe T.Text
_document_title :: Maybe T.Text, , _document_authors :: [Author]
_document_authors :: [Author], , _document_abstract :: Maybe T.Text
_document_abstract :: Maybe T.Text, , _document_publicationDate :: Maybe Int
_document_publicationDate :: Maybe Int, , _document_sources :: [Source]
_document_sources :: [Source]
} deriving (Show, Generic) } deriving (Show, Generic)
L.makeLenses ''Document L.makeLenses ''Document
instance FromJSON Document where instance FromJSON Document where
parseJSON (Object o) = parseJSON (Object o) =
Document <$> Document <$> (o .: "id")
(o .: "id")
<*> (o .:? "title") <*> (o .:? "title")
<*> (o .: "author" <|> pure []) <*> (o .: "author" <|> pure [])
<*> (o .:? "abstract") <*> (o .:? "abstract")
<*> do pPubDate <- (o .:? "publicationDate") <*> ((o .:? "publicationDate") >>= \date -> return $ fmap (read . T.unpack) date)
return $ (read . T.unpack) <$> pPubDate
<*> (o .: "refBibs" <|> pure []) <*> (o .: "refBibs" <|> pure [])
data Documents = Documents data Documents = Documents
{ { _documents_total :: Int
_documents_total :: Int, , _documents_hits :: [Document]
_documents_hits :: [Document]
} deriving (Show, Generic) } deriving (Show, Generic)
L.makeLenses ''Documents L.makeLenses ''Documents
instance FromJSON Documents where instance FromJSON Documents where
parseJSON (Object o) = parseJSON (Object o) =
Documents <$> (o .: "total") <*> (o .: "hits") Documents <$> (o .: "total") <*> (o .: "hits")
type ISTEXAPI = Search type ISTEXAPI = Search
type Search = type Search = QueryParam "output" T.Text
QueryParam "output" T.Text
:> QueryParam "size" Int :> QueryParam "size" Int
:> QueryParam "q" T.Text :> QueryParam "q" T.Text
:> Get '[JSON] Documents :> Get '[JSON] Documents
......
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