]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/API/Admin/Orchestrator/Scrapy/Schedule.hs
Merge branch 'dev-default-extensions' into dev
[gargantext.git] / src / Gargantext / API / Admin / Orchestrator / Scrapy / Schedule.hs
1 {-|
2 Module : Gargantext.API.Admin.Orchestartor.Scrapy.Schedule
3 Description : Server API Auth Module
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
8 Portability : POSIX
9
10 -}
11
12 {-# LANGUAGE TypeOperators #-}
13
14 module Gargantext.API.Admin.Orchestrator.Scrapy.Schedule
15 where
16
17 import Control.Lens
18 import Data.Aeson
19 import Data.Text (Text)
20 import GHC.Generics
21 import Protolude
22 import Servant
23 import Servant.Client
24 import Servant.Job.Utils (jsonOptions)
25 import Web.FormUrlEncoded hiding (parseMaybe)
26 import qualified Data.HashMap.Strict as H
27
28 ------------------------------------------------------------------------
29
30 data Schedule = Schedule
31 { s_project :: !Text
32 , s_spider :: !Text
33 , s_setting :: ![Text]
34 , s_jobid :: !(Maybe Text)
35 , s_version :: !(Maybe Text)
36 , s_extra :: ![(Text,[Text])]
37 }
38 deriving (Generic)
39
40 data ScheduleResponse = ScheduleResponse
41 { r_status :: !Text
42 , r_jobid :: !Text
43 }
44 deriving (Generic)
45
46 instance FromJSON ScheduleResponse where
47 parseJSON = genericParseJSON (jsonOptions "r_")
48
49 instance ToForm Schedule where
50 toForm s =
51 Form . H.fromList $
52 [("project", [s_project s])
53 ,("spider", [s_spider s])
54 ,("setting", s_setting s)
55 ,("jobid", s_jobid s ^.. _Just)
56 ,("_version", s_version s ^.. _Just)
57 ] ++ s_extra s
58
59 type Scrapy =
60 "schedule.json" :> ReqBody '[FormUrlEncoded] Schedule
61 :> Post '[JSON] ScheduleResponse
62
63 scrapyAPI :: Proxy Scrapy
64 scrapyAPI = Proxy
65
66 scrapySchedule :: Schedule -> ClientM ScheduleResponse
67 scrapySchedule = client scrapyAPI