]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Text/Corpus/API.hs
working on synchony
[gargantext.git] / src / Gargantext / Text / Corpus / API.hs
1 {-|
2 Module : Gargantext.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 {-# LANGUAGE NoImplicitPrelude #-}
13 {-# LANGUAGE OverloadedStrings #-}
14 {-# LANGUAGE DeriveGeneric #-}
15 {-# LANGUAGE InstanceSigs #-}
16
17 module Gargantext.Text.Corpus.API
18 where
19
20 import GHC.Generics (Generic)
21 import Data.Aeson
22 import Data.Maybe
23 import Gargantext.Prelude
24 import Gargantext.Core (Lang(..))
25 import Gargantext.Database.Types.Node (HyperdataDocument(..))
26 import Test.QuickCheck.Arbitrary
27 import Test.QuickCheck (elements)
28 import Data.Swagger
29
30 import qualified Gargantext.Text.Corpus.API.Pubmed as PUBMED
31 import qualified Gargantext.Text.Corpus.API.Isidore as ISIDORE
32 import qualified Gargantext.Text.Corpus.API.Hal as HAL
33 import qualified Gargantext.Text.Corpus.API.Istex as ISTEX
34
35 -- | Main Types
36 data ExternalAPIs = All
37 | PubMed
38
39 | HAL_EN
40 | HAL_FR
41
42 | IsTex_EN
43 | IsTex_FR
44
45 | Isidore_EN
46 | Isidore_FR
47 -- | IsidoreAuth
48 deriving (Show, Eq, Enum, Bounded, Generic)
49
50
51 -- | Get External API metadata main function
52 get :: ExternalAPIs -> Query -> Maybe Limit -> IO [HyperdataDocument]
53 get All _ _ = undefined
54
55 get PubMed q l = PUBMED.get q l
56
57 get HAL_EN q l = HAL.get EN q l
58 get HAL_FR q l = HAL.get FR q l
59
60 get IsTex_EN q l = ISTEX.get EN q l
61 get IsTex_FR q l = ISTEX.get FR q l
62
63 get Isidore_EN q l = ISIDORE.get EN (fromIntegral <$> l) (Just q) Nothing
64 get Isidore_FR q l = ISIDORE.get FR (fromIntegral <$> l) (Just q) Nothing
65
66
67 -- | Main Instances
68 instance FromJSON ExternalAPIs
69 instance ToJSON ExternalAPIs
70
71 externalAPIs :: [ExternalAPIs]
72 externalAPIs = [minBound..maxBound]
73
74 instance Arbitrary ExternalAPIs
75 where
76 arbitrary = elements externalAPIs
77
78 instance ToSchema ExternalAPIs
79
80 -- | Some Sugar for the documentation
81 type Query = PUBMED.Query
82 type Limit = PUBMED.Limit
83