]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Core/Text/Corpus/API.hs
Simplify ExternalAPIs type
[gargantext.git] / src / Gargantext / Core / Text / Corpus / API.hs
1 {-|
2 Module : Gargantext.Core.Text.Corpus.API
3 Description : All crawlers of Gargantext in one file.
4 Copyright : (c) CNRS, 2017
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
8 Portability : POSIX
9
10 -}
11
12 module Gargantext.Core.Text.Corpus.API
13 ( ExternalAPIs(..)
14 , Query
15 , Limit
16 , get
17 , externalAPIs
18 ) where
19
20 import Conduit
21 import Control.Lens ((^.))
22 import Data.Either (Either(..))
23 import Data.Maybe
24 import Gargantext.API.Admin.Orchestrator.Types (ExternalAPIs(..), externalAPIs)
25 import Gargantext.Core (Lang(..))
26 import Gargantext.Database.Admin.Types.Hyperdata (HyperdataDocument(..))
27 import Gargantext.Prelude
28 import Gargantext.Prelude.Config (GargConfig, gc_pubmed_api_key)
29 import qualified Gargantext.Core.Text.Corpus.API.Arxiv as Arxiv
30 import qualified Gargantext.Core.Text.Corpus.API.Hal as HAL
31 import qualified Gargantext.Core.Text.Corpus.API.Isidore as ISIDORE
32 import qualified Gargantext.Core.Text.Corpus.API.Istex as ISTEX
33 import qualified Gargantext.Core.Text.Corpus.API.Pubmed as PUBMED
34 import Servant.Client (ClientError)
35
36 -- | Get External API metadata main function
37 get :: GargConfig
38 -> ExternalAPIs
39 -> Lang
40 -> Query
41 -> Maybe Limit
42 -- -> IO [HyperdataDocument]
43 -> IO (Either ClientError (Maybe Integer, ConduitT () HyperdataDocument IO ()))
44 get cfg PubMed _la q limit = PUBMED.get (cfg ^. gc_pubmed_api_key) q limit
45 --docs <- PUBMED.get q default_limit -- EN only by default
46 --pure (Just $ fromIntegral $ length docs, yieldMany docs)
47 get _ Arxiv la q limit = Arxiv.get la q (fromIntegral <$> limit)
48 get _ HAL la q limit = HAL.getC la q limit
49 get _ IsTex la q limit = do
50 docs <- ISTEX.get la q limit
51 pure $ Right (Just $ fromIntegral $ length docs, yieldMany docs)
52 get _ Isidore la q limit = do
53 docs <- ISIDORE.get la (fromIntegral <$> limit) (Just q) Nothing
54 pure $ Right (Just $ fromIntegral $ length docs, yieldMany docs)
55 get _ externalApi _ _ _ = panic $ "[G.C.T.Corpus.API] This options are note taken into account: " <> (cs $ show externalApi)
56
57 -- | Some Sugar for the documentation
58 type Query = PUBMED.Query
59 type Limit = PUBMED.Limit