]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/API/Admin/Orchestrator/Scrapy/Schedule.hs
[zip] implement zip for parsers
[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 GHC.Generics
20 import Protolude
21 import Servant
22 import Servant.Client
23 import Servant.Job.Utils (jsonOptions)
24 import Web.FormUrlEncoded hiding (parseMaybe)
25 import qualified Data.HashMap.Strict as H
26
27 ------------------------------------------------------------------------
28
29 data Schedule = Schedule
30 { s_project :: !Text
31 , s_spider :: !Text
32 , s_setting :: ![Text]
33 , s_jobid :: !(Maybe Text)
34 , s_version :: !(Maybe Text)
35 , s_extra :: ![(Text,[Text])]
36 }
37 deriving (Generic)
38
39 data ScheduleResponse = ScheduleResponse
40 { r_status :: !Text
41 , r_jobid :: !Text
42 }
43 deriving (Generic)
44
45 instance FromJSON ScheduleResponse where
46 parseJSON = genericParseJSON (jsonOptions "r_")
47
48 instance ToForm Schedule where
49 toForm s =
50 Form . H.fromList $
51 [("project", [s_project s])
52 ,("spider", [s_spider s])
53 ,("setting", s_setting s)
54 ,("jobid", s_jobid s ^.. _Just)
55 ,("_version", s_version s ^.. _Just)
56 ] ++ s_extra s
57
58 type Scrapy =
59 "schedule.json" :> ReqBody '[FormUrlEncoded] Schedule
60 :> Post '[JSON] ScheduleResponse
61
62 scrapyAPI :: Proxy Scrapy
63 scrapyAPI = Proxy
64
65 scrapySchedule :: Schedule -> ClientM ScheduleResponse
66 scrapySchedule = client scrapyAPI