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

[Reading] cosmetics

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